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