Auto Action request: Coupon use trigger?

5 years 3 months ago #309049 by fdinkler
I need to populate a profile field based on user's submitting a specific coupon at registration time.
Can you provide the correct trigger and what var to check? (assuming this is possible...)
Thanks,,,
Fred

Please Log in to join the conversation.

5 years 3 months ago #309053 by krileon
Replied by krileon on topic Auto Action request: Coupon use trigger?
There's not a trigger specifically for that in CBSubs. You'd need to act on onCPayAfterPaymentStatusUpdateEvent then have to check the basket if a coupon was used. The variables for that trigger are as follows.

/**
 * Handles changes of payment basket $paymentBasket payment statuses events
 * This function may be called more than one time for events different than the Completed or Processed state if there are multiple notifications
 *
 * $unifiedStatus status mappings with e.g. Paypal status:
 * 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
 * @param  cbpaidPaymentBasket            $paymentBasket           CBPaid Payment basket being paid (corresponding to PayPal variable names)
 * @param  cbpaidUsersubscriptionRecord[] $subscriptions           CBPay Subscriptions being paid
 * @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 )

This means access to the basket object would be done through var2. The tricky part is the coupons are stored as integration parameters, but CB Auto Actions will attempt to convert other param objects into substitutions if possible. So the below is normally what you'd do using API.

$integrationParams = $paymentBasket->getParams( 'integrations' );
$coupons = $integrationParams->get( 'promotions_coupons', null );

The coupons are then just delimitered with |*| like any multiselect field would be. To access this with substitutions you should be able to use the below.

[var2_integrations]

Normally CB Auto Actions would try to parse this into more substitutions, but it's just a JSON string so it won't do anything with it at this time. This means with the above you'd get something like the below.

{"promotions_coupons":"20-off"}

That'd be what it would look like if a coupon with a code of 20-off was used. Should work fine using a Contains operator in your condition to check for your coupon code though. Example as follows.

[var2_integrations] Does Contain 20-off

To be sure the basket is completed you'll need to also check the status. So the below conditions should ensure the basket is completed and it was completed with your specific coupon.

1. [var4] Is REGEX /Completed|Processed/
2. [var2_integrations] Does Contain 20-off


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: fdinkler

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.620 seconds

Facebook Twitter LinkedIn