@sakeetech/viva-payments-core 0.2.1 → 0.2.2

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.
Files changed (105) hide show
  1. package/dist/auth/http.js +14 -9
  2. package/dist/auth/http.js.map +1 -1
  3. package/dist/auth/index.js +18 -5
  4. package/dist/auth/index.js.map +1 -1
  5. package/dist/auth/oauth2-strategy.js +24 -20
  6. package/dist/auth/oauth2-strategy.js.map +1 -1
  7. package/dist/auth/reseller-strategy.js +5 -1
  8. package/dist/auth/reseller-strategy.js.map +1 -1
  9. package/dist/auth/single-flight.js +8 -3
  10. package/dist/auth/single-flight.js.map +1 -1
  11. package/dist/auth/token-cache.js +7 -2
  12. package/dist/auth/token-cache.js.map +1 -1
  13. package/dist/errors/api-error.js +6 -2
  14. package/dist/errors/api-error.js.map +1 -1
  15. package/dist/errors/auth-error.js +6 -2
  16. package/dist/errors/auth-error.js.map +1 -1
  17. package/dist/errors/base.js +5 -1
  18. package/dist/errors/base.js.map +1 -1
  19. package/dist/errors/index.js +17 -7
  20. package/dist/errors/index.js.map +1 -1
  21. package/dist/errors/mode-mismatch-error.js +6 -2
  22. package/dist/errors/mode-mismatch-error.js.map +1 -1
  23. package/dist/errors/rate-limit-error.js +6 -2
  24. package/dist/errors/rate-limit-error.js.map +1 -1
  25. package/dist/errors/validation-error.js +6 -2
  26. package/dist/errors/validation-error.js.map +1 -1
  27. package/dist/errors/webhook-error.js +6 -2
  28. package/dist/errors/webhook-error.js.map +1 -1
  29. package/dist/index.js +4 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/isv/accounts.js +5 -1
  32. package/dist/isv/accounts.js.map +1 -1
  33. package/dist/isv/client.js +23 -19
  34. package/dist/isv/client.js.map +1 -1
  35. package/dist/isv/index.js +17 -8
  36. package/dist/isv/index.js.map +1 -1
  37. package/dist/isv/sources.js +8 -4
  38. package/dist/isv/sources.js.map +1 -1
  39. package/dist/isv/webhooks-api.js +5 -1
  40. package/dist/isv/webhooks-api.js.map +1 -1
  41. package/dist/legacy/client.js +19 -15
  42. package/dist/legacy/client.js.map +1 -1
  43. package/dist/legacy/index.js +5 -1
  44. package/dist/legacy/index.js.map +1 -1
  45. package/dist/observability/context.js +15 -11
  46. package/dist/observability/context.js.map +1 -1
  47. package/dist/observability/index.js +16 -5
  48. package/dist/observability/index.js.map +1 -1
  49. package/dist/observability/logger.js +11 -5
  50. package/dist/observability/logger.js.map +1 -1
  51. package/dist/observability/metrics.js +5 -1
  52. package/dist/observability/metrics.js.map +1 -1
  53. package/dist/observability/redact.js +4 -1
  54. package/dist/observability/redact.js.map +1 -1
  55. package/dist/observability/tracer.js +5 -1
  56. package/dist/observability/tracer.js.map +1 -1
  57. package/dist/payments/client.js +17 -13
  58. package/dist/payments/client.js.map +1 -1
  59. package/dist/payments/index.js +5 -1
  60. package/dist/payments/index.js.map +1 -1
  61. package/dist/refunds/fast-refund-client.js +11 -7
  62. package/dist/refunds/fast-refund-client.js.map +1 -1
  63. package/dist/refunds/index.js +7 -2
  64. package/dist/refunds/index.js.map +1 -1
  65. package/dist/refunds/strategy.js +4 -1
  66. package/dist/refunds/strategy.js.map +1 -1
  67. package/dist/types/auth.js +2 -1
  68. package/dist/types/auth.js.map +1 -1
  69. package/dist/types/card-types.js +7 -3
  70. package/dist/types/card-types.js.map +1 -1
  71. package/dist/types/common.js +8 -4
  72. package/dist/types/common.js.map +1 -1
  73. package/dist/types/index.js +14 -6
  74. package/dist/types/index.js.map +1 -1
  75. package/dist/types/isv-accounts.js +2 -1
  76. package/dist/types/isv-accounts.js.map +1 -1
  77. package/dist/types/isv-payments.js +2 -1
  78. package/dist/types/isv-payments.js.map +1 -1
  79. package/dist/types/status.js +2 -1
  80. package/dist/types/status.js.map +1 -1
  81. package/dist/types/webhook-events.js +5 -2
  82. package/dist/types/webhook-events.js.map +1 -1
  83. package/dist/webhooks/challenge-response.js +6 -3
  84. package/dist/webhooks/challenge-response.js.map +1 -1
  85. package/dist/webhooks/event-types.js +10 -4
  86. package/dist/webhooks/event-types.js.map +1 -1
  87. package/dist/webhooks/extract-client-ip.js +4 -1
  88. package/dist/webhooks/extract-client-ip.js.map +1 -1
  89. package/dist/webhooks/hmac-verify.js +14 -11
  90. package/dist/webhooks/hmac-verify.js.map +1 -1
  91. package/dist/webhooks/index.js +22 -6
  92. package/dist/webhooks/index.js.map +1 -1
  93. package/dist/webhooks/ip-allowlist.js +11 -7
  94. package/dist/webhooks/ip-allowlist.js.map +1 -1
  95. package/dist/webhooks/status-lattice.js +8 -3
  96. package/dist/webhooks/status-lattice.js.map +1 -1
  97. package/package.json +12 -12
  98. package/dist/isv/legacy-basic-client.d.ts +0 -122
  99. package/dist/isv/legacy-basic-client.d.ts.map +0 -1
  100. package/dist/isv/legacy-basic-client.js +0 -281
  101. package/dist/isv/legacy-basic-client.js.map +0 -1
  102. package/dist/isv/payments.d.ts +0 -199
  103. package/dist/isv/payments.d.ts.map +0 -1
  104. package/dist/isv/payments.js +0 -385
  105. package/dist/isv/payments.js.map +0 -1
@@ -1,199 +0,0 @@
1
- /**
2
- * IsvPayments — ISV Payment API methods.
3
- *
4
- * Covers:
5
- * - createOrder → POST /checkout/v2/orders?merchantId={merchantId} (OAuth2)
6
- * - retrieveTransaction → GET /checkout/v2/transactions/{transactionId} (OAuth2)
7
- * - refundPayment → POST /api/transactions/{transactionId} (Legacy/Basic)
8
- * - cancelOrder → DELETE /checkout/v2/orders/{orderCode} (OAuth2)
9
- *
10
- * All methods validate inputs locally before making HTTP calls.
11
- * Amounts are in integer minor units (bigint) per plan P15.
12
- *
13
- * Idempotency: createOrder and refundPayment are non-idempotent (idempotent: false).
14
- * retrieveTransaction and cancelOrder are idempotent.
15
- *
16
- * --- Refund path (F1 — probe-verified 2026-04-25) ---
17
- * Viva returns 405 on `POST /checkout/v2/transactions/{id}` (v2/OAuth2 path).
18
- * The ONLY working refund path is `POST /api/transactions/{transactionId}` on the
19
- * LEGACY HOST (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
20
- * (MerchantId + ApiKey). The 401-fallback design is NOT applicable here — Viva
21
- * returns 405 (not 401) on the v2 path, so no fallback would ever trigger.
22
- * refundPayment now calls `legacyClient` DIRECTLY without any v2 attempt.
23
- *
24
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund endpoint)
25
- *
26
- * --- retrieveTransaction / cancelOrder fallback (D15 — kept defensive) ---
27
- * The optional `secondaryClient` is a fallback for retrieveTransaction and
28
- * cancelOrder. When the primary OAuth2 client returns 401 (after force-refresh),
29
- * the call retries once with the secondary client. A 401 from secondary surfaces
30
- * as VivaAuthError — no further retry.
31
- * Note: cancelOrder is unverified against live sandbox as of 2026-04-25 probe;
32
- * kept on OAuth2 + 401-fallback path defensively.
33
- *
34
- * --- Idempotency-Key header (F2 — probe-verified 2026-04-25) ---
35
- * The `Idempotency-Key` header is sent on createOrder but Viva does NOT appear
36
- * to deduplicate server-side (same key returned two different orderCodes in probe).
37
- * Local dedup via `viva_transaction` row is the authoritative dedup mechanism.
38
- * Header is retained for forward-compat (zero cost, may be honoured in future).
39
- *
40
- * @see references/viva-docs/md/payment-isv-api.txt:1
41
- * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
42
- * @see references/viva-docs/md/isv-partner-program.txt:104 (ISV overview)
43
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
44
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
45
- */
46
- import type { IsvHttpClient } from './client.js';
47
- import type { LegacyBasicClient } from './legacy-basic-client.js';
48
- import type { CreateOrderRequest, CreateOrderResponse, RetrieveTransactionResponse, RefundResponse, CancelOrderResponse, MerchantId, TransactionId, OrderCode, MinorUnits } from '../types/index.js';
49
- /**
50
- * ISV Payment API client.
51
- *
52
- * Constructed with an IsvHttpClient instance shared across all ISV modules.
53
- * Each method scopes its request to a specific merchant via the merchantId
54
- * query parameter per the ISV integration model.
55
- *
56
- * - `client`: primary OAuth2 client for createOrder, retrieveTransaction, cancelOrder.
57
- * - `secondaryClient`: optional 401-fallback for retrieveTransaction and cancelOrder.
58
- * When undefined, 401 errors propagate normally.
59
- * - `legacyClient`: REQUIRED for refundPayment. Calls `POST /api/transactions/{id}`
60
- * on the legacy host with Basic auth (MerchantId + ApiKey). If absent, refundPayment
61
- * throws `VIVA_REFUND_REJECTED` with a config-missing message.
62
- *
63
- * Probe-verified 2026-04-25: refund MUST go through legacy client — v2/OAuth2 path
64
- * returns 405. cancelOrder is unverified but kept on v2/OAuth2 + 401-fallback defensively.
65
- *
66
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund path)
67
- * @see references/viva-docs/md/payment-isv-api.txt:1
68
- * @see references/viva-docs/md/isv-partner-program.txt:61 (P1: merchant scoping)
69
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
70
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback)
71
- */
72
- export declare class IsvPayments {
73
- private readonly client;
74
- private readonly secondaryClient?;
75
- private readonly legacyClient?;
76
- constructor(client: IsvHttpClient, secondaryClient?: IsvHttpClient | undefined, legacyClient?: LegacyBasicClient | undefined);
77
- /**
78
- * Create a payment order for a specific ISV merchant.
79
- *
80
- * Sends a POST /checkout/v2/orders?merchantId={merchantId} request.
81
- * The `Idempotency-Key` header is sent on every call but Viva does NOT appear
82
- * to deduplicate server-side as of 2026-04-25 (probe: same key → two different
83
- * orderCodes). Local dedup via `viva_transaction` row is the authoritative
84
- * dedup mechanism. Header retained for forward-compat only.
85
- *
86
- * Input validation (throws VivaValidationError before HTTP call):
87
- * - amountMinor must be > 0 (per plan P15)
88
- * - currencyCode must be a valid 3-digit numeric string (per plan P15)
89
- *
90
- * Non-idempotent: does not retry on 4xx/5xx (only connection-level errors).
91
- *
92
- * @see references/viva-docs/md/payment-isv-api.txt:1
93
- * @see references/viva-docs/md/isv-partner-program.txt:61 (P14 idempotency)
94
- * @see references/viva-docs/md/isv-partner-program.txt:83 (P15 amounts)
95
- */
96
- createOrder(req: CreateOrderRequest, opts: {
97
- merchantId: MerchantId;
98
- idempotencyKey: string;
99
- }): Promise<CreateOrderResponse>;
100
- /**
101
- * Retrieve transaction details for a specific ISV merchant transaction.
102
- *
103
- * Per Viva docs, this SHOULD be called before updating any local transaction
104
- * status on receipt of a webhook. Validates orderCode and statusId from Viva.
105
- *
106
- * Idempotent: safe to retry on 429 and 5xx.
107
- *
108
- * Path + auth verified 2026-04-25 (F3):
109
- * `GET /checkout/v2/transactions/{transactionId}` with OAuth2 Bearer → correct.
110
- * 404 error envelope shape: `{"status": 404, "message": null, "eventId": "0"}`.
111
- * Note: `message` can be null — handle defensively.
112
- *
113
- * 401 → reseller fallback (D15) — kept DEFENSIVE:
114
- * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
115
- * the request is retried once with the secondary (Reseller basic-auth) client.
116
- * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
117
- * The primary path is verified working; fallback is defensive for edge-case tenants.
118
- *
119
- * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
120
- * @see references/viva-docs/md/payment-isv-api.txt:1
121
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
122
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
123
- */
124
- retrieveTransaction(transactionId: TransactionId, opts?: {
125
- merchantId?: MerchantId;
126
- }): Promise<RetrieveTransactionResponse>;
127
- /**
128
- * Issue a full or partial refund for a captured transaction.
129
- *
130
- * IMPORTANT — probe-verified 2026-04-25 (F1):
131
- * Viva returns 405 Method Not Allowed on `POST /checkout/v2/transactions/{id}`
132
- * (the v2/OAuth2 path). The ONLY working refund path is:
133
- * `POST /api/transactions/{transactionId}` on the LEGACY HOST
134
- * (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
135
- * (MerchantId:ApiKey) and form-urlencoded body.
136
- *
137
- * This method calls `legacyClient` DIRECTLY. The 401-fallback (D15) does NOT
138
- * apply here — Viva returns 405 (not 401) on the v2 path, so no fallback
139
- * could ever trigger.
140
- *
141
- * If `legacyClient` is not configured (absent from constructor), this method
142
- * throws VivaValidationError with code VIVA_REFUND_REJECTED indicating that
143
- * the basic-auth credentials are required and missing.
144
- *
145
- * Per plan P18:
146
- * - Full refund: omit amountMinor (no Amount in form body per Viva convention).
147
- * - Partial refund: provide amountMinor > 0 (Amount sent in form body).
148
- * - ISV fee reverses automatically on refund (per isv-partner-program.txt:296).
149
- * - Failed refund (4xx) surfaces as VivaApiError; payment NOT marked refunded.
150
- *
151
- * Non-idempotent: does not retry on 4xx/5xx.
152
- *
153
- * Viva response fields (PascalCase, mapped to camelCase):
154
- * StatusId → statusId, Amount → amount, TransactionId → transactionId.
155
- *
156
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy path + basic auth)
157
- * @see references/viva-docs/md/isv-partner-program.txt:296 (ISV fee reversal on refund)
158
- * @see references/viva-docs/md/merchant-id-and-api-key.txt:1 (basic auth credentials)
159
- */
160
- refundPayment(transactionId: TransactionId, opts: {
161
- merchantId: MerchantId;
162
- amountMinor?: MinorUnits;
163
- sourceCode?: string;
164
- idempotencyKey: string;
165
- }): Promise<RefundResponse>;
166
- /**
167
- * Cancel an order that has not yet been paid.
168
- *
169
- * Idempotent per Viva docs: calling cancel on an already-cancelled or
170
- * captured order returns the existing Viva response without error.
171
- *
172
- * Per plan P18: cancellation triggers webhook 4865 (Order Updated).
173
- *
174
- * Path: `DELETE /checkout/v2/orders/{orderCode}?merchantId={merchantId}` (OAuth2).
175
- *
176
- * UNVERIFIED against live sandbox as of 2026-04-25 probe. Only
177
- * cancel-transaction (refund/reverse) was tested; cancel-order was not.
178
- * Kept on v2/OAuth2 + 401-fallback path defensively.
179
- *
180
- * 401 → reseller fallback (D15) — kept DEFENSIVE:
181
- * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
182
- * the request is retried once with the secondary (Reseller basic-auth) client.
183
- * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
184
- *
185
- * Note: if cancelOrder already succeeded on Viva's side before any 401 is
186
- * observed, a 4xx from Viva on a subsequent attempt signals the order is
187
- * already cancelled (idempotent). The fallback does NOT apply to non-401
188
- * errors — those propagate as VivaApiError unchanged.
189
- *
190
- * @see references/viva-docs/md/payment-isv-api.txt:1
191
- * @see references/viva-docs/md/webhooks-for-payments.txt:205 (4865 Order Updated)
192
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
193
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
194
- */
195
- cancelOrder(orderCode: OrderCode, opts: {
196
- merchantId: MerchantId;
197
- }): Promise<CancelOrderResponse>;
198
- }
199
- //# sourceMappingURL=payments.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/isv/payments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAC3B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACX,MAAM,mBAAmB,CAAC;AAuB3B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAFb,MAAM,EAAE,aAAa,EACrB,eAAe,CAAC,EAAE,aAAa,YAAA,EAC/B,YAAY,CAAC,EAAE,iBAAiB,YAAA;IAGnD;;;;;;;;;;;;;;;;;;OAkBG;IACG,WAAW,CACf,GAAG,EAAE,kBAAkB,EACvB,IAAI,EAAE;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GACvD,OAAO,CAAC,mBAAmB,CAAC;IA4C/B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,mBAAmB,CACvB,aAAa,EAAE,aAAa,EAC5B,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,UAAU,CAAA;KAAO,GACrC,OAAO,CAAC,2BAA2B,CAAC;IA+DvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,aAAa,CACjB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE;QACJ,UAAU,EAAE,UAAU,CAAC;QACvB,WAAW,CAAC,EAAE,UAAU,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;KACxB,GACA,OAAO,CAAC,cAAc,CAAC;IAuD1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,WAAW,CACf,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE;QAAE,UAAU,EAAE,UAAU,CAAA;KAAE,GAC/B,OAAO,CAAC,mBAAmB,CAAC;CAgChC"}
@@ -1,385 +0,0 @@
1
- /**
2
- * IsvPayments — ISV Payment API methods.
3
- *
4
- * Covers:
5
- * - createOrder → POST /checkout/v2/orders?merchantId={merchantId} (OAuth2)
6
- * - retrieveTransaction → GET /checkout/v2/transactions/{transactionId} (OAuth2)
7
- * - refundPayment → POST /api/transactions/{transactionId} (Legacy/Basic)
8
- * - cancelOrder → DELETE /checkout/v2/orders/{orderCode} (OAuth2)
9
- *
10
- * All methods validate inputs locally before making HTTP calls.
11
- * Amounts are in integer minor units (bigint) per plan P15.
12
- *
13
- * Idempotency: createOrder and refundPayment are non-idempotent (idempotent: false).
14
- * retrieveTransaction and cancelOrder are idempotent.
15
- *
16
- * --- Refund path (F1 — probe-verified 2026-04-25) ---
17
- * Viva returns 405 on `POST /checkout/v2/transactions/{id}` (v2/OAuth2 path).
18
- * The ONLY working refund path is `POST /api/transactions/{transactionId}` on the
19
- * LEGACY HOST (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
20
- * (MerchantId + ApiKey). The 401-fallback design is NOT applicable here — Viva
21
- * returns 405 (not 401) on the v2 path, so no fallback would ever trigger.
22
- * refundPayment now calls `legacyClient` DIRECTLY without any v2 attempt.
23
- *
24
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund endpoint)
25
- *
26
- * --- retrieveTransaction / cancelOrder fallback (D15 — kept defensive) ---
27
- * The optional `secondaryClient` is a fallback for retrieveTransaction and
28
- * cancelOrder. When the primary OAuth2 client returns 401 (after force-refresh),
29
- * the call retries once with the secondary client. A 401 from secondary surfaces
30
- * as VivaAuthError — no further retry.
31
- * Note: cancelOrder is unverified against live sandbox as of 2026-04-25 probe;
32
- * kept on OAuth2 + 401-fallback path defensively.
33
- *
34
- * --- Idempotency-Key header (F2 — probe-verified 2026-04-25) ---
35
- * The `Idempotency-Key` header is sent on createOrder but Viva does NOT appear
36
- * to deduplicate server-side (same key returned two different orderCodes in probe).
37
- * Local dedup via `viva_transaction` row is the authoritative dedup mechanism.
38
- * Header is retained for forward-compat (zero cost, may be honoured in future).
39
- *
40
- * @see references/viva-docs/md/payment-isv-api.txt:1
41
- * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
42
- * @see references/viva-docs/md/isv-partner-program.txt:104 (ISV overview)
43
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
44
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
45
- */
46
- import { VivaValidationError, VivaAuthError } from '../errors/index.js';
47
- // ---------------------------------------------------------------------------
48
- // Validation helpers
49
- // ---------------------------------------------------------------------------
50
- /**
51
- * Validates an ISO 4217 numeric currency code (3-digit numeric string).
52
- *
53
- * Per plan P15: currencyCode must be a valid 3-digit numeric string.
54
- * Examples: '978' (EUR), '826' (GBP), '840' (USD).
55
- *
56
- * @see references/viva-docs/md/webhooks-for-payments.txt:487
57
- */
58
- function isValidCurrencyCode(code) {
59
- return /^\d{3}$/.test(code);
60
- }
61
- // ---------------------------------------------------------------------------
62
- // IsvPayments
63
- // ---------------------------------------------------------------------------
64
- /**
65
- * ISV Payment API client.
66
- *
67
- * Constructed with an IsvHttpClient instance shared across all ISV modules.
68
- * Each method scopes its request to a specific merchant via the merchantId
69
- * query parameter per the ISV integration model.
70
- *
71
- * - `client`: primary OAuth2 client for createOrder, retrieveTransaction, cancelOrder.
72
- * - `secondaryClient`: optional 401-fallback for retrieveTransaction and cancelOrder.
73
- * When undefined, 401 errors propagate normally.
74
- * - `legacyClient`: REQUIRED for refundPayment. Calls `POST /api/transactions/{id}`
75
- * on the legacy host with Basic auth (MerchantId + ApiKey). If absent, refundPayment
76
- * throws `VIVA_REFUND_REJECTED` with a config-missing message.
77
- *
78
- * Probe-verified 2026-04-25: refund MUST go through legacy client — v2/OAuth2 path
79
- * returns 405. cancelOrder is unverified but kept on v2/OAuth2 + 401-fallback defensively.
80
- *
81
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund path)
82
- * @see references/viva-docs/md/payment-isv-api.txt:1
83
- * @see references/viva-docs/md/isv-partner-program.txt:61 (P1: merchant scoping)
84
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
85
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback)
86
- */
87
- export class IsvPayments {
88
- client;
89
- secondaryClient;
90
- legacyClient;
91
- constructor(client, secondaryClient, legacyClient) {
92
- this.client = client;
93
- this.secondaryClient = secondaryClient;
94
- this.legacyClient = legacyClient;
95
- }
96
- /**
97
- * Create a payment order for a specific ISV merchant.
98
- *
99
- * Sends a POST /checkout/v2/orders?merchantId={merchantId} request.
100
- * The `Idempotency-Key` header is sent on every call but Viva does NOT appear
101
- * to deduplicate server-side as of 2026-04-25 (probe: same key → two different
102
- * orderCodes). Local dedup via `viva_transaction` row is the authoritative
103
- * dedup mechanism. Header retained for forward-compat only.
104
- *
105
- * Input validation (throws VivaValidationError before HTTP call):
106
- * - amountMinor must be > 0 (per plan P15)
107
- * - currencyCode must be a valid 3-digit numeric string (per plan P15)
108
- *
109
- * Non-idempotent: does not retry on 4xx/5xx (only connection-level errors).
110
- *
111
- * @see references/viva-docs/md/payment-isv-api.txt:1
112
- * @see references/viva-docs/md/isv-partner-program.txt:61 (P14 idempotency)
113
- * @see references/viva-docs/md/isv-partner-program.txt:83 (P15 amounts)
114
- */
115
- async createOrder(req, opts) {
116
- // Local validation per P14 and P15
117
- if (req.amount <= 0n) {
118
- throw new VivaValidationError({
119
- message: `createOrder: amountMinor must be > 0, got ${req.amount}`,
120
- });
121
- }
122
- if (!isValidCurrencyCode(req.currencyCode)) {
123
- throw new VivaValidationError({
124
- message: `createOrder: currencyCode must be a 3-digit numeric string (ISO 4217), got "${req.currencyCode}"`,
125
- });
126
- }
127
- // Build wire body: convert bigint amount to number for JSON.
128
- // Amount in minor units is always within safe integer range for real payments.
129
- const wireBody = {
130
- amount: req.amount, // bigintSafeStringify in client handles this
131
- currencyCode: Number(req.currencyCode), // Viva expects numeric currency code as number
132
- };
133
- if (req.merchantTrns !== undefined)
134
- wireBody['merchantTrns'] = req.merchantTrns;
135
- if (req.customerTrns !== undefined)
136
- wireBody['customerTrns'] = req.customerTrns;
137
- if (req.customerEmail !== undefined)
138
- wireBody['email'] = req.customerEmail;
139
- if (req.customerPhone !== undefined)
140
- wireBody['phone'] = req.customerPhone;
141
- if (req.customerFullName !== undefined)
142
- wireBody['fullName'] = req.customerFullName;
143
- if (req.successUrl !== undefined)
144
- wireBody['successUrl'] = req.successUrl;
145
- if (req.failureUrl !== undefined)
146
- wireBody['failureUrl'] = req.failureUrl;
147
- if (req.tags !== undefined)
148
- wireBody['tags'] = req.tags;
149
- if (req.sourceCode !== undefined)
150
- wireBody['sourceCode'] = req.sourceCode;
151
- if (req.paymentTimeoutSeconds !== undefined)
152
- wireBody['paymentTimeout'] = req.paymentTimeoutSeconds;
153
- if (req.preselectedPaymentMethod !== undefined)
154
- wireBody['preselectedPaymentMethod'] = req.preselectedPaymentMethod;
155
- const raw = await this.client.request({
156
- method: 'POST',
157
- path: '/checkout/v2/orders',
158
- query: { merchantId: opts.merchantId },
159
- body: wireBody,
160
- idempotencyKey: opts.idempotencyKey,
161
- idempotent: false, // per plan Auth Flow line 319
162
- endpoint: 'POST /checkout/v2/orders',
163
- });
164
- return { orderCode: raw.OrderCode };
165
- }
166
- /**
167
- * Retrieve transaction details for a specific ISV merchant transaction.
168
- *
169
- * Per Viva docs, this SHOULD be called before updating any local transaction
170
- * status on receipt of a webhook. Validates orderCode and statusId from Viva.
171
- *
172
- * Idempotent: safe to retry on 429 and 5xx.
173
- *
174
- * Path + auth verified 2026-04-25 (F3):
175
- * `GET /checkout/v2/transactions/{transactionId}` with OAuth2 Bearer → correct.
176
- * 404 error envelope shape: `{"status": 404, "message": null, "eventId": "0"}`.
177
- * Note: `message` can be null — handle defensively.
178
- *
179
- * 401 → reseller fallback (D15) — kept DEFENSIVE:
180
- * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
181
- * the request is retried once with the secondary (Reseller basic-auth) client.
182
- * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
183
- * The primary path is verified working; fallback is defensive for edge-case tenants.
184
- *
185
- * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
186
- * @see references/viva-docs/md/payment-isv-api.txt:1
187
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
188
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
189
- */
190
- async retrieveTransaction(transactionId, opts = {}) {
191
- const query = {};
192
- if (opts.merchantId)
193
- query['merchantId'] = opts.merchantId;
194
- const requestOpts = {
195
- method: 'GET',
196
- path: `/checkout/v2/transactions/${transactionId}`,
197
- query,
198
- idempotent: true,
199
- endpoint: 'GET /checkout/v2/transactions/{transactionId}',
200
- };
201
- // Viva API returns PascalCase field names (e.g. OrderCode, StatusId).
202
- // We normalize to camelCase matching RetrieveTransactionResponse.
203
- // The bigint-safe parser in IsvHttpClient already converts OrderCode to bigint.
204
- let raw;
205
- try {
206
- raw = await this.client.request(requestOpts);
207
- }
208
- catch (err) {
209
- // 401 → reseller fallback (D15). Only attempt if secondaryClient is present.
210
- // A 401 from the secondary surfaces immediately — no further retry.
211
- // @see docs/plans/vendure-plugin-v0.md §D15
212
- // @see references/viva-docs/md/isv-credentials.txt:107
213
- if (err instanceof VivaAuthError && err.httpStatus === 401 && this.secondaryClient) {
214
- raw = await this.secondaryClient.request(requestOpts);
215
- }
216
- else {
217
- throw err;
218
- }
219
- }
220
- // Normalize: accept both PascalCase (wire) and camelCase (normalized) field names.
221
- // @see references/viva-docs/md/account-api.txt:1584 (OrderCode: long)
222
- const orderCode = (raw['orderCode'] ?? raw['OrderCode']);
223
- const cardNumber = raw['cardNumber'] ?? raw['CardNumber'];
224
- const cardTypeId = raw['cardTypeId'] ?? raw['CardTypeId'];
225
- const email = raw['email'] ?? raw['Email'];
226
- const fullName = raw['fullName'] ?? raw['FullName'];
227
- const merchantTrns = raw['merchantTrns'] ?? raw['MerchantTrns'];
228
- const customerTrns = raw['customerTrns'] ?? raw['CustomerTrns'];
229
- const connectedAccountId = raw['connectedAccountId'] ?? raw['ConnectedAccountId'];
230
- // Build with conditional optional fields to satisfy exactOptionalPropertyTypes.
231
- // (Cannot assign to readonly Partial<> properties so we use spread.)
232
- return {
233
- transactionId: (raw['transactionId'] ?? raw['TransactionId']),
234
- orderCode,
235
- statusId: (raw['statusId'] ?? raw['StatusId']),
236
- amount: BigInt((raw['amount'] ?? raw['Amount']) ?? 0),
237
- currencyCode: (raw['currencyCode'] ?? raw['CurrencyCode']),
238
- merchantId: (raw['merchantId'] ?? raw['MerchantId']),
239
- parentId: (raw['parentId'] ?? raw['ParentId']) ?? null,
240
- insDate: (raw['insDate'] ?? raw['InsDate'] ?? ''),
241
- transactionTypeId: (raw['transactionTypeId'] ?? raw['TransactionTypeId']) ?? 0,
242
- ...(typeof cardNumber === 'string' ? { cardNumber } : {}),
243
- ...(typeof cardTypeId === 'number' ? { cardTypeId } : {}),
244
- ...(typeof email === 'string' ? { email } : {}),
245
- ...(typeof fullName === 'string' ? { fullName } : {}),
246
- ...(typeof merchantTrns === 'string' ? { merchantTrns } : {}),
247
- ...(typeof customerTrns === 'string' ? { customerTrns } : {}),
248
- ...(typeof connectedAccountId === 'string' ? { connectedAccountId } : {}),
249
- };
250
- }
251
- /**
252
- * Issue a full or partial refund for a captured transaction.
253
- *
254
- * IMPORTANT — probe-verified 2026-04-25 (F1):
255
- * Viva returns 405 Method Not Allowed on `POST /checkout/v2/transactions/{id}`
256
- * (the v2/OAuth2 path). The ONLY working refund path is:
257
- * `POST /api/transactions/{transactionId}` on the LEGACY HOST
258
- * (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
259
- * (MerchantId:ApiKey) and form-urlencoded body.
260
- *
261
- * This method calls `legacyClient` DIRECTLY. The 401-fallback (D15) does NOT
262
- * apply here — Viva returns 405 (not 401) on the v2 path, so no fallback
263
- * could ever trigger.
264
- *
265
- * If `legacyClient` is not configured (absent from constructor), this method
266
- * throws VivaValidationError with code VIVA_REFUND_REJECTED indicating that
267
- * the basic-auth credentials are required and missing.
268
- *
269
- * Per plan P18:
270
- * - Full refund: omit amountMinor (no Amount in form body per Viva convention).
271
- * - Partial refund: provide amountMinor > 0 (Amount sent in form body).
272
- * - ISV fee reverses automatically on refund (per isv-partner-program.txt:296).
273
- * - Failed refund (4xx) surfaces as VivaApiError; payment NOT marked refunded.
274
- *
275
- * Non-idempotent: does not retry on 4xx/5xx.
276
- *
277
- * Viva response fields (PascalCase, mapped to camelCase):
278
- * StatusId → statusId, Amount → amount, TransactionId → transactionId.
279
- *
280
- * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy path + basic auth)
281
- * @see references/viva-docs/md/isv-partner-program.txt:296 (ISV fee reversal on refund)
282
- * @see references/viva-docs/md/merchant-id-and-api-key.txt:1 (basic auth credentials)
283
- */
284
- async refundPayment(transactionId, opts) {
285
- // Local validation per P18
286
- if (opts.amountMinor !== undefined && opts.amountMinor <= 0n) {
287
- throw new VivaValidationError({
288
- message: `refundPayment: amountMinor must be > 0 when specified, got ${opts.amountMinor}`,
289
- });
290
- }
291
- // legacyClient REQUIRED for refund (F1 — probe-verified 2026-04-25).
292
- if (!this.legacyClient) {
293
- throw new VivaValidationError({
294
- message: 'refundPayment requires a legacyClient (Basic auth with MerchantId + ApiKey). ' +
295
- 'Configure VIVA_MERCHANT_ID and VIVA_API_KEY in plugin options. ' +
296
- 'Viva returns 405 on the v2/OAuth2 refund path (probe-verified 2026-04-25).',
297
- });
298
- }
299
- // Build form-urlencoded body.
300
- // - Amount: send only for partial refund; omit for full refund per Viva convention.
301
- // - SourceCode: defaults to 'Default'.
302
- // @see references/viva-docs/md/tut-create-recurring-payment.txt:288
303
- const formBody = {
304
- SourceCode: opts.sourceCode ?? 'Default',
305
- };
306
- if (opts.amountMinor !== undefined) {
307
- // Viva legacy endpoint expects amount in minor units as integer.
308
- formBody['Amount'] = opts.amountMinor;
309
- }
310
- const result = await this.legacyClient.request({
311
- method: 'POST',
312
- path: `/api/transactions/${transactionId}`,
313
- formBody,
314
- idempotent: false, // non-idempotent POST — no 4xx/5xx retry
315
- endpoint: 'POST /api/transactions/{transactionId}',
316
- });
317
- const raw = result.data;
318
- // Map PascalCase → camelCase and return typed RefundResponse.
319
- return {
320
- transactionId: (raw.TransactionId ?? transactionId),
321
- ...(raw.StatusId !== undefined ? { statusId: raw.StatusId } : {}),
322
- ...(raw.Amount !== undefined ? { amount: BigInt(raw.Amount) } : {}),
323
- };
324
- }
325
- /**
326
- * Cancel an order that has not yet been paid.
327
- *
328
- * Idempotent per Viva docs: calling cancel on an already-cancelled or
329
- * captured order returns the existing Viva response without error.
330
- *
331
- * Per plan P18: cancellation triggers webhook 4865 (Order Updated).
332
- *
333
- * Path: `DELETE /checkout/v2/orders/{orderCode}?merchantId={merchantId}` (OAuth2).
334
- *
335
- * UNVERIFIED against live sandbox as of 2026-04-25 probe. Only
336
- * cancel-transaction (refund/reverse) was tested; cancel-order was not.
337
- * Kept on v2/OAuth2 + 401-fallback path defensively.
338
- *
339
- * 401 → reseller fallback (D15) — kept DEFENSIVE:
340
- * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
341
- * the request is retried once with the secondary (Reseller basic-auth) client.
342
- * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
343
- *
344
- * Note: if cancelOrder already succeeded on Viva's side before any 401 is
345
- * observed, a 4xx from Viva on a subsequent attempt signals the order is
346
- * already cancelled (idempotent). The fallback does NOT apply to non-401
347
- * errors — those propagate as VivaApiError unchanged.
348
- *
349
- * @see references/viva-docs/md/payment-isv-api.txt:1
350
- * @see references/viva-docs/md/webhooks-for-payments.txt:205 (4865 Order Updated)
351
- * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
352
- * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
353
- */
354
- async cancelOrder(orderCode, opts) {
355
- const requestOpts = {
356
- method: 'DELETE',
357
- path: `/checkout/v2/orders/${orderCode}`,
358
- query: { merchantId: opts.merchantId },
359
- idempotent: true, // idempotent per Viva docs
360
- endpoint: 'DELETE /checkout/v2/orders/{orderCode}',
361
- };
362
- let raw;
363
- try {
364
- raw = await this.client.request(requestOpts);
365
- }
366
- catch (err) {
367
- // 401 → reseller fallback (D15). Only attempt if secondaryClient is present.
368
- // A 401 from the secondary surfaces immediately — no further retry.
369
- // @see docs/plans/vendure-plugin-v0.md §D15
370
- // @see references/viva-docs/md/isv-credentials.txt:107
371
- if (err instanceof VivaAuthError && err.httpStatus === 401 && this.secondaryClient) {
372
- raw = await this.secondaryClient.request(requestOpts);
373
- }
374
- else {
375
- throw err;
376
- }
377
- }
378
- return {
379
- orderCode: raw.OrderCode,
380
- errorCode: raw.ErrorCode,
381
- errorText: raw.ErrorText,
382
- };
383
- }
384
- }
385
- //# sourceMappingURL=payments.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payments.js","sourceRoot":"","sources":["../../src/isv/payments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAeH,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,WAAW;IAEH;IACA;IACA;IAHnB,YACmB,MAAqB,EACrB,eAA+B,EAC/B,YAAgC;QAFhC,WAAM,GAAN,MAAM,CAAe;QACrB,oBAAe,GAAf,eAAe,CAAgB;QAC/B,iBAAY,GAAZ,YAAY,CAAoB;IAChD,CAAC;IAEJ;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,WAAW,CACf,GAAuB,EACvB,IAAwD;QAExD,mCAAmC;QACnC,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACrB,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,6CAA6C,GAAG,CAAC,MAAM,EAAE;aACnE,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,+EAA+E,GAAG,CAAC,YAAY,GAAG;aAC5G,CAAC,CAAC;QACL,CAAC;QAED,6DAA6D;QAC7D,+EAA+E;QAC/E,MAAM,QAAQ,GAA4B;YACxC,MAAM,EAAE,GAAG,CAAC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