You are here

function commerce_paypal_checkout_void_form_submit in Commerce PayPal 7.2

Submit handler: process the void request.

File

modules/checkout/includes/commerce_paypal_checkout.admin.inc, line 166
Administrative forms for the Paypal Checkout module.

Code

function commerce_paypal_checkout_void_form_submit($form, &$form_state) {
  $transaction = $form_state['transaction'];
  $api_client = commerce_paypal_checkout_api_client($form_state['payment_method']['settings']);
  try {

    // This API call doesn't return content, so nothing to check, if no
    // exception is thrown, this means the void operation succeeded.
    $api_client
      ->voidPayment($transaction->remote_id);
    drupal_set_message(t('Transaction successfully voided.'));

    // Set the remote and local status accordingly.
    $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
    $transaction->remote_status = COMMERCE_CREDIT_VOID;

    // Update the transaction message to show that it has been voided.
    $transaction->message .= '<br />' . t('Voided: @date', array(
      '@date' => format_date(REQUEST_TIME, 'short'),
    ));
    commerce_payment_transaction_save($transaction);
  } catch (PayPalCheckoutHttpException $exception) {
    drupal_set_message(t('The void operation failed, so the transaction will remain in a pending status.'), 'error');
  }
  $form_state['redirect'] = 'admin/commerce/orders/' . $form_state['order']->order_id . '/payment';
}