Skip to Content Skip to Menu

CBSubs Auto Actions not firing on PayPal payment completion

  • liaskas
  • liaskas
  • ONLINE
  • Posts: 502
  • Thanks: 42
  • Karma: 3
  • Add-ons
6 days 11 hours ago - 6 days 10 hours ago #342703 by liaskas
Hello,

We are using CBSubs with PayPal on Joomla 5.4.

We are trying to run post-payment logic (VAT / OSS accounting) using CB Auto Actions, but no Auto Action is firing when PayPal payments are completed.

What we have tested and confirmed:

1. Payments do complete successfully in PayPal

2. Rows are correctly written to: #__cbsubs_payment_baskets (payment_status = 'Completed') and #__cbsubs_payments

We tested the following Auto Action triggers:

onCPayAfterPaymentStatusChange
onCPayUserStateChange

Auto Action PHP code does not execute at all -> verified via error_log

Conditions were reduced to a single SQL condition:

SELECT 1
FROM cbsubs_payment_baskets
WHERE user_id = [var1_id]
  AND payment_status = 'Completed'
  AND gateway_account = <paypal_gateway_id>
ORDER BY id DESC
LIMIT 1


Even with minimal PHP code (just logging), no Auto Action is executed

Our questions:

Are CB Auto Actions expected to fire when PayPal payments are completed asynchronously (IPN / delayed completion)?

Which Auto Action trigger is guaranteed to fire after a PayPal payment is finalized and subscriptions are activated?

Is there an official recommended hook for running post-payment accounting logic (VAT / OSS) in CBSubs?

Thank you.Can you please advise?
Thank you.
Last edit: 6 days 10 hours ago by liaskas.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49917
  • Thanks: 8532
  • Karma: 1465
6 days 8 hours ago #342705 by krileon
Your conditions are probably is what is failing. The database state is considered in transit. It can change based off webhooks, what state they're moving into/from, etc..

Are you needing to act on the payment status change or the subscription status change? onCPayAfterPaymentStatusChange is the correct trigger for payment status changes and onCPayUserStateChange is the correct trigger for subscription status changes. With both you should be using the variables already provided to them instead of querying for information. After selecting either trigger you should see what variables are available to them just below the Triggers parameter.

Since you mentioned payment being finalized and subscription being active I'd act on subscription state change with onCPayUserStateChange. The below for example should work fine.

Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
Condition 1
Field: Custom > Value
Custom Value: [var2]
Operator: Equal To
Value: A
Condition 2
Field: Custom > Code
Code:
Code:
return ( $variables['var9']->getCurrentBasket()->gateway_account ?? 0 );
Operator: Equal To
Value: YOUR_PAYPAL_GATEWAY_ID_HERE

This will work on renewals as well. If you only want it on first payment you'll need to add a condition against the $reason. Example as follows.

Field: Custom > Value
Custom Value: [var6]
Operator: Not Equal To
Value: R


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.

  • liaskas
  • liaskas
  • ONLINE
  • Posts: 502
  • Thanks: 42
  • Karma: 3
  • Add-ons
5 days 14 hours ago #342731 by liaskas
Here is what we have currently and the auto action is not fired for some reason.

Payment is being finalized and subscription is active.

Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
Condition 1
Field: Custom > Value
Custom Value: [var2]
Operator: Equal To
Value: A
Condition 2
Field: Custom > Code
Code:Code:return ( $variables->getCurrentBasket()->gateway_account ?? 0 );Operator: Equal To
Value: 5

The code in the action tab is the following:

Method: PHP
Code:
Code:
defined('_JEXEC') or die; require_once JPATH_LIBRARIES . '/oss/cbsubs-oss-handler.php'; oss_handle_cbsubs_payment($variables);

Thank you.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49917
  • Thanks: 8532
  • Karma: 1465
5 days 6 hours ago #342733 by krileon
My example above is a tested working example. Most likely the culprit is whatever code you're trying to include isn't working. For example you do not need the defined check as you're already in Joomla at that point. A simple test is changing your auto action to Email and sending an email to yourself.


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.

  • liaskas
  • liaskas
  • ONLINE
  • Posts: 502
  • Thanks: 42
  • Karma: 3
  • Add-ons
2 days 8 hours ago - 2 days 7 hours ago #342755 by liaskas
I have spent the whole week testing without success, and finally i returned back to the very basic!
My goal is to fire a php code after cb subs payments return complete from paypal.

Auto Action
Global
Triggers: onCPayUserStateChange
Type: Code
User: Automatic
Access: Everybody

Conditions:
Condition 1
Custom Value: [var2]
Operator: Equal To
Value: A
Condition 2
Field: Custom > Code
Code:Code:return ( $variables->getCurrentBasket()->gateway_account ?? 0 );Operator: Equal To
Value: 5

Action:
Method: PHP
Code:
Code:
$mailer = \Joomla\CMS\Factory::getMailer(); $mailer->addRecipient('name@domain.com'); //(where info@domain.com is my e-mail) $mailer->setSubject('OSS PHP AUTO ACTION TEST'); $mailer->setBody('If you receive this email, PHP Auto Actions ARE executing.'); $mailer->Send();

The mail is not sent! Is the code wrong or the auto action is not firing? (tested with more that 10 real payments from clients)

What am i doing wrong?
 
Last edit: 2 days 7 hours ago by liaskas.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49917
  • Thanks: 8532
  • Karma: 1465
7 hours 32 minutes ago #342765 by krileon
By sending an email I meant use an Email action. That's what I used in my tests with success. Are you sure your gateway id is correct? You need to provide the number under the Id column and not under the # column.

It's possible to act on payment state change as well. That maybe more ideal since you're just needing to act on successful payments from paypal. Below is tested working as well.

Global
Triggers: onCPayAfterPaymentStatusChange
User: Automatic
Access: Everybody
Conditions
Condition 1
Field: Custom > Value
Custom Value: [var4]
Operator: Equal To
Value: Completed
Condition 2
Field: Custom > Value
Custom Value: [var2_gateway_account]
Operator: Equal To
Value: YOUR_PAYPAL_GATEWAY_ID_HERE

This is just acting on a payment basket being marked completed for a specific payment gateway. Below was used in both test examples.

Global
Type: Email
Action
Subject: Payment Test Email
Body: Success!


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