You are here

function commerce_payleap_rules_capture_pending in Commerce Payleap 7

Action: Capture a pending transaction.

1 string reference to 'commerce_payleap_rules_capture_pending'
commerce_payleap_rules_action_info in ./commerce_payleap.rules.inc
Implements hook_rules_action_info().

File

./commerce_payleap.rules.inc, line 61

Code

function commerce_payleap_rules_capture_pending($order, $transaction = FALSE) {
  if ($transaction) {
    $payments = array();
    $payments[0]->transaction_id = $transaction->transaction_id;
    $payments[0]->commerce_payment_transaction_status = $transaction->transaction_id;
  }
  else {
    $payments = views_get_view_result('commerce_payment_order', 'defaults', $order->order_id);
  }

  // Process all transactions.
  foreach ($payments as $payment) {

    // Process only pending transactions.
    if ($payment->commerce_payment_transaction_status != COMMERCE_PAYMENT_STATUS_PENDING) {
      continue;
    }
    $wrapper = entity_metadata_wrapper('commerce_payment_transaction', $payment->transaction_id);
    $transaction = $wrapper
      ->value();
    $payment_method = commerce_payment_method_instance_load($transaction->instance_id);
    $amount = commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code);
    $result = commerce_payleap_transaction_request($transaction, $payment_method, $amount, 'Force');
  }
}