You are here

function commerce_payflow_link_submit_form_submit in Commerce PayPal 7.2

Payment method callback: submit form submission.

File

modules/payflow/commerce_payflow.module, line 548
Implements PayPal Payments Advanced (U.S. only) and Payflow Link Hosted Checkout pages and Transparent Redirect.

Code

function commerce_payflow_link_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) {

  // Update the order to reference the Payflow Link payment method.
  $order->data['payment_method'] = $payment_method['instance_id'];

  // Generate a payment redirect key and Secure Token ID.
  $order->data['payment_redirect_key'] = drupal_hash_base64(time());
  $order->data['commerce_payflow'] = array(
    'tokenid' => str_replace('.', '', uniqid('', TRUE)),
  );

  // Request a token from Payflow Link.
  $payment_method['settings']['ba_desc'] = trim($payment_method['settings']['ba_desc']);
  if (!empty($payment_method['settings']['ba_desc'])) {
    $token = commerce_payflow_link_create_secure_token($payment_method, $order, $payment_method['settings']['ba_desc']);
  }
  else {
    $token = commerce_payflow_link_create_secure_token($payment_method, $order);
  }

  // If we got one back...
  if (!empty($token)) {

    // Set the Payflow Link data array and proceed to the redirect page.
    $order->data['commerce_payflow']['token'] = $token;
    return TRUE;
  }
  else {

    // Otherwise show an error message and remain on the current page.
    drupal_set_message(t('Communication with PayPal failed. Please try again or contact an administrator to resolve the issue.'), 'error');
    return FALSE;
  }
}