function commerce_authnet_acceptjs_form_elements in Commerce Authorize.Net 7
Return the form elements for Accept.js.
Parameters
array $payment_method: The payment method.
Return value
array The form elements.
2 calls to commerce_authnet_acceptjs_form_elements()
- commerce_authnet_acceptjs_submit_form in includes/
commerce_authnet.acceptjs.inc - Payment method callback: checkout form.
- commerce_authnet_form_commerce_cardonfile_card_form_alter in ./
commerce_authnet.module - Implements hook_form_FORM_ID_alter().
File
- includes/
commerce_authnet.acceptjs.inc, line 587 - Includes the Accept.js payment method callbacks.
Code
function commerce_authnet_acceptjs_form_elements(array $payment_method) {
$form = array();
// @todo change to proper library.
if ($payment_method['settings']['txn_mode'] == AUTHNET_TXN_MODE_DEVELOPER) {
$form['#attached']['library'][] = array(
'commerce_authnet',
'commerce_authnet.acceptjs.sandbox',
);
}
else {
$form['#attached']['library'][] = array(
'commerce_authnet',
'commerce_authnet.acceptjs.production',
);
}
$form['#attached']['library'][] = array(
'commerce_authnet',
'commerce_authnet.acceptjs.accept',
);
$form['#attached']['css'][] = drupal_get_path('module', 'commerce_payment') . '/theme/commerce_payment.theme.css';
$js_settings = array(
'clientKey' => $payment_method['settings']['client_key'],
'apiLoginID' => $payment_method['settings']['login'],
'paymentMethodType' => 'credit_card',
);
// Allow other modules to alter the JS settings.
drupal_alter('commerce_authnet_acceptjs_settings', $js_settings, $payment_method);
$form['#attached']['js'][] = array(
'data' => array(
'commerceAuthorizeNet' => $js_settings,
),
'type' => 'setting',
);
$form['credit_card'] = array(
'#type' => 'container',
);
$form['credit_card']['#attributes']['class'][] = 'acceptjs-form';
$form['credit_card']['errors'] = array(
'#type' => 'hidden',
);
$form['credit_card']['cc'] = array(
'#type' => 'container',
);
// Fields placeholder to be built by the JS.
$form['credit_card']['cc']['credit_card_number'] = array(
'#type' => 'textfield',
'#title' => t('Card number'),
'#attributes' => array(
'placeholder' => '•••• •••• •••• ••••',
'autocomplete' => 'off',
'autocorrect' => 'off',
'autocapitalize' => 'none',
'id' => 'credit-card-number',
'required' => 'required',
),
'#label_attributes' => array(
'class' => array(
'js-form-required',
'form-required',
),
),
'#maxlength' => 20,
'#size' => 20,
);
$form['credit_card']['cc']['expiration'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'credit-card-form__expiration',
'container-inline',
),
),
);
$form['credit_card']['cc']['expiration']['month'] = array(
'#type' => 'textfield',
'#title' => t('Month'),
'#attributes' => array(
'placeholder' => 'MM',
'autocomplete' => 'off',
'autocorrect' => 'off',
'autocapitalize' => 'none',
'id' => 'expiration-month',
'required' => 'required',
),
'#label_attributes' => array(
'class' => array(
'js-form-required',
'form-required',
),
),
'#maxlength' => 2,
'#size' => 3,
);
$form['credit_card']['cc']['expiration']['divider'] = array(
'#type' => 'item',
'#title' => '',
'#markup' => '<span class="credit-card-form__divider">/</span>',
);
$form['credit_card']['cc']['expiration']['year'] = array(
'#type' => 'textfield',
'#title' => t('Year'),
'#attributes' => array(
'placeholder' => 'YY',
'autocomplete' => 'off',
'autocorrect' => 'off',
'autocapitalize' => 'none',
'id' => 'expiration-year',
'required' => 'required',
),
'#label_attributes' => array(
'class' => array(
'js-form-required',
'form-required',
),
),
'#maxlength' => 2,
'#size' => 3,
);
$form['credit_card']['cc']['security_code'] = array(
'#type' => 'textfield',
'#title' => t('CVV'),
'#attributes' => array(
'placeholder' => '•••',
'autocomplete' => 'off',
'autocorrect' => 'off',
'autocapitalize' => 'none',
'id' => 'cvv',
'required' => 'required',
),
'#label_attributes' => array(
'class' => array(
'js-form-required',
'form-required',
),
),
'#maxlength' => 4,
'#size' => 4,
);
// To display validation errors.
$form['credit_card']['cc']['payment_errors'] = array(
'#type' => 'markup',
'#markup' => '<div id="payment-errors"></div>',
'#weight' => -200,
);
// Populated by the JS library after receiving a response from AuthorizeNet.
$form['credit_card']['cc']['data_descriptor'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'accept-js-data-descriptor',
),
),
);
$form['credit_card']['cc']['data_value'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'accept-js-data-value',
),
),
);
$form['credit_card']['cc']['last4'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'accept-js-data-last4',
),
),
);
$form['credit_card']['cc']['expiration_month'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'accept-js-data-month',
),
),
);
$form['credit_card']['cc']['expiration_year'] = array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'accept-js-data-year',
),
),
);
return $form;
}