Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

Auto Action that will fire ONLY on the following recurring payments but not on the first one

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 9 months ago #276981 by ricco1
Hi,

Could you tell us how to set up a CBAutoAction that will fire only when the following recurring payments are received but not when the first payment is received?

For example:

User subscribes

Recurring payment 1 is received = CBAutoAction will NOT fire

Recurring payment 2 is received = CBAutoAction will fire

Recurring payment 3 is received = CBAutoAction will fire

and so on...

Thank you

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 9 months ago #276985 by krileon
I've already explained how all of this is done in my below reply.

www.joomlapolis.com/forum/153-professional-member-support/232610-auto-action-that-is-triggered-on-recurring-payments#276955

The subscr_payment $eventType is only used for recurring payments. The initial payment (payment 1) is subscr_signup. So conditioning against subscr_payment should only react for payment 2 and onward.

There is no specific trigger for what you're wanting. You need to condition the variables of the trigger supplied in your other topic.


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

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

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 9 months ago - 8 years 9 months ago #276987 by ricco1
Sorry, but I think you are wrong.

Here is an answer from bershika:

"

Typically subscr_signup is sent after subscr_payment(3 sec apart), but the sequence is not guaranteed. PayPal recommendation is to rely on subscr_signup. Read more here:

stackoverflow.com/questions/10541615/paypal-subscriptions-and-ipn/10693709#10693709

and here:

www.mixedwaves.com/2010/11/paypal-subscriptions-ipn-demystified/

"

They are almost the same.
Last edit: 8 years 9 months ago by ricco1.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 9 months ago - 8 years 9 months ago #277015 by krileon
The subscriptions array of objects has previous_recurrings_used to keep track of recurring that have occurred. So the following condition might work.

[var3_0_previous_recurrings_used] Greater Than 1

There could be issues with this though if there are multiple subscriptions in a basket.

You could act on the user state change instead though using the onCPayUserStateChange trigger and the below conditions to catch auto renewals. This would work with multiple subscriptions in a basket.

[var2] Equal To A
[var6] Equal To PaidSubscription
[var7] Equal To R
[var10] Equal To 1

See the below phpdoc for onCPayUserStateChange to help with conditions.

Code:
/** * Called at each change of user subscription state due to a plan activation or deactivation * * @param UserTable $user The user owning the $subscription with that $planId * @param string $status New status: 'A'=Active, 'X'=Expired, 'C'=Cancelled * @param int $planId Plan Id which is changing status * @param int $replacedPlanId Replaced Plan Id in case of an upgrade * @param ParamsInterface $integrationParams Integration parameters for that plan $planId * @param string $cause 'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied' * @param string $reason 'N' new subscription, 'R' renewal, 'U'=update ) * @param int $now Unix time * @param cbpaidSomething $subscription Subscription/Donation/Merchandise record * @param int $autorenewed 0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R') * @return void */ public function onCPayUserStateChange( $user, $status, $planId, $replacedPlanId, $integrationParams, $cause, $reason, $now, $subscription, $autorenewed )

Below is a set of IF conditions checking for various payment events (taken from CBSubs Emails).

Code:
if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) { $event = 'activation'; } elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) { $event = 'renewal'; } elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 1 ) ) { $event = 'autorenewal'; } elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) { $event = 'expired'; } elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) { $event = 'deactivation'; } elseif ( ( $cause == 'Pending' ) && ( $reason != 'R' ) && ( $autorenewed == 0 ) ) { $event = 'pendingfirst'; } elseif ( ( $cause == 'Pending' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) { $event = 'pendingrenewal'; }


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 9 months ago by krileon.

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

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 9 months ago - 8 years 9 months ago #277032 by ricco1
I think I've found a temporary salvation to my main problem, which was to get all the invoices together with the ones for the following recurring payments, in the order I needed. Like you said PayPal is managing the statements, so we only need the invoices for all payments, you’ve already done the rest.

Here are the queries for the fields, which I think are the better solution:
Code:
SELECT `invoice` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `payment_status` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `payment_method` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `txn_id` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `item_number` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `payer_email` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `item_name` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT CONCAT('<strong>Sub-Total:</strong> £', TRUNCATE( `mc_gross` - `tax`, 2 ), '<br /><br />') AS SubTotal FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT CONCAT('<strong>Tax:</strong> £', TRUNCATE( `tax`, 2 ), '<br /><br />') AS tTax FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT TRUNCATE( `mc_gross`, 2 ) FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT `ip_addresses` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT DATE_FORMAT( `time_updated`, '%T - %d %b %Y' ) AS ttime_updated FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `time_updated` DESC LIMIT 1; SELECT DATE_FORMAT( `expiry_date`, '%T - %d %b %Y' ) AS texpiry_date FROM `#__cbsubs_subscriptions` WHERE `user_id` = '[cb:userdata field="user_id" /]' ORDER BY `expiry_date` DESC LIMIT 1;

Here are the 3 queries needed for the auto action:
Code:
UPDATE `#__cbsubs_payment_baskets` SET `invoice` = ( SELECT `invoice` FROM ( SELECT MAX( `invoice` + 1 ) AS `invoice` FROM `#__cbsubs_payment_baskets` ) AS t ) WHERE `user_id` = '[cb:userdata field="user_id" /]'; UPDATE `#__cbsubs_payment_baskets` SET `proformainvoice` = ( SELECT `proformainvoice` FROM ( SELECT MAX( `proformainvoice` + 1 ) AS `proformainvoice` FROM `#__cbsubs_payment_baskets` ) AS t ) WHERE `user_id` = '[cb:userdata field="user_id" /]'; UPDATE `#__cbsubs_payments` SET `invoice` = ( SELECT `invoice` FROM ( SELECT MAX( `invoice` + 1 ) AS `invoice` FROM `#__cbsubs_payments` ) AS t ) WHERE `user_id` = '[cb:userdata field="user_id" /]';

Invoices and proformas are set both but to increment by 0.

I think it’s not the perfect way and you are very welcome to correct me, or tell me. I hope I didn't forget something.

Thank you,
ricco
Last edit: 8 years 9 months ago by ricco1.

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

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 9 months ago - 8 years 9 months ago #277048 by ricco1
And here is a photo of the 2 auto actions needed to update the invoice and the proforma numbers and to send the invoices as emails.



So far its working.

What do you think? Could it be improved?

Thank you
Last edit: 8 years 9 months ago by ricco1.

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

Moderators: beatnantkrileon
Powered by Kunena Forum