You are here

function payment_ubercart_finish in Payment for Ubercart 7.2

Same name and namespace in other branches
  1. 7 payment_ubercart.module \payment_ubercart_finish()

Implements Payment::finish_callback.

1 string reference to 'payment_ubercart_finish'
payment_ubercart_payment_create in ./payment_ubercart.module
Creates a payment for an order.

File

./payment_ubercart.module, line 199
Hook implementations and shared functions.

Code

function payment_ubercart_finish(Payment $payment) {

  // Set messages for the user.
  if (payment_status_is_or_has_ancestor($payment
    ->getStatus()->status, PAYMENT_STATUS_SUCCESS)) {
    drupal_set_message(t('Your payment was successfully completed.'));
    $complete = TRUE;
  }
  elseif (payment_status_is_or_has_ancestor($payment
    ->getStatus()->status, PAYMENT_STATUS_PENDING)) {
    drupal_set_message(t('Your payment is still being processed.'));
    $complete = TRUE;
  }
  else {
    drupal_set_message(t('Your payment was not completed.'), 'error');
    $complete = FALSE;
  }

  // Redirect the user.
  if (empty($_SESSION['cart_order'])) {
    drupal_goto('<front>');
  }
  elseif ($complete) {

    // Tell Ubercart's uc_cart_checkout_complete() to complete the sale.
    $_SESSION['uc_checkout'][$_SESSION['cart_order']]['do_complete'] = TRUE;
    unset($_SESSION['uc_checkout'][$_SESSION['cart_order']]['do_review']);
    drupal_goto('cart/checkout/complete');
  }
  else {
    drupal_goto('cart/checkout');
  }
}