@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:Run the complete example
Save this aspayments-demo.mjs:
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 localidempotencyKey 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.
Troubleshooting
Next steps
- Orders quickstart: verify reservation and cancellation behavior.
- Returns quickstart: create and receive a return using an actual order item ID.
- Durable workflows: explore orchestration across service boundaries.
- Finance and accounting: find the broader accounting domains.