Skip to content

Developer notes

Technical reference for developers who customize Viva.com Smart Checkout.

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)
  1. payments/kv_viva_payments.php (processor script) calls PaymentService::initialize(): it stores a transaction row, creates a payment order with POST /checkout/v2/orders and redirects to /web/checkout?ref=<orderCode>.
  2. 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) and t (transaction id), and sends a webhook.
  3. 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, calls GET /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.
  4. Refunds, captures and cancellations use the same lock; a refund row (status creating) and its idempotency key are stored before the HTTP call.

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:

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.

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
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
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

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/.

Admin templates live in design/backend/templates/addons/kv_viva_payments/. Do not edit them in a store; they are replaced on update.