Skip to Content Skip to Menu

[SOLVED] onCPayAfterPaymentStatusUpdateEvent and var3

  • lousyfool
  • lousyfool
  • OFFLINE
  • Posts: 141
  • Thanks: 46
  • Karma: 5
8 years 7 months ago - 8 years 7 months ago #280385 by lousyfool
Hi,

I need to run a query once the plan with ID 1 has been purchased, meaning it's been in a basket and status is "Completed".

Created an Auto Action of type Query,
Trigger: onCPayAfterPaymentStatusUpdateEvent
Conditional 1: [var4] Equal to Completed
Conditional 2: [var3_plan_id] Equal to 1

Conditional 2 keeps failing (also if I use only [var3]):
Code:
Conditional 2 failed for 470: [var3_plan_id] Equal To 1
even though plan #1 is involved, and the record in #__cbsubs_subscriptions exists and has "1" in field plan_id for the user.

What am I doing wrong? A hint would be greatly appreciated.
Last edit: 8 years 7 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48495
  • Thanks: 8284
  • Karma: 1443
8 years 7 months ago #280450 by krileon
Replied by krileon on topic onCPayAfterPaymentStatusUpdateEvent and var3
That trigger is no ideal for what you're wanting to do. I recommend using the below.

Plan Active
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var3] Equal To PLAN_ID_HERE
2: [var2] Equal To A

Plan Expired
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var3] Equal To PLAN_ID_HERE
2: [var2] Not Equal To A


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: nant

Please Log in or Create an account to join the conversation.

  • lousyfool
  • lousyfool
  • OFFLINE
  • Posts: 141
  • Thanks: 46
  • Karma: 5
8 years 7 months ago #280496 by lousyfool
Replied by lousyfool on topic onCPayAfterPaymentStatusUpdateEvent and var3
Hi Kyle,

Thanks for your effort, but onCPayUserStateChange fires too early, way before the tables I need to query are populated. So, I went back to using onCPayAfterPaymentStatusUpdateEvent and worked my checks into the query.
It was a bit fiddly (a lot of trial & error as you said elsewhere ;) ) but now it works the way I need it, I'm happy, and I'm marking this thread solved.

BTW, when using "IF" conditions in any form in an Auto Action of type Query, it causes strange effects, like a field name "slaughtered" and ` changed to '.
Example: the first `cb_field_name` in the code gets turned into `cb_fiel' or similar, causing a syntax error.

So, it might be worth mentioning that instead of "IF" conditions in Auto Action queries one should use "CASE" - which are passing unharmed.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48495
  • Thanks: 8284
  • Karma: 1443
8 years 7 months ago - 8 years 7 months ago #280500 by krileon
Replied by krileon on topic onCPayAfterPaymentStatusUpdateEvent and var3
The phpdoc and expected values of onCPayAfterPaymentStatusUpdateEvent are as follows if you need to use it then. We use it primarily in the tracking integrations like iDevAffiliate, Piwik, etc..

Code:
/** * Event handler for onCPayAfterPaymentStatusUpdateEvent, called each time an update occurs to the payment status of the payment basket * * Paypal status mappings: * CB Unified status Paypal status * Completed <-- Completed * Processed <-- Processed, Canceled_Reversal * Denied <-- Denied, Expired, Failed, Voided * Refunded <-- Reversed, Refunded, Partially-Refunded * Pending <-- Pending, In-Progress * RegistrationCancelled <-- A new cb registration got cancelled by user (e.g. paypal cancel payment button) * * @param UserTable $user User paying the payment basket * @param cbpaidPaymentBasket $paymentBasket Payment basket * @param cbpaidSomething[] $subscriptions Subscriptions in the basket * @param string $unifiedStatus New Unified status (see above) * @param string $previousUnifiedStatus Previous Unified status (see above) * @param string $eventType type of event (paypal type): 'web_accept', 'subscr_payment', 'subscr_signup', 'subscr_modify', 'subscr_eot', 'subscr_cancel', 'subscr_failed' * @param cbpaidPaymentNotification $notification notification object of the payment * @return void */ public function onCPayAfterPaymentStatusUpdateEvent( &$user, &$paymentBasket, &$subscriptions, $unifiedStatus, $previousUnifiedStatus, $eventType, &$notification ) {}

I've had no issues with IF usages in queries, but depends on your usage I guess. I would not use it to add to the SQL structure, but to condition a string value. Example as follows.

'[cb:if username="demo"]DEMO[/cb:if][cb:if username="admin"]ADMIN[/cb:if]'

All substitutions must be treated as strings for reliable usage.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 8 years 7 months ago by krileon.
The following user(s) said Thank You: lousyfool

Please Log in or Create an account to join the conversation.

  • lousyfool
  • lousyfool
  • OFFLINE
  • Posts: 141
  • Thanks: 46
  • Karma: 5
8 years 7 months ago - 8 years 7 months ago #280503 by lousyfool
Replied by lousyfool on topic onCPayAfterPaymentStatusUpdateEvent and var3
Thanks again, Kyle!

krileon wrote: The phpdoc and expected values of onCPayAfterPaymentStatusUpdateEvent are as follows if you need to use it then.


Yup, by now I'm finding my way better around in your code, so I had that figured already before my initial post. ;)
But your posting the reference here may well help others.

krileon wrote: I've had no issues with IF usages in queries, but depends on your usage I guess. I would not use it to add to the SQL structure, but to condition a string value. Example as follows.

'[cb:if username="demo"]DEMO[/cb:if][cb:if username="admin"]ADMIN[/cb:if]'


Maybe you misunderstood, I'm talking the (My)SQL "IF()" function, like e.g. described here: www.w3resource.com/mysql/control-flow-functions/if-function.php
Again, after much trial and error it was clear that's definitely something Auto Action queries don't like, resulting in errors.
Last edit: 8 years 7 months ago by lousyfool.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48495
  • Thanks: 8284
  • Karma: 1443
8 years 7 months ago #280508 by krileon
Replied by krileon on topic onCPayAfterPaymentStatusUpdateEvent and var3
Strange, should work fine. Have added a bug ticket to test and look into it later. Can you provide an example of your exact usage that caused it to fail?

forge.joomlapolis.com/issues/5911


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum