function commerce_braintree_express_checkout_submit in Commerce Braintree 7.3
Form submit handler for Express Checkout payload submission.
1 string reference to 'commerce_braintree_express_checkout_submit'
- commerce_braintree_express_checkout_form_views_form_commerce_cart_form_default_alter in modules/
commerce_braintree_express_checkout/ commerce_braintree_express_checkout.module - Implements hook_form_FORM_ID_alter().
File
- modules/
commerce_braintree_express_checkout/ commerce_braintree_express_checkout.module, line 354 - Provides integration PayPal Express Checkout for Braintree.
Code
function commerce_braintree_express_checkout_submit($form, &$form_state) {
$order = $form_state['order'];
$payment_method = commerce_payment_method_instance_load(COMMERCE_BRAINTREE_EXPRESS_CHECKOUT_INSTANCE_ID);
// If a payload was provided, extract it and grab the nonce.
if (!empty($form_state['values']['commerce_braintree_payload'])) {
$payload = json_decode($form_state['values']['commerce_braintree_payload'], TRUE);
if (empty($payload['nonce'])) {
watchdog('commerce_braintree_express_checkout', 'Payload submitted without a nonce.', array(), WATCHDOG_ERROR);
return;
}
// Append the payload data to the order object.
$order->data['commerce_braintree_express_checkout'] = $payload;
if (empty($order->mail)) {
$order->mail = $payload['details']['email'];
}
// Force the payment method on the order to be Express Checkout.
$order->data['payment_method'] = COMMERCE_BRAINTREE_EXPRESS_CHECKOUT_INSTANCE_ID;
// Create a billing information profile for the order with the available info.
if (!empty($payment_method['settings']['update_billing_profiles'])) {
commerce_braintree_express_checkout_create_customer_profile($order, 'billing', $payload, TRUE);
}
// If the shipping module exists on the site, create a shipping information
// profile for the order with the available info.
if (module_exists('commerce_shipping') && !empty($payment_method['settings']['update_shipping_profiles'])) {
commerce_braintree_express_checkout_create_customer_profile($order, 'shipping', $payload, TRUE);
}
// Save the order updates.
commerce_order_save($order);
}
}