2

I am using ubercart on drupal 7.The ubercart version is 3.x. I have tried to search a lot for a hook which runs after payment is successful.I want to insert few more details to the DB after that. Is there any hook for complete and successful payment. I believe most of projects would involve some work after payment so there has to be a hook or way to do it.

Thanks to all Smith

Smith
  • 1,266
  • 13
  • 31

3 Answers3

3

Use hook_uc_order() (documentation) with $op = 'save' case. And check $order->order_status for the status of the order.

Junaid
  • 488
  • 1
  • 5
  • 17
  • This is not correct, I tried this with no luck, after much testing I was able to figure out what values actually correspond to a successful order completion, see my answer. – DrCord Jan 20 '15 at 19:11
1

Using hook_uc_order the conditions needed to figure out when an order is successfully completed are:

  1. $op == 'update'
  2. $order->order_status == 'payment_received'
  3. $arg2 == 'completed'

I am unsure if #2 is absolutely needed, but it doesn't seem to hurt.

So this code will let you act when an order is successfully completed:

function MODULE_NAME_uc_order($op, $order, $arg2) {
    if($op == 'update' && $order->order_status == 'payment_received' && $arg2 == 'completed'){
        //do something on successful order completion
    }
}
DrCord
  • 3,917
  • 3
  • 34
  • 47
0

I do not think there is a specific hook for this, instead use rules and actions, simply create an action as per the code below, then go to configuration, workflow, rules and add your action to the existing rule "Update order status on full payment" or create a separate rule making sure you add a condition to check that the value order:payment-balance is <= 0.

/**
 * Implements hook_rules_action_info().
 *
 * Add rules action to process order after payment
 */
function my_module_rules_action_info() {
  $order_arg = array(
    'type' => 'uc_order',
    'label' => t('Order'),
  );

  $actions['my_module_action_process_order'] = array(
    'label' => t('My Module Process Ubercart Order'),
    'group' => t('My Module'),
    'base' => 'my_module_action_process_order',
    'parameter' => array(
      'order' => $order_arg,
    ),
  );

  return $actions;
}

function my_module_action_process_order($order) {
   // Do Whatever Here
}
PAB
  • 51
  • 1
  • 3