function commerce_stripe_cardonfile_create_form in Commerce Stripe 7
Same name and namespace in other branches
- 7.3 commerce_stripe.module \commerce_stripe_cardonfile_create_form()
- 7.2 commerce_stripe.module \commerce_stripe_cardonfile_create_form()
Card on file callback: create form
1 string reference to 'commerce_stripe_cardonfile_create_form'
File
- ./
commerce_stripe.module, line 839 - This module provides Stripe (http://stripe.com/) payment gateway integration to Commerce. Commerce Stripe offers a PCI-compliant way to process payments straight from you Commerce shop.
Code
function commerce_stripe_cardonfile_create_form($form, &$form_state, $op, $card_data) {
// Pass along information to the validate and submit handlers.
$form_state['card_data'] = $card_data;
$form_state['op'] = $op;
$stripe_integration = _commerce_stripe_load_setting('integration_type', STRIPE_DEFAULT_INTEGRATION);
if ($stripe_integration === 'stripejs') {
_commerce_stripe_form_add_credit_card_form($form);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add card'),
);
}
elseif ($stripe_integration === 'checkout') {
// Stub this out so that making this the default card doesn't break.
$form['credit_card'] = array(
'#tree' => TRUE,
);
$order_total = array(
'amount' => 0,
'currency_code' => commerce_default_currency(),
);
$checkout_currency = _commerce_stripe_load_setting('stripe_currency');
// Since there is no associated order, just use the logged-in user's email
// address.
$email = $GLOBALS['user']->mail;
// Add Checkout settings.
$checkout_settings = _commerce_stripe_load_setting('checkout_settings');
// Change the label to Save, since we are not charging any money.
$checkout_settings['panelLabel'] = t('Save card');
_commerce_stripe_form_configure_stripe_checkout($checkout_settings, $checkout_currency, $email, $order_total);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Enter card details'),
'#description' => t('Please enter your details in the pop-up that opens. They are sent directly to the payment processor and do not pass through this website.'),
);
}
$public_key = _commerce_stripe_load_setting('public_key');
$stripe_token = !empty($form_state['values']['stripe_token']) ? $form_state['values']['stripe_token'] : '';
_commerce_stripe_form_configure_stripe_common($form, $stripe_token, $public_key, $stripe_integration);
$payment_method = commerce_payment_method_instance_load($card_data->instance_id);
$form['credit_card']['cardonfile_instance_default'] = array(
'#type' => 'checkbox',
'#title' => t('Use as default card for payments with %method', array(
'%method' => $payment_method['display_title'],
)),
'#default_value' => FALSE,
);
// Create a billing profile object and add the address form.
$profile = commerce_customer_profile_new('billing', $GLOBALS['user']->uid);
$form_state['commerce_customer_profile'] = $profile;
$form['commerce_customer_profile'] = array();
field_attach_form('commerce_customer_profile', $profile, $form['commerce_customer_profile'], $form_state);
$form['commerce_customer_profile']['#weight'] = -1;
// Add a validation callback so that we can call field_attach functions.
$form['#validate'][] = 'commerce_stripe_cardonfile_create_validate';
commerce_stripe_set_addressfield_class_names($form['address']);
$form['errors'] = array(
'#markup' => '<div id="card-errors"></div>',
);
return $form;
}