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
1 hour 38 minutes 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: 49911
  • Thanks: 8529
  • Karma: 1465
1 hour 12 minutes 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
  • ONLINE
  • Posts: 502
  • Thanks: 42
  • Karma: 3
  • Add-ons
Just now #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.

Moderators: beatnantkrileon
Powered by Kunena Forum