You are here

function commerce_payment_example_transaction in Commerce Core 7

Creates an example payment transaction for the specified charge amount.

Parameters

$payment_method: The payment method instance object used to charge this payment.

$order: The order object the payment applies to.

$charge: An array indicating the amount and currency code to charge.

1 call to commerce_payment_example_transaction()
commerce_payment_example_submit_form_submit in modules/payment/modules/commerce_payment_example.module
Payment method callback: submit form submission.

File

modules/payment/modules/commerce_payment_example.module, line 84
Provides an example payment method for Drupal Commerce for testing and development.

Code

function commerce_payment_example_transaction($payment_method, $order, $charge) {
  $card_details = $order->data['commerce_payment_example']['credit_card'];
  $transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
  $transaction->instance_id = $payment_method['instance_id'];
  $transaction->amount = $charge['amount'];
  $transaction->currency_code = $charge['currency_code'];
  $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
  $transaction->message = 'Number: @number<br/>Expiration: @month/@year';
  $transaction->message_variables = array(
    '@number' => $card_details['number'],
    '@month' => $card_details['exp_month'],
    '@year' => $card_details['exp_year'],
  );
  commerce_payment_transaction_save($transaction);
  return $transaction;
}