You are here

function commerce_purchase_order_transaction in Commerce Purchase Order 7

Creates a PO number 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.

$name: The name entered on the submission form.

2 calls to commerce_purchase_order_transaction()
commerce_purchase_order_rules_issue_po_action in ./commerce_purchase_order.rules.inc
commerce_purchase_order_submit_form_submit in ./commerce_purchase_order.module
Payment method callback: submit form submission.

File

./commerce_purchase_order.module, line 193
Provides an example payment method for Drupal Commerce for testing and development.

Code

function commerce_purchase_order_transaction($payment_method, $order, $charge, $po_number) {
  $transaction = commerce_payment_transaction_new('commerce_purchase_order', $order->order_id);
  $transaction->instance_id = $payment_method['instance_id'];
  $transaction->amount = $charge['amount'];
  $transaction->currency_code = $charge['currency_code'];

  // Set to pending: the administrator will need to set it manually to success when the PO number was verified.
  $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
  $transaction->message = 'Paid with PO Number: @po_number';
  $transaction->message_variables = array(
    '@po_number' => $po_number,
  );
  commerce_payment_transaction_save($transaction);

  // Insert PO number in DB
  $order_id = $order->order_id;
  db_insert('commerce_purchase_order')
    ->fields(array(
    'transaction_id' => $transaction->transaction_id,
    'order_id' => $order_id,
    'po_number' => $po_number,
  ))
    ->execute();
}