Tags/topics: 
2
Answers
Vote up!
2
Vote down!

How can I make a robust payment received rule?

I created a new order state and status called Payment received. I set up a rule: when the order's first paid in full, update the order state to Payment received. I modified the checkout rule Update the order status on checkout completion to make sure that it didn't overwrite the state set in my new rule. To test the rule I used commerce_no_payment. The test fails because the event When an order is first paid in full is called before commerce_checkout_form_submit() which changes the order's state again (to checkout_payment, then checkout_complete).

I presume I can fix this behaviour by using a presave rule that checks the balance and order state, and if less than or equal to zero and in the pending state then change to payment received, but obviously this doesn't feel as neat as using When an order is first paid in full. I'd expect that most of the time the notification from my payment method will occur later than it does for commerce_no_payment, but I worry about assuming that (ie I'd like to have a system that could cope with an absolutely immediate payment notification).

Any suggestions?
(original Q)

Asked by: AndyF
on October 18, 2012

2 Answers

Vote up!
3
Vote down!

The solution here should be to change the approach. Instead of the rule executing every time the "When an order is first paid in full" event is triggered, there needs to be a condition that says the order status update should only happen on this event if the order is in a non-checkout status. Then an additional rule that executes on the "Completing the checkout process" should be added that updates the order status if the balance of the order is less than or equal to $0. This will cover both cases - if the payment completes before checkout or after.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Oct 18, 2012