Skip to Content Skip to Menu

🌲 Merry Christmas! Great Savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2025!

CBSubs Auto Actions not firing on PayPal payment completion

  • liaskas
  • liaskas
  • OFFLINE
  • Posts: 504
  • Thanks: 42
  • Karma: 3
  • Add-ons
6 days 14 hours ago #342771 by liaskas
Hello again,

Emails were only used as tests to confirm that the Auto Action itself executes. Our actual requirement is database persistence.

Goal
We need to create a custom database record (for OSS / VAT reporting) only after a payment is fully completed, and only for a specific payment gateway (identified by its numeric gateway ID, e.g. 5).
The record must be created exactly once per completed payment, using finalized payment data:
gateway ID
transaction ID
amounts
currency
billing country

What we observe
#__cbsubs_payments does contain the correct finalized data (payment_status = Completed, gateway_account, txn_id, etc).
Auto Actions do execute (emails and SELECT queries work). However, INSERTs into a custom table from a Code-type Auto Action (PHP) either:
do not persist at all, or execute at a point where the numeric gateway ID is not yet available.
[PAYMENT_GATEWAY_ID] evaluates to 0 before the gateway callback.

What we need guidance on

Which trigger is guaranteed to run after payment finalization, with the finalized gateway_account, and is safe for writing to a custom database table.
Whether Auto Actions are intended/supported for persistent database writes in the payment lifecycle.
If not, what is the recommended CB / CBSubs mechanism for this use case.

The solution must rely only on finalized payment data.

Minimal example

Below is a very simple Code-type Auto Action test that does not create a database record, even though the Auto Action executes (emails work).

Auto Action configuration

Global
Trigger: onCPayUserStateChange
Type: Code
User: Automatic
Access: Everybody

Conditions
Custom Value: [var2]
Operator: Equal To
Value: A

Field: Custom → Code
Code:
return ( $variables->getCurrentBasket()->gateway_account ?? 0 );
Operator: Equal To
Value: 5

Action
Method: PHP
Code:
Code:
$db = \Joomla\CMS\Factory::getDbo(); $db->setQuery(     "INSERT INTO #__oss_vat_test (user_id, created_at)      VALUES ('" . (int) $userId . "', UTC_TIMESTAMP())" ); $db->execute();

The same INSERT works immediately if executed directly in phpMyAdmin.

Thank you

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49934
  • Thanks: 8536
  • Karma: 1466
6 days 14 hours ago #342774 by krileon
The email action was just for me to be sure it's working. I've confirmed both cases as working. From there whatever you do is entirely on your PHP. If you're just running queries though I suggest not using PHP and instead just using a Query action. Based off the information you need then my second example (using onCPayAfterPaymentStatusChange) is what you should use as a Basket = Invoice so all the information you're wanting already exists on 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.

  • liaskas
  • liaskas
  • OFFLINE
  • Posts: 504
  • Thanks: 42
  • Karma: 3
  • Add-ons
6 days 13 hours ago #342781 by liaskas
The following does not create records. Can you please point me to the right direction?

Auto Action configuration

Global
Trigger: onCPayAfterPaymentStatusChange
Type: Query
User: Automatic
Access: Everybody

Conditions
Custom Value: [var4]
Operator: Equal To
Value: Completed

Custom Value: [var5]
Operator: Not Equal To
Value: Completed (To ensure the Auto Action fires only once, not on repeats)

Custom Value: [PAYMENT_GATEWAY_ID]
Operator: Equal To
Value: 5

Action
Query:
Code:
INSERT IGNORE INTO #__oss_vat_records (   user_id,   cbsubs_plan_id,   invoice_no,   payment_txn_id,   currency,   gross_amount,   vat_amount,   created_at_utc,   paid_at_utc ) VALUES (   '[USER_ID]',   '[PLAN_ID]',   '[INVOICE_NO]',   '[TRANSACTION_ID]',   '[CURRENCY]',   '[TOTAL_PRICE]',   '[TAX_AMOUNT]',   UTC_TIMESTAMP(),   '[DATE_PAID]' );

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49934
  • Thanks: 8536
  • Karma: 1466
6 days 12 hours ago #342783 by krileon
Your 3rd condition is not correct. See the below with my example updated with your gateway id.

Field: Custom > Value
Custom Value: [var2_gateway_account]
Operator: Equal To
Value: 5


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
  • OFFLINE
  • Posts: 504
  • Thanks: 42
  • Karma: 3
  • Add-ons
6 days 10 minutes ago #342793 by liaskas
Thanks for the clarification earlier — we followed your recommendation and switched to:

Trigger: onCPayAfterPaymentStatusChange
Action type: Query

Conditions:
[var4] = Completed
[var5] != Completed
[var2_gateway_account] = 5 (here we want to condition against the gateway ID, not against the "Type of gateway")

Action: Query (To rule out substitutions and SQL issues, we tested with the most minimal possible query):
Code:
INSERT INTO #__oss_vat_records (user_id, created_at_utc, notes) VALUES ('62', UTC_TIMESTAMP(), 'AUTOACTION_TEST');

Result: (All tests are with real payments from users)
Payment completes normally
Subscription activates
No record is inserted !!!

Seems that the Query action itself is not executing under this trigger, even without substitutions or conditions that could fail.

Is there a required configuration detail we may be missing for this trigger?
Is onCPayAfterPaymentStatusChange trigger the one for DB writes after payment finalization?

We are trying to insert a single database row after a completed payment, but this does not work even with hardcoded values.

Thanks again for your help

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 49934
  • Thanks: 8536
  • Karma: 1466
5 days 16 hours ago #342797 by krileon
I don't know what more to suggest. I recommend following my exact examples. Do not add extra conditions to them.

www.joomlapolis.com/forum/developer-members-support/247821-cbsubs-auto-actions-not-firing-on-paypal-payment-completion?start=0#342765

Both of my examples are tested working. Use an Email action to confirm the trigger is firing (my confirmed test). If that's not working for you then it's possible CB Auto Actions isn't loading. Be sure CB Auto Actions is Public and Published in CB > Plugin Management.

At this point I can take a look for you if you PM backend super user login credentials (see link in signature below), but I will not be able to make test payments unless you've the gateway in test mode and provide test payment credentials.


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