Developer notes
Technical reference for developers who customize Viva.com Smart Checkout.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_viva_payments |
| Function prefix | fn_kv_viva_payments_ |
| Language variables | kv_viva_payments.* |
| CSS scope | .kv-viva-payments (admin), .kv-viva-pay (checkout) |
| PHP namespace | Tygh\Addons\KvVivaPayments |
| Preset | payment (generated by kv new --kind integration) |
How a payment runs
Section titled “How a payment runs”payments/kv_viva_payments.php(processor script) callsPaymentService::initialize(): it stores a transaction row, creates a payment order withPOST /checkout/v2/ordersand redirects to/web/checkout?ref=<orderCode>.- The customer pays on Viva. Viva sends the browser to the Success or Failure URL of the payment source (these URLs are set in the Viva app, not per request) with
s(order code) andt(transaction id), and sends a webhook. - The return handler and the webhook job both call
PaymentService::sync(), which takes a named lock per payment (GET_LOCK), re-reads the row inside the lock, callsGET /checkout/v2/transactions/{id}and only then changes the order. The order code,statusId,transactionTypeId, amount and currency are compared with what was sent. A webhook body or the query string is never trusted for state. - Refunds, captures and cancellations use the same lock; a refund row (status
creating) and its idempotency key are stored before the HTTP call.
Viva API reference
Section titled “Viva API reference”Every endpoint and field the add-on uses is listed with its documentation URL in notes/API-NOTES.md. The sources are the official Viva developer portal:
- OAuth2: https://developer.viva.com/integration-reference/oauth2-authentication/
- Smart Checkout integration: https://developer.viva.com/smart-checkout/smart-checkout-integration/
- Payment API (OpenAPI file): https://developer.viva.com/apis-for-payments/payment-api/ and https://developer.viva.com/downloads/payment-api.yaml
- Webhooks: https://developer.viva.com/webhooks-for-payments/ and https://developer.viva.com/webhooks-for-payments/setting-up-webhooks/
- Refunds: https://developer.viva.com/tutorials/payments/issue-a-refund/
- Pre-authorizations: https://developer.viva.com/tutorials/payments/handle-pre-authorizations/
- Status and transaction type codes: https://developer.viva.com/integration-reference/response-codes/
- Multicurrency: https://developer.viva.com/smart-checkout/smart-checkout-multicurrency/
Viva webhooks carry no signature. The add-on answers the GET verification with the key from GET /acquiring/v1/webhooks/token, optionally restricts POSTs to Viva’s documented addresses (setting), and treats every body as a hint.
Structure
Section titled “Structure”| Class | Role |
|---|---|
Client\BaseClient |
HTTP (cURL, TLS verification, timeouts), JSON, error mapping, masked logging |
Client\Api |
The Viva calls: OAuth2 token (Basic), create order, retrieve transaction, webhook key, refund / cancel, capture (legacy host, Basic) |
Client |
Client per company, the connection test |
Accounts, Secret |
Credentials (test and live) sealed with AES-256-GCM; one account per store owner or per vendor |
Config, Access |
Settings, owner mode, who may see and manage what |
PaymentService |
Start, read-back sync, order status update, refunds, reversal booking, capture, cancel |
Transition |
Pure status logic (Viva statusId / transactionTypeId to local status to order status); never moves an order backwards |
Transactions |
Payment attempts and their refunds; Multi-Vendor parent payments are refunded per child order share |
Queue, Jobs, JobException |
Job queue: back-off 5 min / 15 min / 1 h / 3 h / 12 h, per-job isolation, overlap lock |
Log |
Event log with masking of secrets and payer data, filters, CSV, retention |
Webhook |
Shape check of an event, event id for idempotency, documented source addresses, verification key |
Database tables
Section titled “Database tables”| Table | Purpose |
|---|---|
?:kv_viva_payments_accounts |
Credentials per company (secrets sealed), last connection check, token cache |
?:kv_viva_payments_log |
Log |
?:kv_viva_payments_jobs |
Queue |
?:kv_viva_payments_transactions |
Payment attempts: provider_ref = order code, txn_ref = Viva transaction id, capture_ref |
?:kv_viva_payments_refunds |
Refunds: provider_ref = Viva reversal transaction id, source admin / status / viva |
Hooks used
Section titled “Hooks used”| Hook | Purpose |
|---|---|
change_order_status_post |
Queues a full refund when the order reaches the status chosen in the settings |
prepare_checkout_payment_methods |
Hides the method while the add-on cannot start payments (disabled, unlicensed, not connected) |
init_templater_post |
Upgrade synchronizer (only while an update is pending) |
orders:tabs_extra (admin template hook) |
The “Viva payment” tab on the order page |
index:styles (admin and storefront template hooks) |
Style sheets |
Test the HTTP layer without Viva
Section titled “Test the HTTP layer without Viva”The base URL can be overridden for tests in config.local.php (development only); all three Viva hosts then collapse to that root:
$config['kv_viva_payments_base_url'] = 'http://127.0.0.1:11830';node tests/mock-server/server.js 11830 starts a local stand-in built from the documentation examples; node tests/e2e/e2e.mjs runs the HTTP end-to-end test against it (it refuses to run when the store is not pointed at the mock); php tests/unit.php runs the unit tests with the doc examples in tests/fixtures/.
Template overrides
Section titled “Template overrides”Admin templates live in design/backend/templates/addons/kv_viva_payments/. Do not edit them in a store; they are replaced on update.