Skip to main content
This walkthrough uses @stateset/embedded 1.35.1 to create a 25.00 USD payment record and a 12.50 USD refund record. It verifies retry behavior and two rejected refund requests in a fresh in-memory database.
These calls update local commerce records. They do not charge a card, contact a payment provider, or transfer a refund. The completion step below simulates a successful provider result so you can explore the lifecycle without credentials or money movement.

Prerequisites

Use Node.js 20.20.0+ and npm 10+. In a new directory:
See SDK installation if the native module cannot load.

Run the complete example

Save this as payments-demo.mjs:
Success: all assertions pass and you see:

Read the results correctly

Use decimal strings with createExact and createRefundExact, and read amountExact. The binding also exposes numeric money fields; do not convert exact values to JavaScript floating-point numbers for financial calculations.

Integrate with a provider

Keep the local payment ID, provider transaction ID, and your operation’s stable retry key in your integration’s persisted records. A local idempotencyKey does not configure the provider’s own retry behavior. Use that provider’s contract when sending or reconciling a charge or refund. If a provider request times out, its result is unknown. Reconcile the original operation before creating another payment or refund. For local retries, preserve both the original request and its key; generating a new key creates a different operation identity. Only mark a local payment completed after verifying the provider result in a real integration. Update and reconcile order, payment, refund, and inventory state explicitly rather than treating one successful method call as completion of the whole workflow.
The published Node 1.35.1 Payments class exposes refund creation but no refund-completion method. This walkthrough ends with a pending refund record. A production refund flow needs a supported interface for recording the final outcome as well as the provider call; do not treat this example as an end-to-end refund integration.

Troubleshooting

Next steps

Last modified on September 20, 2026