Hi Xano,

I'm trying to get my head around this module, as I will be using it extensively in an application I'm developing. To start with, I am creating a contrib module to allow for donations. (On a side note, it will also allow for admins to add new payments, and relate them to users by selecting a uid.) Donations require a payment form where the user can fill in their own amount, description, payment method, and click "Pay".

Currently, my form is never getting to its submission function because the payment_method field is setting $form_state['rebuild'] to TRUE. I'm not so familiar with multistep forms, but shouldn't it revert to FALSE when its done, so the form can execute like normal?

I believe @chaby had a similar problem here: http://drupal.org/node/1370118#comment-6220222.

Appreciate any insight you can give.

CommentFileSizeAuthor
#4 payment_arbitrary.zip2.09 KBChris Gillis

Comments

xano’s picture

It should only rebuild when you choose a different payment method than the one that is currently being used, so the form can be rebuilt and the new payment method-specific elements can be displayed to the user.

If that does not get you on the right track, please provide step-by-step instructions on how to reproduce the problem.

Chris Gillis’s picture

Here, this is what my form looks like:

function payment_arbitrary_form($form, &$form_state){
  $form_state['payment'] = new Payment(array(
      'context' => 'payment_arbitrary',
      'currency_code' => 'AUD',//todo: Make a setting
      'description' => 'Donation',//Default - will be overwritten
      'finish_callback' => 'payment_arbitrary_payment_finish',
    ));
  
  $form['payment_method'] = array(
    '#access' => TRUE,
    '#type' => 'payment_method',
    '#title' => t('Payment method'),
    '#required' => TRUE,
    '#pmids' => array(),//Todo: Access Checking for payment methods
  );
  $form['payment_amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Payment Amount'),
    '#required' => TRUE,
    );
  $form['payment_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Payment Description'),
    );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Pay'),
  );
  return $form;
}

So the form displays as expected, I can choose a payment method, fill in the details, and then, when I click the Pay button, nothing happens. payment_arbitrary_form_submit() is never called...

xano’s picture

I have little time, so please provide me with a ready-to-go module that I can enable and test directly, without even having to configure anything.

Chris Gillis’s picture

StatusFileSize
new2.09 KB

Sure. Very simple module attached. Ignore all the commented code. Enable it and then go to 'payment/new'.

Thanks for your time.

Chris Gillis’s picture

Well, I gave up using '#type' => 'payment_method' and just got the options myself using the following method.

  $payment_methods = entity_load('payment_method', FALSE);
  foreach ($payment_methods as $payment_method) {
    $pmid_options[(string) $payment_method->pmid] = check_plain($payment_method->title_generic);
  }

The arbitrary module is now working. You can see it here: http://drupal.org/sandbox/ChrisGillis/2000394

xano’s picture

Status: Active » Closed (fixed)

It's better to use Payment::availablePaymentMethods(), so you don't get to see any methods that are not able to process the payment at all.