You are here

function commerce_payleap_rules_cancel_capture in Commerce Payleap 7

Action: Cancel a pending transaction.

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

File

./commerce_payleap.rules.inc, line 88

Code

function commerce_payleap_rules_cancel_capture($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) {
    $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, 'Void');
  }
}