Skip to Content Skip to Menu

[SOLVED] CB Subs Promotions action after subscription

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 327
  • Thanks: 42
  • Karma: 9
7 years 5 months ago - 7 years 5 months ago #288605 by cpaschen
We're setting up a subscription promotion that uses the value in a CB field.
The value will get automatically populated (via other external means) from the 'balance' that is in a user's Alta User Points account.

When a subscription is process, I need to run an auto action to update the Alta User Points balance. I can figure out how to do that (either PHP or query), but not sure on a couple things.

1. What trigger would be best to use?
I need it to process immediately after a subscription has been fully completed (and the promotion discount actually used).

2. How to determine the promotion amount used
Will the amount that was used by the promotion be available via any var?
Or is there an easy way to query some other table to determine how much was just used?
BTW ... I know that the amount used can be deducted from the value of the cb field; however, I need to do the same to another table.
I also know that I could compare the cb field value to the balance in Alta User Points; however, there is a possibility (even if small) that the balance in AltaUP could get changed between the start and end of the subscription process. So I really need to have a reliable way to determine (from cb) the amount of discount used by cb for the promotion.

Thanks.
Last edit: 7 years 5 months ago by krileon. Reason: Added [SOLVED] tag to subject

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 68605
  • Thanks: 9108
  • Karma: 1434
7 years 5 months ago #288612 by krileon
Replied by krileon on topic CB Subs Promotions action after subscription

1. What trigger would be best to use?

The below is the best way to act on subscription state changes.

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

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

2. How to determine the promotion amount used

Theoretically you'd be applying the entire amount of the field. There's no way for a user to select how much of the field value would apply so you'd apply all of it then reset it to 0 after they subscribed. If you need significantly more advanced usage you've to dig deeper into using PHP in a Code action to parse out basket items. More specifically you'd need to act on onCPayAfterPaymentStatusUpdateEvent where it becomes more complicated to configure all of this; the below should work to get you started, but you'll then want to review the affiliate tracking plugins for API usages.

Global
Triggers: onCPayAfterPaymentStatusUpdateEvent
User: Automatic
Access: Everybody
Conditions
1: [var4] Is REGEXP /Completed|Processed/

Examples:
components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/plugin/cbsubspostafpro/cbsubs.postafpro.php
components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/plugin/cbsubspiwik/cbsubs.piwik.php
components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/plugin/cbsubsgoogleanalytics/cbsubs.googleanalytics.php


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.

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 327
  • Thanks: 42
  • Karma: 9
7 years 5 months ago #288614 by cpaschen
Replied by cpaschen on topic CB Subs Promotions action after subscription
I don't need to change how much was used (or let the user do that). I just need to know:

- what was the value of the field BEFORE the payment
- what was the value of the field AFTER the payment (which would normally be 0; however, there is a good chance that the amount of the field is greater than the checkout price, so there would be some 'left over' in the field]

Can you explain the difference (i.e. when they are specifically triggered) for:

* onCPayUserStateChange
* onCPayAfterPaymentStatusUpdateEvent

And do either of them have a variable that would indicate the value of the cb field used for discount BEFORE and AFTER the discount was used?

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

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 327
  • Thanks: 42
  • Karma: 9
7 years 5 months ago #288615 by cpaschen
Replied by cpaschen on topic CB Subs Promotions action after subscription
One other thing I just thought of ...

Is there any 'trigger' that happens whenEVER a cb custom field's value is changed that has a BEFORE and AFTER variable?

(something like onCBFieldChange?)

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 68605
  • Thanks: 9108
  • Karma: 1434
7 years 5 months ago #288621 by krileon
Replied by krileon on topic CB Subs Promotions action after subscription
Looked into this further. You don't need to do any of this. Create an integer field where you'll keep track of the users points (you can update it with CB Auto Actions or by whatever means you like). Next create the following promotion usage.

The promotion is: A fixed amount from a CB field
CB Field containing amount: YOUR_INTEGER_FIELD_HERE
Deduct used amount from CB field once payment is completed: Yes, remove amount from CB field after payment is completed

This will cause the promotion to automatically handle adjusting the field based off the basket.


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.

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 327
  • Thanks: 42
  • Karma: 9
7 years 5 months ago #288622 by cpaschen
Replied by cpaschen on topic CB Subs Promotions action after subscription
Yes, I DO need to do this. My workflow is already based on what you mentioned.

However, as indicated originally, after the promotion use happens (and that cb field gets changed) I need to push that change back out to Alpha User Points.

I can not JUST use the CB field for tracking - I need to update Alta User Points due to other required functionality required on the site (that cb can't, and shouldn't, handle).

BTW ... I already have the functionality to update the field from Alta User Points into the cb field, and I have a work-around (comparing values the value of the cb field against AUPs point balance).

If there is no trigger for something like onFieldChange (with 'before' and 'after' variables), then I just need to know ...

What trigger should I use that would fire right after those points are deducted from the cb field via the promotion use?

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

Moderators: beatnantkrileon
Powered by Kunena Forum

Facebook Twitter LinkedIn