You are here

function commerce_coupon_commerce_checkout_form_review_validate in Commerce Coupon 7.2

Form validate callback: validate and record coupon transactions.

1 string reference to 'commerce_coupon_commerce_checkout_form_review_validate'
commerce_coupon_form_commerce_checkout_form_alter in ./commerce_coupon.module
Implements hook_form_FORM_ID_alter().

File

./commerce_coupon.module, line 2173
Provides coupon functionality for Drupal Commerce.

Code

function commerce_coupon_commerce_checkout_form_review_validate(&$form, &$form_state) {

  // If the form was submitted via the continue button and there are no errors:
  if (end($form_state['triggering_element']['#array_parents']) == 'continue' && !form_get_errors()) {
    $order = commerce_order_load($form_state['order']->order_id);
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

    // Allow modules to perform a final validation after checkout is done, but
    // before the payment module processes payment.
    foreach (module_implements('commerce_coupon_final_checkout_validate') as $module) {

      // If a module successfully creates a transaction, it must return any
      // new transaction ids. We store them on the order mostly so that if the
      // payment form loads again, we can do a rollback. Modules implementing
      // this hook must do their own error generation using form_set_error.
      $transaction_ids = module_invoke($module, 'commerce_coupon_final_checkout_validate', $form, $form_state, $order_wrapper);
      if (!empty($transaction_ids)) {
        $order->data['coupon_transaction_ids'][$module] = $transaction_ids;
        commerce_order_save($order);
      }
    }
  }
}