role assignment fails when workflow-ng used to update order to complete

Posts: 15
Joined: 04/09/2008

Ok guys, thanks again for all the great work, perfection is just around the corner.

I am experiencing the following problem:

I have a subscription purchase site with role assignment upon successful payment.

Now, if I enable the workflow profile that moves the order status from Pending to Complete, the role does not get assigned even though the new account is created etc.

If however I disable the workflow profile (leaving the order staus on Pending) and then from the admin control panel I manually update the order status to Complete, then the new role gets assigned successfully.

So it almost looks like the role check occurs at the wrong time during the automated workg\flow, but it occurs at the right time when I manually update the order status.

I think it's a bug but I may be wrong, any hint as to how to observe the workflow steps in the code? Thanks!

Posts: 1850
Joined: 08/07/2007
AdministratoreLiTe!

The way checkout works, payment is received before the user account is created. Since they payment causes the order change, the role is assigned to a non-existent user, and then the order goes through. You should make or modify a workflow configuration to work off the "checkout complete" event, rather than "payment entered". That event happens after all the other checkout processing, so everything will be available to the roles code.

Posts: 15
Joined: 04/09/2008

OK, so what I did was I disabled the Workflow-Ng profile that updated the order from pending to complete when the balance is zero.

Then I created a new workflow profile that fires on Checkout Complete and then checks for Order Status Pending, and if so updates the order from Pending to Complete (hopefully, the Order Pending still means that the payment has been made). Everything seems to work fine now after doing that.

Now though, I see that in order for the Checkout to be Complete, the user MUST get back to the site after paying eg. at Paypal. So what if the user closes the browser without returning to the site if paying at the external server? (Sorry if this question has been asked before, it sure looks like an importan topic).

Posts: 1850
Joined: 08/07/2007
AdministratoreLiTe!

I would have the condition that the balance is zero, rather than checking for Pending. That's the real reason you want to set it to Complete.

Posts: 15
Joined: 04/09/2008

Looks like it is working now, very cool.

So the workflow I am using now is:

On Checkout Complete, if Balance <= 0, then Order Status = Complete

However I am still not quite clear as to what triggers the Checkout Complete event.

Posts: 5
Joined: 08/28/2007

I am also struggling with this.

The Product is a 1 year subscription set up as per
http://www.ubercart.org/docs/user/3366/selling_site_access_role_promotio...

I have tried Test gateway, set as checked
"Attempt to process credit card payments at checkout".
in admin/store/settings/payment/edit/methods

in workflow_ng I have
"Update order status on full payment" set to condition
"Check the order Balance" <= 0

action
"Update the order status" > Completed

The order goes through, new user created, order set to complete but no role added

Product > edit > features set up as
Role assignment
SKU: Any
Role: member
Expiration: 1 year(s)
Shippable: No
Multiply by Quantity: No

If I set Test gateway
"Attempt to process credit card payments at checkout". as unchecked
I have to go in and process credit card manually and then the role add works

The role also fails to be added using Paypal Standard sandbox (which itself work fine).

My conclusions so far are:
workflow_ng "Update order status on full payment" is working, if I disable this rule the order status hangs at pending

uc_roles only works when I manually process the CC, it does not pick up the process when I set it to automatically complete (which is a 'must have')

Adding another workflow_ng rule "register user to member role" to pick up 'registered user' with 'authenticated user' status and giving it a new role "member" does not seem to work at all. I even added a 'log to watchdog' action after it which *does* work. Bizarre ;-(

My next step I guess will be to add a watchdog line to
function workflow_ng_action_user_addrole()
and see if the action is passing through there and with which $settings

uc_roles writes to uc_roles_products OK though I don't have anything to compare it with.

Any hints on how best to debug this much appreciated

Posts: 15
Joined: 04/09/2008

Well this sounds like the problem I was having too. From what written above though, the payment arrives before the new account is created. Therefore, if the Payment Complete triggers the order change, then the role cannot be assigned because the new user hasn't be created yet. But if the Checkout Complete triggers the order change, then it looks like by then the new account has already be created and therefore the role can be succesfully assigned.

So try disabling the current profile and create a new one triggered by Checkout Complete instead of by the Payment Received.

It'be great to have some kind of pictorial illustration or flowchart of the actual workflow events in the documentation.

Posts: 5
Joined: 08/28/2007

You have pointed me to something, it is not quite all there yet but it's much less puzzling,

"I'll be back!"
woohoo, opensource at it's best Eye-wink

Well I have managed to get the workflow to work, after a fashion.
Two rules:

workflow
Update order status on full payment
Invoked on event: A payment gets entered for an order
condition: check order balance <= 0
action: update order status to complete
(action: Log to watchdog)

Checkout complete
Invoked on event: Customer completes checkout
condition: Order status Completed
action: Add user role
(action: Log to watchdog)

The role is set for the user (by function workflow_ng_action_user_addrole() in workflow_ng_user.inc ), but not the expiration stuff that gets done when I do it manually
This appears to be because the uc_roles module is invoked when the CC is manually charged, but not when set to do so automatically. This anomaly probably lies in payment.module, but I'm not sure yet.

More later.

Posts: 15
Joined: 04/09/2008

Well I think the second rule is superfluous because that's what already happens with the role assignment config (I guess in the Product Settings config if I remember correctly).

The problem is that the payment gets received too early for the role assignment to be delivered to the new account (the new account does not exist yet), so Payment Received is the wrong event. The right event must be Checkout Complete because it happens at the very end of the process, so:

"On Checkout Complete, if Balance <=0 Then Order Status = Complete"

(then the Role gets assigned on Order Complete to an existing account - as set from the Product Settings config).

Posts: 5
Joined: 08/28/2007

You are absolutely right, the role is created and expiration set with rule

"On Checkout Complete, if Balance <=0 Then Order Status = Complete"

Thanks for your help.