@atumlabs/payment-gateway-client 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -445,10 +445,16 @@ type VerifiableCredential = {
445
445
  };
446
446
  };
447
447
  /**
448
- * Response from submitting a payment request. If processing completes within 30 seconds,
449
- * the response will include a fulfillment_confirmation with full settlement details.
450
- * Otherwise, you'll receive a payment_id that you can use to poll the
451
- * /v1/payments/{paymentId}/status endpoint for updates.
448
+ * Response from submitting a payment request. If settlement completes inside the
449
+ * gateway's synchronous window, the response includes a fulfillment_confirmation with
450
+ * full settlement details. Otherwise you receive a payment_id plus the payment's
451
+ * current `status`, and can poll /v1/payments/{paymentId}/status for updates.
452
+ *
453
+ * Read `status` before deciding what to do next: a `pending` payment is in flight and
454
+ * must NOT be re-submitted under a new request_id (that would be a second payment),
455
+ * whereas a `failed` or `cancelled` one is terminal — re-submitting it under the SAME
456
+ * request_id resolves to the same terminal payment, so a genuine re-attempt needs a
457
+ * new request_id.
452
458
  *
453
459
  */
454
460
  type PaymentResponse = {
@@ -456,9 +462,71 @@ type PaymentResponse = {
456
462
  * Unique ID for tracking this payment. Save this to check status later.
457
463
  *
458
464
  */
459
- payment_id?: string;
465
+ payment_id: string;
466
+ /**
467
+ * Current status of the payment, with the same meaning as on
468
+ * /v1/payments/{paymentId}/status:
469
+ * - `pending`: accepted and being processed
470
+ * - `completed`: successfully delivered
471
+ * - `failed`: failed (funds returned if escrowed)
472
+ * - `cancelled`: cancelled before completion
473
+ *
474
+ * Present on every response. `completed` is always accompanied by
475
+ * fulfillment_confirmation; `failed` is accompanied by `error` where a reason has
476
+ * been recorded.
477
+ *
478
+ */
479
+ status: 'pending' | 'completed' | 'failed' | 'cancelled';
480
+ /**
481
+ * Whether this response describes a payment that already existed, rather than one
482
+ * created by this request. `true` means the request_id had been used before and you
483
+ * are being handed the ORIGINAL payment — no second payment was created and nothing
484
+ * additional was charged.
485
+ *
486
+ * **Re-attempting a payment.** Re-submit the same request and you get the same payment
487
+ * back. You may re-send the original bytes unchanged: the deadlines will have expired by
488
+ * then — `quote_deadline` bounds the auction and is short, while this endpoint may hold a
489
+ * submission for up to 30 seconds — and an expired deadline on a re-submission is not an
490
+ * error, because the request is resolved onto the payment that already exists rather than
491
+ * used to create one.
492
+ *
493
+ * Re-signing with fresh deadlines is equally fine and returns the same payment. What you
494
+ * must NOT change is the request_id, and what you must not change under it is the
495
+ * payment's economics — source, destination, fulfillment_amount, max_source_amount — which
496
+ * are rejected with 409 IDEMPOTENCY_TERMS_MISMATCH. Deadlines and the signature are
497
+ * exempt precisely so that a re-attempt is possible.
498
+ *
499
+ * A genuinely new payment needs a NEW request_id. In particular a `failed` payment is
500
+ * terminal: re-submitting its request_id keeps returning that dead payment, so recovering
501
+ * means starting a new one under a new key.
502
+ *
503
+ * Present on every response, `false` for a newly created payment. A response without
504
+ * the field is from a gateway predating it, not a newly created payment.
505
+ *
506
+ * This is the field to read when reconciling a suspected double charge: two
507
+ * submissions where the second reports `true` are one payment, whereas two both
508
+ * reporting `false` are two. It says nothing about how far the payment has got —
509
+ * read `status` for that.
510
+ *
511
+ */
512
+ idempotent_replay: boolean;
460
513
  fulfillment_confirmation?: FulfillmentConfirmation;
514
+ error?: PaymentError;
461
515
  };
516
+ /**
517
+ * Current status of the payment, with the same meaning as on
518
+ * /v1/payments/{paymentId}/status:
519
+ * - `pending`: accepted and being processed
520
+ * - `completed`: successfully delivered
521
+ * - `failed`: failed (funds returned if escrowed)
522
+ * - `cancelled`: cancelled before completion
523
+ *
524
+ * Present on every response. `completed` is always accompanied by
525
+ * fulfillment_confirmation; `failed` is accompanied by `error` where a reason has
526
+ * been recorded.
527
+ *
528
+ */
529
+ type status2 = 'pending' | 'completed' | 'failed' | 'cancelled';
462
530
  type GetPaymentStatusResponse = {
463
531
  /**
464
532
  * The payment ID you're checking status for.
@@ -481,15 +549,6 @@ type GetPaymentStatusResponse = {
481
549
  fulfillment_confirmation?: FulfillmentConfirmation;
482
550
  error?: PaymentError;
483
551
  };
484
- /**
485
- * Current status of your payment:
486
- * - `pending`: Payment is being processed
487
- * - `completed`: Payment successfully delivered
488
- * - `failed`: Payment failed (funds returned if escrowed)
489
- * - `cancelled`: Payment was cancelled before completion
490
- *
491
- */
492
- type status2 = 'pending' | 'completed' | 'failed' | 'cancelled';
493
552
  /**
494
553
  * Error details when payment status is "failed".
495
554
  * Only present when the payment has failed. Contains a machine-readable
@@ -1327,6 +1386,14 @@ type $OpenApiTs = {
1327
1386
  * Payment declined during counterparty authorization
1328
1387
  */
1329
1388
  403: ErrorResponse;
1389
+ /**
1390
+ * The `request_id` has already been used for a payment with different economics
1391
+ * (`IDEMPOTENCY_TERMS_MISMATCH`). Re-submitting one `request_id` is how a retry is
1392
+ * made safe, so it must identify one payment; use a distinct `request_id` per
1393
+ * payment.
1394
+ *
1395
+ */
1396
+ 409: ErrorResponse;
1330
1397
  /**
1331
1398
  * Payment request too large to process
1332
1399
  */
@@ -1555,8 +1622,26 @@ declare class PaymentsService {
1555
1622
  * 2. Find optimal settlement routes across chains/assets
1556
1623
  * 3. Secure funds in escrow
1557
1624
  * 4. Coordinate with settlement agents for execution
1558
- * 5. Return a real-time result if processing completes within 30 seconds,
1559
- * otherwise return a payment ID for status polling
1625
+ * 5. Return a real-time result if settlement completes inside the synchronous window,
1626
+ * otherwise return a payment ID and status for polling
1627
+ *
1628
+ * **Idempotency.** `request_id` is the idempotency key, scoped to the source account
1629
+ * and originator. Submitting the same `request_id` again returns the ORIGINAL payment
1630
+ * instead of charging a second time, so a client whose request timed out or failed
1631
+ * in transit can safely re-submit.
1632
+ *
1633
+ * Because a re-submission must be admissible on its own, some fields legitimately
1634
+ * differ between attempts and are excluded from the comparison: `quote_deadline` and
1635
+ * `fulfillment_deadline` (both must be in the future, so a later attempt has to move
1636
+ * them), and the `sender_auth` signature they are signed into.
1637
+ *
1638
+ * What must NOT differ is the payment's economics — source account and asset,
1639
+ * destination accounts and assets, `fulfillment_amount`, and `max_source_amount` (the
1640
+ * payer's own risk cap; lowering it on a retry describes a different payment, not the
1641
+ * same one with less headroom). Re-using one `request_id` for a genuinely different
1642
+ * payment is a client bug that would otherwise be silently collapsed onto the first
1643
+ * payment, so it is rejected with `409` and `IDEMPOTENCY_TERMS_MISMATCH`. Use a
1644
+ * distinct `request_id` per payment.
1560
1645
  *
1561
1646
  * @param data The data for the request.
1562
1647
  * @param data.requestBody
@@ -2251,16 +2336,30 @@ declare const $VerifiableCredential: {
2251
2336
  };
2252
2337
  declare const $PaymentResponse: {
2253
2338
  readonly type: "object";
2254
- readonly description: "Response from submitting a payment request. If processing completes within 30 seconds,\nthe response will include a fulfillment_confirmation with full settlement details.\nOtherwise, you'll receive a payment_id that you can use to poll the\n/v1/payments/{paymentId}/status endpoint for updates.\n";
2339
+ readonly description: "Response from submitting a payment request. If settlement completes inside the\ngateway's synchronous window, the response includes a fulfillment_confirmation with\nfull settlement details. Otherwise you receive a payment_id plus the payment's\ncurrent `status`, and can poll /v1/payments/{paymentId}/status for updates.\n\nRead `status` before deciding what to do next: a `pending` payment is in flight and\nmust NOT be re-submitted under a new request_id (that would be a second payment),\nwhereas a `failed` or `cancelled` one is terminal — re-submitting it under the SAME\nrequest_id resolves to the same terminal payment, so a genuine re-attempt needs a\nnew request_id.\n";
2340
+ readonly required: readonly ["payment_id", "status", "idempotent_replay"];
2255
2341
  readonly properties: {
2256
2342
  readonly payment_id: {
2257
2343
  readonly type: "string";
2258
2344
  readonly description: "Unique ID for tracking this payment. Save this to check status later.\n";
2259
2345
  readonly example: "550e8400-e29b-41d4-a716-446655440000";
2260
2346
  };
2347
+ readonly status: {
2348
+ readonly type: "string";
2349
+ readonly enum: readonly ["pending", "completed", "failed", "cancelled"];
2350
+ readonly description: "Current status of the payment, with the same meaning as on\n/v1/payments/{paymentId}/status:\n- `pending`: accepted and being processed\n- `completed`: successfully delivered\n- `failed`: failed (funds returned if escrowed)\n- `cancelled`: cancelled before completion\n\nPresent on every response. `completed` is always accompanied by\nfulfillment_confirmation; `failed` is accompanied by `error` where a reason has\nbeen recorded.\n";
2351
+ };
2352
+ readonly idempotent_replay: {
2353
+ readonly type: "boolean";
2354
+ readonly description: "Whether this response describes a payment that already existed, rather than one\ncreated by this request. `true` means the request_id had been used before and you\nare being handed the ORIGINAL payment — no second payment was created and nothing\nadditional was charged.\n\n**Re-attempting a payment.** Re-submit the same request and you get the same payment\nback. You may re-send the original bytes unchanged: the deadlines will have expired by\nthen — `quote_deadline` bounds the auction and is short, while this endpoint may hold a\nsubmission for up to 30 seconds — and an expired deadline on a re-submission is not an\nerror, because the request is resolved onto the payment that already exists rather than\nused to create one.\n\nRe-signing with fresh deadlines is equally fine and returns the same payment. What you\nmust NOT change is the request_id, and what you must not change under it is the\npayment's economics — source, destination, fulfillment_amount, max_source_amount — which\nare rejected with 409 IDEMPOTENCY_TERMS_MISMATCH. Deadlines and the signature are\nexempt precisely so that a re-attempt is possible.\n\nA genuinely new payment needs a NEW request_id. In particular a `failed` payment is\nterminal: re-submitting its request_id keeps returning that dead payment, so recovering\nmeans starting a new one under a new key.\n\nPresent on every response, `false` for a newly created payment. A response without\nthe field is from a gateway predating it, not a newly created payment.\n\nThis is the field to read when reconciling a suspected double charge: two\nsubmissions where the second reports `true` are one payment, whereas two both\nreporting `false` are two. It says nothing about how far the payment has got —\nread `status` for that.\n";
2355
+ readonly example: false;
2356
+ };
2261
2357
  readonly fulfillment_confirmation: {
2262
2358
  readonly $ref: "#/components/schemas/FulfillmentConfirmation";
2263
2359
  };
2360
+ readonly error: {
2361
+ readonly $ref: "#/components/schemas/PaymentError";
2362
+ };
2264
2363
  };
2265
2364
  };
2266
2365
  declare const $GetPaymentStatusResponse: {