You are here

function uc_stripe_authenticate_payment_form in Ubercart Stripe 7.3

Implements hook_form().

This form allows the user to authenticate in order for their recurring payment to be processed.

1 string reference to 'uc_stripe_authenticate_payment_form'
uc_stripe_menu in ./uc_stripe.module
Implements hook_menu().

File

./uc_stripe.pages.inc, line 9

Code

function uc_stripe_authenticate_payment_form($form, &$form_state, $hash) {
  $form = array();
  $pending_order = db_select('uc_stripe_pending_auth', 'u')
    ->fields('u', array(
    'order_id',
    'completed',
    'rfee_id',
  ))
    ->condition('hash', $hash)
    ->execute()
    ->fetchObject();
  if (!$pending_order) {
    $form['error'] = array(
      '#markup' => t('Sorry, we could not verify your payment details. Please verify the link and try again. Contact support if the problem persists.'),
    );
    return $form;
  }
  $order_id = $pending_order->order_id;
  $completed = $pending_order->completed;
  $rfee_id = $pending_order->rfee_id;
  if ($completed) {
    $form['error'] = array(
      '#markup' => t('This payment has already been verified.'),
    );
    return $form;
  }
  $form['heading'] = array(
    '#markup' => t('<p>Your financial institution has requested additional verification to process your scheduled payment.</p>'),
  );
  $form['order_id'] = array(
    '#type' => 'hidden',
    '#value' => $order_id,
  );
  $form['rfee_id'] = array(
    '#type' => 'hidden',
    '#value' => $rfee_id,
  );
  $form['hash'] = array(
    '#type' => 'hidden',
    '#value' => $hash,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Verify Payment'),
  );
  $order = uc_order_load($order_id);
  $user = user_load($order->uid);
  $payment_method_id = _uc_stripe_get_payment_id($user->uid);
  $stripe_customer_id = _uc_stripe_get_customer_id($user->uid);
  $order_id = $order_id;
  $apikey = variable_get('uc_stripe_testmode', TRUE) ? check_plain(variable_get('uc_stripe_api_key_test_publishable', '')) : check_plain(variable_get('uc_stripe_api_key_live_publishable', ''));
  $settings = array(
    'apikey' => $apikey,
    'methodId' => $payment_method_id,
    'orderId' => $order_id,
  );

  //Attach Stripe v3 JS library and JS for processing payment
  $form['#attached']['js']['https://js.stripe.com/v3/'] = array(
    'type' => 'external',
  );
  $form['#attached']['js'][] = array(
    'data' => array(
      'uc_stripe' => $settings,
    ),
    'type' => 'setting',
  );
  $form['#attached']['js'][] = drupal_get_path('module', 'uc_stripe') . '/js/uc_stripe_process_payment.js';
  $form['#attached']['css'][] = drupal_get_path('module', 'uc_stripe') . '/css/uc_stripe.css';
  return $form;
}