Skip to content

Developer notes

Technical reference for developers who customize Helcim Payments for CS-Cart and Multi-Vendor.

Item Value
Add-on id kv_helcim_payments
Function prefix fn_kv_helcim_payments_
Language variables kv_helcim_payments.*
CSS scope .kv-helcim-payments
PHP namespace Tygh\Addons\KvHelcimPayments
Preset payment (generated by kv new --kind integration)
Class Role
Client\BaseClient HTTP (cURL, TLS verification, timeouts), JSON, error mapping, masked logging
Client\Api The Helcim calls (below), static api-token header (no OAuth)
Client Client per company, the connection test
PaymentService Start (initialize), confirm (hash + read-back), sync, capture, reverse, refund; order status moves
PaymentPage The standalone payment page that loads HelcimPay.js and posts the modal result
HelcimPay Pure helpers: parse the modal message, SHA-256 hash check, amount comparison, idempotency key
Transition Pure status logic: card / ACH transaction -> local status -> order status
Surcharge Fee Saver guard (blocked states)
Webhook Signature check (webhook-id / timestamp / signature) and event ids
Accounts, Secret API token and verifier token (test and live) sealed with AES-256-GCM
Queue, Jobs, JobException, Idempotency Job queue with back-off, per-object locks, atomic state claims
Log, Config, Access, Money, OrderTax Log, settings, permissions, ISO 4217 minor units, order taxes
  1. payments/kv_helcim_payments.php (started by fn_start_payment) calls PaymentService::initialize(): a transaction row is stored first (created), then POST /helcim-pay/initialize returns checkoutToken + secretToken. The secret token is sealed in the row and never leaves the server; the page gets only the checkout token and the attempt’s random access key.
  2. PaymentPage prints a standalone page: it loads https://secure.helcim.app/helcim-pay/services/start.js, calls appendHelcimPayIframe(checkoutToken, true) and listens for message events named helcim-pay-js-<checkoutToken> from the Helcim origin.
  3. On SUCCESS the page posts eventMessage to kv_helcim_payments.confirm. PaymentService::confirm() checks the hash with the sealed secret token, ties the Helcim transaction id to the attempt (atomic: only an attempt without an id takes it), and calls sync().
  4. sync() reads the transaction back (GET /card-transactions/{id} or GET /ach/transactions/{id}), compares amount and currency, maps the status and moves the order. The same sync() serves the return page, the webhook job and the cron.
  5. A payment whose result never arrived is found by our invoice number (KVH-<attempt id>, sent in invoiceRequest): GET /card-transactions?invoiceNumber= (webhook job or cron). An attempt with no payment after the 60 minute checkout lifetime becomes expired.

Helcim API reference used (official pages only)

Section titled “Helcim API reference used (official pages only)”

Base URL https://api.helcim.com/v2 for test and live (a developer test account has its own token on the same host, Developer testing). Auth header api-token (Connecting to the Helcim API: the token is created in an API Access Configuration; Transaction Processing levels None / Auth / Positive Transaction / Admin; GET /connection-test answers “Connected Successfully” or “Unauthorized”, used by “Test connection”). Error bodies {"errors": "..."}, {"errors": ["..."]} or {"errors": {"field": "..."}}; ACH endpoints answer {"message": "..."} (Errors and error handling, HelcimPay.js errors). Rate limits: 5 concurrent, 100 per minute, 3000 per hour, then HTTP 429; headers minute-limit-remaining, hour-limit-remaining (API rate limits).

Called from the server only (a browser call fails with CORS).

Request field Used as
paymentType purchase or preauth (setting; verify is not used)
amount number, major units (order total)
currency USD or CAD
paymentMethod cc, ach or cc-ach (setting)
language en, or fr when the storefront language is French
confirmationScreen false (the add-on shows its own result)
hasConvenienceFee 1 only when Fee Saver is on, methods are cc-ach and the surcharge guard allows the buyer’s state
invoiceRequest invoiceNumber (KVH-<id>), contactName (billing name), lineItems[] with description, quantity, price, total (one line, the whole amount); only when “Create a Helcim invoice” is on

Response checkoutToken (valid 60 minutes or until the transaction is processed) and secretToken. Not used: customerCode, invoiceNumber (existing invoice), allowPartial, taxAmount, terminalId, digitalWallet, displayContactFields, customStyling, customerRequest, hideExistingPaymentDetails, setAsDefaultPaymentMethod.

  • Script https://secure.helcim.app/helcim-pay/services/start.js; appendHelcimPayIframe(checkoutToken, allowExit), removeHelcimPayIframe() (needs the element with id helcimPayIframe).
  • window message event, eventName helcim-pay-js-<checkoutToken>, eventStatus SUCCESS (approved) | ABORTED (declined) | HIDE (window closed), eventMessage = JSON text of the transaction response ({"status":200,"data":{"data":{...},"hash":"..."}}) or an error string.
  • Result data fields read: card transactionId, status, type, amount, currency, approvalCode, cardNumber, cardType, invoiceNumber, warning; ACH transactionId, bankToken, statusAuth, statusClearing, amount, currency.
  • Hash: SHA-256 of the JSON encoding of data followed directly by the secretToken. The page’s PHP example is hash('sha256', json_encode(json_decode($data, true)) . $secretToken); Helcim hashes the JSON-escaped unicode form, which is the PHP default (\u00e9, \/). The add-on accepts the default form and the form with unescaped slashes (the page does not say which one the server used; both need the secret token). The comparison uses hash_equals.
  • GET /card-transactions/{cardTransactionId} (reference): status APPROVED | DECLINED, type purchase | preauth | verify, amount, currency, cardType (abbreviation: VI, MC, AX, DI, …), cardNumber (first 6 and last 4), approvalCode, invoiceNumber, warning.
  • GET /card-transactions?invoiceNumber=&limit= (reference): array of the same objects.
  • GET /ach/transactions/{transactionId} (reference): statusAuth, statusClearing, amount, bankAccountL4l4, approvalCode, invoiceNumber. Meaning of the codes from ACH bank payments: statusAuth 1 approved, 2 declined, 4 cancelled, 5 pending customer bank authorization; statusClearing 0 settling, 1 settled and approved, 4 settled and declined. Paid = auth 1 + clearing 1.

Money actions (all need an idempotency-key header of 25-36 alphanumeric characters with - and _; keys are kept 5 minutes; same key and same body returns the first answer; same key and another body returns 409 (Idempotency))

Section titled “Money actions (all need an idempotency-key header of 25-36 alphanumeric characters with - and _; keys are kept 5 minutes; same key and same body returns the first answer; same key and another body returns 409 (Idempotency))”
Call Body Reference
POST /payment/capture preAuthTransactionId, amount (at most the pre-authorized amount), ipAddress, ecommerce capture
POST /payment/reverse cardTransactionId, ipAddress, ecommerce reverse
POST /payment/refund originalTransactionId (the purchase or capture), amount, ipAddress, ecommerce refund
PUT /ach/transactions/{id}/refund amount ACH refund

Responses are the card transaction object; a declined action can still be HTTP 200 with status DECLINED, so the add-on checks status. Helcim documents no eligibility rule for reverse (it does for ACH void vs refund by batch state), so a refusal is shown as Helcim answers. ACH void and cancel are not implemented (use Helcim).

ipAddress is required for fraud detection: the add-on stores the checkout visitor’s IP (REMOTE_ADDR) with the attempt and sends it for later actions.

The “suspected duplicate” rule (same card, name and amount within 5 minutes, any idempotency key) declines with errors: "Transaction Declined: DECLINED - Suspected duplicate transaction in the last 5 minutes." (Suspected duplicate transactions).

  • Event cardTransaction: body {"id": <card transaction id>, "type": "cardTransaction"}; terminalCancel is ignored. Delivery URL: HTTPS, no word “Helcim”. Retries until a 2xx.
  • Headers webhook-id, webhook-timestamp, webhook-signature. Signing string <webhook-id>.<webhook-timestamp>.<raw body>, HMAC SHA-256, key = base64-decoded verifier token, result base64; the header holds space separated v1,<signature> values and one must match. No timestamp tolerance is documented, so none is enforced; a replay only triggers another read-back.
  • The event is stored as a job keyed by webhook-id (a repeat delivery is one job); the job reads the transaction back by id and matches it to an attempt by id or by invoice number. Refunds and captures of known payments create events too and are ignored.
Local status From Order
pending modal open; ACH approved but not settled; unknown stays (not paid)
authorized card APPROVED + preauth “authorized” status setting
paid card APPROVED + purchase; ACH auth 1 + clearing 1; capture approved paid status
failed / expired / canceled DECLINED, ACH auth 2 / clearing 4, checkout older than 60 min, window closed failed / canceled status (open orders only)
capturing / voiding action sent, answer lost unchanged; retry with the same key within 5 minutes
voided, partial_refund, refunded our own reverse / refund calls unchanged

Pending states never cancel an order, a late “failed” never undoes a paid order, and applyRemote() never downgrades captured, voided or refunded payments.

Table Purpose
?:kv_helcim_payments_accounts Tokens per company (sealed), last connection check
?:kv_helcim_payments_log Log
?:kv_helcim_payments_jobs Queue
?:kv_helcim_payments_transactions One row per attempt: checkout token, sealed secret token, Helcim ids (provider_ref, capture_ref), invoice number, card brand / last 4, approval code, fee, refunded amount
?:kv_helcim_payments_refunds Refund requests (creating, approved, accepted, failed, unconfirmed)

PHP: change_order_status_post (refund when an order reaches the chosen status), prepare_checkout_payment_methods (hide the method when disabled, unlicensed, not connected or the cart is not in USD / CAD), init_templater_post (pending upgrade synchronisation, only while pending). Template hook: orders:tabs_extra (the “Helcim payment” tab). The processor script and the frontend controller kv_helcim_payments (confirm, webhook, cron) carry the rest.

Override the base URL in config.local.php (development only; the e2e REFUSES to run unless it points at 127.0.0.1 / localhost):

$config['kv_helcim_payments_base_url'] = 'http://127.0.0.1:11830/v2';

node tests/mock-server/server.js 11830 starts a stand-in of the API and of the HelcimPay.js modal (its start.js is served from the same override, and the page then accepts the mock’s origin); every response in it is copied from the pages above. node tests/e2e/e2e.mjs --store ... --db ... --root ... runs the HTTP end-to-end test; php tests/unit.php runs the unit tests; php tests/php/mockhash.php <pay.json> <secret> checks the mock’s hash against the add-on’s validation. This proves the add-on against the documentation, not against the live Helcim service.

Admin templates live in design/backend/templates/addons/kv_helcim_payments/. The payment page is generated by PaymentPage (no theme template, so it works with every storefront theme). Do not edit templates in a store; they are replaced on update.