You are here

function commerce_paypal_wpp_capture_form in Commerce PayPal 7

Same name and namespace in other branches
  1. 7.2 modules/wpp/includes/commerce_paypal_wpp.admin.inc \commerce_paypal_wpp_capture_form()

Form callback: allows the user to capture a prior authorization.

1 string reference to 'commerce_paypal_wpp_capture_form'
commerce_paypal_wpp_menu in modules/wpp/commerce_paypal_wpp.module
Implements hook_menu().

File

modules/wpp/includes/commerce_paypal_wpp.admin.inc, line 12
Administrative forms for the PayPal WPP module.

Code

function commerce_paypal_wpp_capture_form($form, &$form_state, $order, $transaction) {
  $form_state['order'] = $order;
  $form_state['transaction'] = $transaction;

  // Load and store the payment method instance for this transaction.
  $payment_method = commerce_payment_method_instance_load($transaction->instance_id);
  $form_state['payment_method'] = $payment_method;
  $balance = commerce_payment_order_balance($order);

  // Convert the balance to the transaction currency.
  if ($balance['currency_code'] != $transaction->currency_code) {
    $balance['amount'] = commerce_currency_convert($balance['amount'], $balance['currency_code'], $transaction->currency_code);
    $balance['currency_code'] = $transaction->currency_code;
  }
  if ($balance['amount'] > 0 && $balance['amount'] < $transaction->amount) {
    $default_amount = $balance['amount'];
  }
  else {
    $default_amount = $transaction->amount;
  }

  // Convert the price amount to a user friendly decimal value.
  $default_amount = commerce_currency_amount_to_decimal($default_amount, $transaction->currency_code);
  $description = implode('<br />', array(
    t('Authorization: @amount', array(
      '@amount' => commerce_currency_format($transaction->amount, $transaction->currency_code),
    )),
    t('Order balance: @balance', array(
      '@balance' => commerce_currency_format($balance['amount'], $balance['currency_code']),
    )),
  ));
  $form['amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Capture amount'),
    '#description' => $description,
    '#default_value' => $default_amount,
    '#field_suffix' => check_plain($transaction->currency_code),
    '#size' => 16,
  );
  $form = confirm_form($form, t('What amount do you want to capture?'), 'admin/commerce/orders/' . $order->order_id . '/payment', '', t('Capture'), t('Cancel'), 'confirm');
  return $form;
}