Question

Sorry if the title's a bit vaque, I promise I'll clear it up bellow:

First of all, a while ago I asked a question about selling serial keys :

How can I execute a custom script after purchase with Ubercart for Drupal

The information I posted there may help clear things up in this question but I doubt it much because this question is a bit more general.

Basically, I don't want to execute my custom code until I know the payment has been cleared and the moneys in my account. I was a bit unsure what the conditional action thats trigger is 'Customer completes check out' did though? When it says they completed checkout does it necessarily mean successfully and the money is in my account or not?

If not, how do I make Ubercart wait until it knows I've got the money from any PSP (e.g. Google Checkout, PayPal, etc) to execute my custom code? I can't work it out, is it even possible?

Was it helpful?

Solution

It's not documented or exposed as something that should be reliable but I think that using the 'Customer completes check out' trigger is the way to go.

Bear in mind that the following applies to Ubercart 6.x-2.4. (Latest version as of today)

From what I looked at the code, it seems that the trigger is only executed on successful orders. Whether a successful order means that you have received payment, that depends a lot on your current configuration and the different payment gateways or method you are using, but in general situations and configuration.

That trigger is only launched from one function:

function uc_cart_complete_sale($order, $login = FALSE);

If you do a module-wide search on when that function is executed, it should give you a rough idea on the different situations. Basically I found out that it's being executed from a few payment modules (paypal and 2checkout for example) as well as when you reach the cart/checkout/complete drupal page, which is generally on successful orders. The paypal module, which you specifically asked, seems to be calling that function when a 'Completed' IPN status is received.

It shouldn't be hard to try out a few purchases (right and wrong) and see if your trigger executes only when the order is properly charged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top