Is there a way to programmatically show payment form?

Comments

dillix created an issue. See original summary.

xano’s picture

Status: Active » Fixed

See payment_form_embedded(). For a comprehensive example, see the Payment Form submodule.

jagermonster’s picture

To add it to a page or somewhere:

$payment = new Payment(array(
      'context_data' => array(
          'entity_type' => '<some entity type>',
          'bundle' => '<some entity bundle>',
      ),
      'currency_code' => 'GBP',
      'description' => 'Payment for la di dada',
      'finish_callback' => 'done_with_payment'
  ));

  $payment->setLineItem(new PaymentLineItem(array(
      'amount' => 123,
      'tax_rate' => 0.2,
      'description' => "some description ",
      'name' => 'some name ',
  )));
  
  $payment_form = drupal_get_form('payment_form_standalone', $payment);

Then when payment is finished (look at the above finish callback)
function done_with_payment(Payment $payment){
  //do what you want to do when payment is processed
}

Also look at hook_payment_status_change(Payment $payment, PaymentStatusItem $previous_status_item)

dillix’s picture

@jagermonster, big thanks for the code. But I don't understand what is context_data array.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.