@sakeetech/viva-payments-core 0.2.1

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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +413 -0
  3. package/dist/auth/http.d.ts +44 -0
  4. package/dist/auth/http.d.ts.map +1 -0
  5. package/dist/auth/http.js +80 -0
  6. package/dist/auth/http.js.map +1 -0
  7. package/dist/auth/index.d.ts +19 -0
  8. package/dist/auth/index.d.ts.map +1 -0
  9. package/dist/auth/index.js +18 -0
  10. package/dist/auth/index.js.map +1 -0
  11. package/dist/auth/oauth2-strategy.d.ts +117 -0
  12. package/dist/auth/oauth2-strategy.d.ts.map +1 -0
  13. package/dist/auth/oauth2-strategy.js +217 -0
  14. package/dist/auth/oauth2-strategy.js.map +1 -0
  15. package/dist/auth/reseller-strategy.d.ts +65 -0
  16. package/dist/auth/reseller-strategy.d.ts.map +1 -0
  17. package/dist/auth/reseller-strategy.js +68 -0
  18. package/dist/auth/reseller-strategy.js.map +1 -0
  19. package/dist/auth/single-flight.d.ts +81 -0
  20. package/dist/auth/single-flight.d.ts.map +1 -0
  21. package/dist/auth/single-flight.js +160 -0
  22. package/dist/auth/single-flight.js.map +1 -0
  23. package/dist/auth/token-cache.d.ts +50 -0
  24. package/dist/auth/token-cache.d.ts.map +1 -0
  25. package/dist/auth/token-cache.js +59 -0
  26. package/dist/auth/token-cache.js.map +1 -0
  27. package/dist/errors/api-error.d.ts +15 -0
  28. package/dist/errors/api-error.d.ts.map +1 -0
  29. package/dist/errors/api-error.js +18 -0
  30. package/dist/errors/api-error.js.map +1 -0
  31. package/dist/errors/auth-error.d.ts +14 -0
  32. package/dist/errors/auth-error.d.ts.map +1 -0
  33. package/dist/errors/auth-error.js +17 -0
  34. package/dist/errors/auth-error.js.map +1 -0
  35. package/dist/errors/base.d.ts +59 -0
  36. package/dist/errors/base.d.ts.map +1 -0
  37. package/dist/errors/base.js +51 -0
  38. package/dist/errors/base.js.map +1 -0
  39. package/dist/errors/index.d.ts +18 -0
  40. package/dist/errors/index.d.ts.map +1 -0
  41. package/dist/errors/index.js +16 -0
  42. package/dist/errors/index.js.map +1 -0
  43. package/dist/errors/mode-mismatch-error.d.ts +19 -0
  44. package/dist/errors/mode-mismatch-error.d.ts.map +1 -0
  45. package/dist/errors/mode-mismatch-error.js +22 -0
  46. package/dist/errors/mode-mismatch-error.js.map +1 -0
  47. package/dist/errors/rate-limit-error.d.ts +20 -0
  48. package/dist/errors/rate-limit-error.d.ts.map +1 -0
  49. package/dist/errors/rate-limit-error.js +20 -0
  50. package/dist/errors/rate-limit-error.js.map +1 -0
  51. package/dist/errors/validation-error.d.ts +14 -0
  52. package/dist/errors/validation-error.d.ts.map +1 -0
  53. package/dist/errors/validation-error.js +17 -0
  54. package/dist/errors/validation-error.js.map +1 -0
  55. package/dist/errors/webhook-error.d.ts +14 -0
  56. package/dist/errors/webhook-error.d.ts.map +1 -0
  57. package/dist/errors/webhook-error.js +17 -0
  58. package/dist/errors/webhook-error.js.map +1 -0
  59. package/dist/index.d.ts +15 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +15 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/isv/accounts.d.ts +38 -0
  64. package/dist/isv/accounts.d.ts.map +1 -0
  65. package/dist/isv/accounts.js +60 -0
  66. package/dist/isv/accounts.js.map +1 -0
  67. package/dist/isv/client.d.ts +187 -0
  68. package/dist/isv/client.d.ts.map +1 -0
  69. package/dist/isv/client.js +465 -0
  70. package/dist/isv/client.js.map +1 -0
  71. package/dist/isv/index.d.ts +52 -0
  72. package/dist/isv/index.d.ts.map +1 -0
  73. package/dist/isv/index.js +53 -0
  74. package/dist/isv/index.js.map +1 -0
  75. package/dist/isv/legacy-basic-client.d.ts +122 -0
  76. package/dist/isv/legacy-basic-client.d.ts.map +1 -0
  77. package/dist/isv/legacy-basic-client.js +281 -0
  78. package/dist/isv/legacy-basic-client.js.map +1 -0
  79. package/dist/isv/payments.d.ts +199 -0
  80. package/dist/isv/payments.d.ts.map +1 -0
  81. package/dist/isv/payments.js +385 -0
  82. package/dist/isv/payments.js.map +1 -0
  83. package/dist/isv/sources.d.ts +80 -0
  84. package/dist/isv/sources.d.ts.map +1 -0
  85. package/dist/isv/sources.js +112 -0
  86. package/dist/isv/sources.js.map +1 -0
  87. package/dist/isv/webhooks-api.d.ts +48 -0
  88. package/dist/isv/webhooks-api.d.ts.map +1 -0
  89. package/dist/isv/webhooks-api.js +66 -0
  90. package/dist/isv/webhooks-api.js.map +1 -0
  91. package/dist/legacy/client.d.ts +199 -0
  92. package/dist/legacy/client.d.ts.map +1 -0
  93. package/dist/legacy/client.js +351 -0
  94. package/dist/legacy/client.js.map +1 -0
  95. package/dist/legacy/index.d.ts +15 -0
  96. package/dist/legacy/index.d.ts.map +1 -0
  97. package/dist/legacy/index.js +14 -0
  98. package/dist/legacy/index.js.map +1 -0
  99. package/dist/observability/context.d.ts +30 -0
  100. package/dist/observability/context.d.ts.map +1 -0
  101. package/dist/observability/context.js +40 -0
  102. package/dist/observability/context.js.map +1 -0
  103. package/dist/observability/index.d.ts +15 -0
  104. package/dist/observability/index.d.ts.map +1 -0
  105. package/dist/observability/index.js +11 -0
  106. package/dist/observability/index.js.map +1 -0
  107. package/dist/observability/logger.d.ts +81 -0
  108. package/dist/observability/logger.d.ts.map +1 -0
  109. package/dist/observability/logger.js +127 -0
  110. package/dist/observability/logger.js.map +1 -0
  111. package/dist/observability/metrics.d.ts +37 -0
  112. package/dist/observability/metrics.d.ts.map +1 -0
  113. package/dist/observability/metrics.js +40 -0
  114. package/dist/observability/metrics.js.map +1 -0
  115. package/dist/observability/redact.d.ts +21 -0
  116. package/dist/observability/redact.d.ts.map +1 -0
  117. package/dist/observability/redact.js +72 -0
  118. package/dist/observability/redact.js.map +1 -0
  119. package/dist/observability/tracer.d.ts +25 -0
  120. package/dist/observability/tracer.d.ts.map +1 -0
  121. package/dist/observability/tracer.js +18 -0
  122. package/dist/observability/tracer.js.map +1 -0
  123. package/dist/payments/client.d.ts +247 -0
  124. package/dist/payments/client.d.ts.map +1 -0
  125. package/dist/payments/client.js +488 -0
  126. package/dist/payments/client.js.map +1 -0
  127. package/dist/payments/index.d.ts +14 -0
  128. package/dist/payments/index.d.ts.map +1 -0
  129. package/dist/payments/index.js +13 -0
  130. package/dist/payments/index.js.map +1 -0
  131. package/dist/refunds/fast-refund-client.d.ts +128 -0
  132. package/dist/refunds/fast-refund-client.d.ts.map +1 -0
  133. package/dist/refunds/fast-refund-client.js +138 -0
  134. package/dist/refunds/fast-refund-client.js.map +1 -0
  135. package/dist/refunds/index.d.ts +19 -0
  136. package/dist/refunds/index.d.ts.map +1 -0
  137. package/dist/refunds/index.js +17 -0
  138. package/dist/refunds/index.js.map +1 -0
  139. package/dist/refunds/strategy.d.ts +78 -0
  140. package/dist/refunds/strategy.d.ts.map +1 -0
  141. package/dist/refunds/strategy.js +75 -0
  142. package/dist/refunds/strategy.js.map +1 -0
  143. package/dist/types/auth.d.ts +80 -0
  144. package/dist/types/auth.d.ts.map +1 -0
  145. package/dist/types/auth.js +12 -0
  146. package/dist/types/auth.js.map +1 -0
  147. package/dist/types/card-types.d.ts +48 -0
  148. package/dist/types/card-types.d.ts.map +1 -0
  149. package/dist/types/card-types.js +62 -0
  150. package/dist/types/card-types.js.map +1 -0
  151. package/dist/types/common.d.ts +160 -0
  152. package/dist/types/common.d.ts.map +1 -0
  153. package/dist/types/common.js +70 -0
  154. package/dist/types/common.js.map +1 -0
  155. package/dist/types/index.d.ts +21 -0
  156. package/dist/types/index.d.ts.map +1 -0
  157. package/dist/types/index.js +21 -0
  158. package/dist/types/index.js.map +1 -0
  159. package/dist/types/isv-accounts.d.ts +109 -0
  160. package/dist/types/isv-accounts.d.ts.map +1 -0
  161. package/dist/types/isv-accounts.js +22 -0
  162. package/dist/types/isv-accounts.js.map +1 -0
  163. package/dist/types/isv-payments.d.ts +262 -0
  164. package/dist/types/isv-payments.d.ts.map +1 -0
  165. package/dist/types/isv-payments.js +19 -0
  166. package/dist/types/isv-payments.js.map +1 -0
  167. package/dist/types/status.d.ts +125 -0
  168. package/dist/types/status.d.ts.map +1 -0
  169. package/dist/types/status.js +19 -0
  170. package/dist/types/status.js.map +1 -0
  171. package/dist/types/webhook-events.d.ts +447 -0
  172. package/dist/types/webhook-events.d.ts.map +1 -0
  173. package/dist/types/webhook-events.js +76 -0
  174. package/dist/types/webhook-events.js.map +1 -0
  175. package/dist/webhooks/challenge-response.d.ts +28 -0
  176. package/dist/webhooks/challenge-response.d.ts.map +1 -0
  177. package/dist/webhooks/challenge-response.js +35 -0
  178. package/dist/webhooks/challenge-response.js.map +1 -0
  179. package/dist/webhooks/event-types.d.ts +44 -0
  180. package/dist/webhooks/event-types.d.ts.map +1 -0
  181. package/dist/webhooks/event-types.js +50 -0
  182. package/dist/webhooks/event-types.js.map +1 -0
  183. package/dist/webhooks/extract-client-ip.d.ts +40 -0
  184. package/dist/webhooks/extract-client-ip.d.ts.map +1 -0
  185. package/dist/webhooks/extract-client-ip.js +72 -0
  186. package/dist/webhooks/extract-client-ip.js.map +1 -0
  187. package/dist/webhooks/hmac-verify.d.ts +38 -0
  188. package/dist/webhooks/hmac-verify.d.ts.map +1 -0
  189. package/dist/webhooks/hmac-verify.js +92 -0
  190. package/dist/webhooks/hmac-verify.js.map +1 -0
  191. package/dist/webhooks/index.d.ts +19 -0
  192. package/dist/webhooks/index.d.ts.map +1 -0
  193. package/dist/webhooks/index.js +19 -0
  194. package/dist/webhooks/index.js.map +1 -0
  195. package/dist/webhooks/ip-allowlist.d.ts +59 -0
  196. package/dist/webhooks/ip-allowlist.d.ts.map +1 -0
  197. package/dist/webhooks/ip-allowlist.js +147 -0
  198. package/dist/webhooks/ip-allowlist.js.map +1 -0
  199. package/dist/webhooks/status-lattice.d.ts +72 -0
  200. package/dist/webhooks/status-lattice.d.ts.map +1 -0
  201. package/dist/webhooks/status-lattice.js +208 -0
  202. package/dist/webhooks/status-lattice.js.map +1 -0
  203. package/package.json +85 -0
@@ -0,0 +1,488 @@
1
+ /**
2
+ * Payments — Viva Payment API methods (mode-aware).
3
+ *
4
+ * The class is parameterised by `mode: 'merchant' | 'isv'`. URL paths and
5
+ * query-string contracts switch per mode:
6
+ *
7
+ * createOrder
8
+ * merchant → POST /checkout/v2/orders (OAuth2)
9
+ * isv → POST /checkout/v2/isv/orders?merchantId={uuid} (OAuth2)
10
+ * retrieveTransaction
11
+ * merchant → GET /checkout/v2/transactions/{transactionId} (OAuth2)
12
+ * isv → GET /checkout/v2/isv/transactions/{transactionId}?merchantId={uuid} (OAuth2)
13
+ * cancelOrder
14
+ * merchant → DELETE /checkout/v2/orders/{orderCode} (OAuth2)
15
+ * isv → DELETE /checkout/v2/orders/{orderCode}?merchantId={uuid} (OAuth2)
16
+ * refundPayment
17
+ * both → POST /api/transactions/{transactionId} (Legacy/Basic)
18
+ *
19
+ * In merchant mode `opts.merchantId` (if passed) is silently ignored — never
20
+ * added to the query string. In ISV mode `merchantId` is required and a
21
+ * VivaValidationError is thrown if absent.
22
+ *
23
+ * `CreateOrderRequest.isvAmount` is stripped from the wire body when
24
+ * `mode === 'merchant'` — only forwarded on the ISV `/isv/orders` path.
25
+ *
26
+ * All methods validate inputs locally before making HTTP calls.
27
+ * Amounts are in integer minor units (bigint) per plan P15.
28
+ *
29
+ * Idempotency: createOrder and refundPayment are non-idempotent (idempotent: false).
30
+ * retrieveTransaction and cancelOrder are idempotent.
31
+ *
32
+ * --- Refund path (F1 — probe-verified 2026-04-25) ---
33
+ * Viva returns 405 on `POST /checkout/v2/transactions/{id}` (v2/OAuth2 path).
34
+ * The ONLY working refund path is `POST /api/transactions/{transactionId}` on the
35
+ * LEGACY HOST (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
36
+ * (MerchantId + ApiKey). The 401-fallback design is NOT applicable here — Viva
37
+ * returns 405 (not 401) on the v2 path, so no fallback would ever trigger.
38
+ * refundPayment now calls `legacyClient` DIRECTLY without any v2 attempt.
39
+ *
40
+ * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund endpoint)
41
+ *
42
+ * --- retrieveTransaction / cancelOrder fallback (D15 — kept defensive) ---
43
+ * The optional `secondaryClient` is a fallback for retrieveTransaction and
44
+ * cancelOrder. When the primary OAuth2 client returns 401 (after force-refresh),
45
+ * the call retries once with the secondary client. A 401 from secondary surfaces
46
+ * as VivaAuthError — no further retry.
47
+ * Note: cancelOrder is unverified against live sandbox as of 2026-04-25 probe;
48
+ * kept on OAuth2 + 401-fallback path defensively.
49
+ *
50
+ * --- Idempotency-Key header (F2 — probe-verified 2026-04-25) ---
51
+ * The `Idempotency-Key` header is sent on createOrder but Viva does NOT appear
52
+ * to deduplicate server-side (same key returned two different orderCodes in probe).
53
+ * Local dedup via `viva_transaction` row is the authoritative dedup mechanism.
54
+ * Header is retained for forward-compat (zero cost, may be honoured in future).
55
+ *
56
+ * @see references/viva-docs/md/payment-isv-api.txt:1
57
+ * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
58
+ * @see references/viva-docs/md/isv-partner-program.txt:104 (ISV overview)
59
+ * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
60
+ * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
61
+ */
62
+ import { VivaValidationError, VivaAuthError } from '../errors/index.js';
63
+ import { resolveCardType } from '../types/card-types.js';
64
+ // ---------------------------------------------------------------------------
65
+ // Validation helpers
66
+ // ---------------------------------------------------------------------------
67
+ /**
68
+ * Validates an ISO 4217 numeric currency code (3-digit numeric string).
69
+ *
70
+ * Per plan P15: currencyCode must be a valid 3-digit numeric string.
71
+ * Examples: '978' (EUR), '826' (GBP), '840' (USD).
72
+ *
73
+ * @see references/viva-docs/md/webhooks-for-payments.txt:487
74
+ */
75
+ function isValidCurrencyCode(code) {
76
+ return /^\d{3}$/.test(code);
77
+ }
78
+ /**
79
+ * Build the path + query for `POST /checkout/v2/(isv/)orders`.
80
+ *
81
+ * In ISV mode `merchantId` is REQUIRED — throws VivaValidationError if absent.
82
+ * In merchant mode `merchantId` is ignored entirely.
83
+ */
84
+ function buildOrderCreateUrl(mode, merchantId) {
85
+ switch (mode) {
86
+ case 'merchant':
87
+ return { path: '/checkout/v2/orders', query: {} };
88
+ case 'isv':
89
+ if (!merchantId) {
90
+ throw new VivaValidationError({
91
+ message: "createOrder: merchantId is required when mode='isv'",
92
+ });
93
+ }
94
+ return { path: '/checkout/v2/isv/orders', query: { merchantId } };
95
+ }
96
+ }
97
+ /**
98
+ * Build the path + query for `GET /checkout/v2/(isv/)transactions/{id}`.
99
+ *
100
+ * In ISV mode `merchantId` is REQUIRED — throws VivaValidationError if absent.
101
+ * In merchant mode `merchantId` is ignored entirely.
102
+ */
103
+ function buildTransactionRetrieveUrl(mode, transactionId, merchantId) {
104
+ switch (mode) {
105
+ case 'merchant':
106
+ return { path: `/checkout/v2/transactions/${transactionId}`, query: {} };
107
+ case 'isv':
108
+ if (!merchantId) {
109
+ throw new VivaValidationError({
110
+ message: "retrieveTransaction: merchantId is required when mode='isv'",
111
+ });
112
+ }
113
+ return {
114
+ path: `/checkout/v2/isv/transactions/${transactionId}`,
115
+ query: { merchantId },
116
+ };
117
+ }
118
+ }
119
+ /**
120
+ * Build the path + query for `DELETE /checkout/v2/orders/{orderCode}`.
121
+ *
122
+ * Both modes share the same path template; only ISV mode appends the
123
+ * `merchantId` query parameter (and requires it).
124
+ */
125
+ function buildOrderCancelUrl(mode, orderCode, merchantId) {
126
+ const path = `/checkout/v2/orders/${orderCode}`;
127
+ switch (mode) {
128
+ case 'merchant':
129
+ return { path, query: {} };
130
+ case 'isv':
131
+ if (!merchantId) {
132
+ throw new VivaValidationError({
133
+ message: "cancelOrder: merchantId is required when mode='isv'",
134
+ });
135
+ }
136
+ return { path, query: { merchantId } };
137
+ }
138
+ }
139
+ // ---------------------------------------------------------------------------
140
+ // Payments
141
+ // ---------------------------------------------------------------------------
142
+ /**
143
+ * Viva Payment API client (mode-aware).
144
+ *
145
+ * Constructed with a {@link PaymentsConfig}. The `mode` field determines URL
146
+ * paths and query-string contract per slice 2 of the multi-mode refactor.
147
+ *
148
+ * - `mode`: `'merchant'` or `'isv'`. Required.
149
+ * - `client`: primary OAuth2 client for createOrder, retrieveTransaction, cancelOrder.
150
+ * - `secondaryClient`: optional 401-fallback for retrieveTransaction and cancelOrder.
151
+ * When undefined, 401 errors propagate normally.
152
+ * - `legacyClient`: REQUIRED for refundPayment. Calls `POST /api/transactions/{id}`
153
+ * on the legacy host with Basic auth (MerchantId + ApiKey). If absent, refundPayment
154
+ * throws `VIVA_REFUND_REJECTED` with a config-missing message.
155
+ *
156
+ * Probe-verified 2026-04-25: refund MUST go through legacy client — v2/OAuth2 path
157
+ * returns 405. cancelOrder is unverified but kept on v2/OAuth2 + 401-fallback defensively.
158
+ *
159
+ * @see docs/plans/multi-mode-v0.md §8.1
160
+ * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund path)
161
+ * @see references/viva-docs/md/payment-isv-api.txt:1
162
+ * @see references/viva-docs/md/isv-partner-program.txt:61 (P1: merchant scoping)
163
+ * @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
164
+ * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback)
165
+ */
166
+ export class Payments {
167
+ mode;
168
+ client;
169
+ secondaryClient;
170
+ legacyClient;
171
+ constructor(config) {
172
+ this.mode = config.mode;
173
+ this.client = config.client;
174
+ this.secondaryClient = config.secondaryClient;
175
+ this.legacyClient = config.legacyClient;
176
+ }
177
+ /**
178
+ * Create a payment order for a specific ISV merchant.
179
+ *
180
+ * Sends a POST /checkout/v2/orders?merchantId={merchantId} request.
181
+ * The `Idempotency-Key` header is sent on every call but Viva does NOT appear
182
+ * to deduplicate server-side as of 2026-04-25 (probe: same key → two different
183
+ * orderCodes). Local dedup via `viva_transaction` row is the authoritative
184
+ * dedup mechanism. Header retained for forward-compat only.
185
+ *
186
+ * Input validation (throws VivaValidationError before HTTP call):
187
+ * - amountMinor must be > 0 (per plan P15)
188
+ * - currencyCode must be a valid 3-digit numeric string (per plan P15)
189
+ *
190
+ * Non-idempotent: does not retry on 4xx/5xx (only connection-level errors).
191
+ *
192
+ * @see references/viva-docs/md/payment-isv-api.txt:1
193
+ * @see references/viva-docs/md/isv-partner-program.txt:61 (P14 idempotency)
194
+ * @see references/viva-docs/md/isv-partner-program.txt:83 (P15 amounts)
195
+ */
196
+ async createOrder(req, opts) {
197
+ // Local validation per P14 and P15
198
+ if (req.amount <= 0n) {
199
+ throw new VivaValidationError({
200
+ message: `createOrder: amountMinor must be > 0, got ${req.amount}`,
201
+ });
202
+ }
203
+ if (!isValidCurrencyCode(req.currencyCode)) {
204
+ throw new VivaValidationError({
205
+ message: `createOrder: currencyCode must be a 3-digit numeric string (ISO 4217), got "${req.currencyCode}"`,
206
+ });
207
+ }
208
+ // Resolve URL per mode. Throws VivaValidationError in ISV mode if
209
+ // merchantId is missing. In merchant mode `opts.merchantId` is silently
210
+ // ignored — back-compat for adapters that still pass it.
211
+ const { path, query } = buildOrderCreateUrl(this.mode, opts.merchantId);
212
+ // Build wire body: convert bigint amount to number for JSON.
213
+ // Amount in minor units is always within safe integer range for real payments.
214
+ const wireBody = {
215
+ amount: req.amount, // bigintSafeStringify in client handles this
216
+ currencyCode: Number(req.currencyCode), // Viva expects numeric currency code as number
217
+ };
218
+ if (req.merchantTrns !== undefined)
219
+ wireBody['merchantTrns'] = req.merchantTrns;
220
+ if (req.customerTrns !== undefined)
221
+ wireBody['customerTrns'] = req.customerTrns;
222
+ if (req.customerEmail !== undefined)
223
+ wireBody['email'] = req.customerEmail;
224
+ if (req.customerPhone !== undefined)
225
+ wireBody['phone'] = req.customerPhone;
226
+ if (req.customerFullName !== undefined)
227
+ wireBody['fullName'] = req.customerFullName;
228
+ if (req.successUrl !== undefined)
229
+ wireBody['successUrl'] = req.successUrl;
230
+ if (req.failureUrl !== undefined)
231
+ wireBody['failureUrl'] = req.failureUrl;
232
+ if (req.tags !== undefined)
233
+ wireBody['tags'] = req.tags;
234
+ if (req.sourceCode !== undefined)
235
+ wireBody['sourceCode'] = req.sourceCode;
236
+ if (req.paymentTimeoutSeconds !== undefined)
237
+ wireBody['paymentTimeout'] = req.paymentTimeoutSeconds;
238
+ if (req.preselectedPaymentMethod !== undefined)
239
+ wireBody['preselectedPaymentMethod'] = req.preselectedPaymentMethod;
240
+ // ISV-only: `isvAmount` only emitted in ISV mode. Strip in merchant mode
241
+ // even if caller passed it (forward-compat shim for shared adapter code).
242
+ if (this.mode === 'isv' && req.isvAmount !== undefined) {
243
+ wireBody['isvAmount'] = req.isvAmount;
244
+ }
245
+ const raw = await this.client.request({
246
+ method: 'POST',
247
+ path,
248
+ query,
249
+ body: wireBody,
250
+ idempotencyKey: opts.idempotencyKey,
251
+ idempotent: false, // per plan Auth Flow line 319
252
+ endpoint: `POST ${path}`,
253
+ });
254
+ return { orderCode: raw.OrderCode };
255
+ }
256
+ /**
257
+ * Retrieve transaction details for a specific ISV merchant transaction.
258
+ *
259
+ * Per Viva docs, this SHOULD be called before updating any local transaction
260
+ * status on receipt of a webhook. Validates orderCode and statusId from Viva.
261
+ *
262
+ * Idempotent: safe to retry on 429 and 5xx.
263
+ *
264
+ * Path + auth verified 2026-04-25 (F3):
265
+ * `GET /checkout/v2/transactions/{transactionId}` with OAuth2 Bearer → correct.
266
+ * 404 error envelope shape: `{"status": 404, "message": null, "eventId": "0"}`.
267
+ * Note: `message` can be null — handle defensively.
268
+ *
269
+ * 401 → reseller fallback (D15) — kept DEFENSIVE:
270
+ * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
271
+ * the request is retried once with the secondary (Reseller basic-auth) client.
272
+ * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
273
+ * The primary path is verified working; fallback is defensive for edge-case tenants.
274
+ *
275
+ * @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
276
+ * @see references/viva-docs/md/payment-isv-api.txt:1
277
+ * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
278
+ * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
279
+ */
280
+ async retrieveTransaction(transactionId, opts = {}) {
281
+ // Resolve URL per mode. In merchant mode `opts.merchantId` is silently
282
+ // ignored. In ISV mode it is required.
283
+ const { path, query } = buildTransactionRetrieveUrl(this.mode, transactionId, opts.merchantId);
284
+ const endpointTemplate = this.mode === 'isv'
285
+ ? 'GET /checkout/v2/isv/transactions/{transactionId}'
286
+ : 'GET /checkout/v2/transactions/{transactionId}';
287
+ const requestOpts = {
288
+ method: 'GET',
289
+ path,
290
+ query,
291
+ idempotent: true,
292
+ endpoint: endpointTemplate,
293
+ };
294
+ // Viva API returns PascalCase field names (e.g. OrderCode, StatusId).
295
+ // We normalize to camelCase matching RetrieveTransactionResponse.
296
+ // The bigint-safe parser in IsvHttpClient already converts OrderCode to bigint.
297
+ let raw;
298
+ try {
299
+ raw = await this.client.request(requestOpts);
300
+ }
301
+ catch (err) {
302
+ // 401 → reseller fallback (D15). Only attempt if secondaryClient is present.
303
+ // A 401 from the secondary surfaces immediately — no further retry.
304
+ // @see docs/plans/vendure-plugin-v0.md §D15
305
+ // @see references/viva-docs/md/isv-credentials.txt:107
306
+ if (err instanceof VivaAuthError && err.httpStatus === 401 && this.secondaryClient) {
307
+ raw = await this.secondaryClient.request(requestOpts);
308
+ }
309
+ else {
310
+ throw err;
311
+ }
312
+ }
313
+ // Normalize: accept both PascalCase (wire) and camelCase (normalized) field names.
314
+ // @see references/viva-docs/md/account-api.txt:1584 (OrderCode: long)
315
+ const orderCode = (raw['orderCode'] ?? raw['OrderCode']);
316
+ const cardNumber = raw['cardNumber'] ?? raw['CardNumber'];
317
+ const cardTypeId = raw['cardTypeId'] ?? raw['CardTypeId'];
318
+ const email = raw['email'] ?? raw['Email'];
319
+ const fullName = raw['fullName'] ?? raw['FullName'];
320
+ const merchantTrns = raw['merchantTrns'] ?? raw['MerchantTrns'];
321
+ const customerTrns = raw['customerTrns'] ?? raw['CustomerTrns'];
322
+ const connectedAccountId = raw['connectedAccountId'] ?? raw['ConnectedAccountId'];
323
+ // Derive cardType (string scheme name) from Viva's numeric cardTypeId.
324
+ // Pure mapping via resolveCardType — undefined when id is absent, a
325
+ // sentinel (Invalid/Unknown), or otherwise unmapped.
326
+ // @see ../types/card-types.ts
327
+ // @see ../refunds/strategy.ts (consumer)
328
+ const cardType = typeof cardTypeId === 'number' ? resolveCardType(cardTypeId) : undefined;
329
+ // Build with conditional optional fields to satisfy exactOptionalPropertyTypes.
330
+ // (Cannot assign to readonly Partial<> properties so we use spread.)
331
+ return {
332
+ transactionId: (raw['transactionId'] ?? raw['TransactionId']),
333
+ orderCode,
334
+ statusId: (raw['statusId'] ?? raw['StatusId']),
335
+ amount: BigInt((raw['amount'] ?? raw['Amount']) ?? 0),
336
+ currencyCode: (raw['currencyCode'] ?? raw['CurrencyCode']),
337
+ merchantId: (raw['merchantId'] ?? raw['MerchantId']),
338
+ parentId: (raw['parentId'] ?? raw['ParentId']) ?? null,
339
+ insDate: (raw['insDate'] ?? raw['InsDate'] ?? ''),
340
+ transactionTypeId: (raw['transactionTypeId'] ?? raw['TransactionTypeId']) ?? 0,
341
+ ...(typeof cardNumber === 'string' ? { cardNumber } : {}),
342
+ ...(typeof cardTypeId === 'number' ? { cardTypeId } : {}),
343
+ ...(cardType !== undefined ? { cardType } : {}),
344
+ ...(typeof email === 'string' ? { email } : {}),
345
+ ...(typeof fullName === 'string' ? { fullName } : {}),
346
+ ...(typeof merchantTrns === 'string' ? { merchantTrns } : {}),
347
+ ...(typeof customerTrns === 'string' ? { customerTrns } : {}),
348
+ ...(typeof connectedAccountId === 'string' ? { connectedAccountId } : {}),
349
+ };
350
+ }
351
+ /**
352
+ * Issue a full or partial refund for a captured transaction.
353
+ *
354
+ * IMPORTANT — probe-verified 2026-04-25 (F1):
355
+ * Viva returns 405 Method Not Allowed on `POST /checkout/v2/transactions/{id}`
356
+ * (the v2/OAuth2 path). The ONLY working refund path is:
357
+ * `POST /api/transactions/{transactionId}` on the LEGACY HOST
358
+ * (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
359
+ * (MerchantId:ApiKey) and form-urlencoded body.
360
+ *
361
+ * This method calls `legacyClient` DIRECTLY. The 401-fallback (D15) does NOT
362
+ * apply here — Viva returns 405 (not 401) on the v2 path, so no fallback
363
+ * could ever trigger.
364
+ *
365
+ * If `legacyClient` is not configured (absent from constructor), this method
366
+ * throws VivaValidationError with code VIVA_REFUND_REJECTED indicating that
367
+ * the basic-auth credentials are required and missing.
368
+ *
369
+ * Per plan P18:
370
+ * - Full refund: omit amountMinor (no Amount in form body per Viva convention).
371
+ * - Partial refund: provide amountMinor > 0 (Amount sent in form body).
372
+ * - ISV fee reverses automatically on refund (per isv-partner-program.txt:296).
373
+ * - Failed refund (4xx) surfaces as VivaApiError; payment NOT marked refunded.
374
+ *
375
+ * Non-idempotent: does not retry on 4xx/5xx.
376
+ *
377
+ * Viva response fields (PascalCase, mapped to camelCase):
378
+ * StatusId → statusId, Amount → amount, TransactionId → transactionId.
379
+ *
380
+ * @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy path + basic auth)
381
+ * @see references/viva-docs/md/isv-partner-program.txt:296 (ISV fee reversal on refund)
382
+ * @see references/viva-docs/md/merchant-id-and-api-key.txt:1 (basic auth credentials)
383
+ */
384
+ async refundPayment(transactionId, opts) {
385
+ // Local validation per P18
386
+ if (opts.amountMinor !== undefined && opts.amountMinor <= 0n) {
387
+ throw new VivaValidationError({
388
+ message: `refundPayment: amountMinor must be > 0 when specified, got ${opts.amountMinor}`,
389
+ });
390
+ }
391
+ // legacyClient REQUIRED for refund (F1 — probe-verified 2026-04-25).
392
+ if (!this.legacyClient) {
393
+ throw new VivaValidationError({
394
+ message: 'refundPayment requires a legacyClient (Basic auth with MerchantId + ApiKey). ' +
395
+ 'Configure VIVA_MERCHANT_ID and VIVA_API_KEY in plugin options. ' +
396
+ 'Viva returns 405 on the v2/OAuth2 refund path (probe-verified 2026-04-25).',
397
+ });
398
+ }
399
+ // Build form-urlencoded body.
400
+ // - Amount: send only for partial refund; omit for full refund per Viva convention.
401
+ // - SourceCode: defaults to 'Default'.
402
+ // @see references/viva-docs/md/tut-create-recurring-payment.txt:288
403
+ const formBody = {
404
+ SourceCode: opts.sourceCode ?? 'Default',
405
+ };
406
+ if (opts.amountMinor !== undefined) {
407
+ // Viva legacy endpoint expects amount in minor units as integer.
408
+ formBody['Amount'] = opts.amountMinor;
409
+ }
410
+ const result = await this.legacyClient.request({
411
+ method: 'POST',
412
+ path: `/api/transactions/${transactionId}`,
413
+ formBody,
414
+ idempotent: false, // non-idempotent POST — no 4xx/5xx retry
415
+ endpoint: 'POST /api/transactions/{transactionId}',
416
+ });
417
+ const raw = result.data;
418
+ // Map PascalCase → camelCase and return typed RefundResponse.
419
+ return {
420
+ transactionId: (raw.TransactionId ?? transactionId),
421
+ ...(raw.StatusId !== undefined ? { statusId: raw.StatusId } : {}),
422
+ ...(raw.Amount !== undefined ? { amount: BigInt(raw.Amount) } : {}),
423
+ };
424
+ }
425
+ /**
426
+ * Cancel an order that has not yet been paid.
427
+ *
428
+ * Idempotent per Viva docs: calling cancel on an already-cancelled or
429
+ * captured order returns the existing Viva response without error.
430
+ *
431
+ * Per plan P18: cancellation triggers webhook 4865 (Order Updated).
432
+ *
433
+ * Path: `DELETE /checkout/v2/orders/{orderCode}?merchantId={merchantId}` (OAuth2).
434
+ *
435
+ * UNVERIFIED against live sandbox as of 2026-04-25 probe. Only
436
+ * cancel-transaction (refund/reverse) was tested; cancel-order was not.
437
+ * Kept on v2/OAuth2 + 401-fallback path defensively.
438
+ *
439
+ * 401 → reseller fallback (D15) — kept DEFENSIVE:
440
+ * If the primary OAuth2 client receives a 401 and secondaryClient is configured,
441
+ * the request is retried once with the secondary (Reseller basic-auth) client.
442
+ * A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
443
+ *
444
+ * Note: if cancelOrder already succeeded on Viva's side before any 401 is
445
+ * observed, a 4xx from Viva on a subsequent attempt signals the order is
446
+ * already cancelled (idempotent). The fallback does NOT apply to non-401
447
+ * errors — those propagate as VivaApiError unchanged.
448
+ *
449
+ * @see references/viva-docs/md/payment-isv-api.txt:1
450
+ * @see references/viva-docs/md/webhooks-for-payments.txt:205 (4865 Order Updated)
451
+ * @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
452
+ * @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
453
+ */
454
+ async cancelOrder(orderCode, opts = {}) {
455
+ // Resolve URL per mode. In merchant mode `opts.merchantId` is silently
456
+ // ignored. In ISV mode it is required.
457
+ const { path, query } = buildOrderCancelUrl(this.mode, orderCode, opts.merchantId);
458
+ const requestOpts = {
459
+ method: 'DELETE',
460
+ path,
461
+ query,
462
+ idempotent: true, // idempotent per Viva docs
463
+ endpoint: 'DELETE /checkout/v2/orders/{orderCode}',
464
+ };
465
+ let raw;
466
+ try {
467
+ raw = await this.client.request(requestOpts);
468
+ }
469
+ catch (err) {
470
+ // 401 → reseller fallback (D15). Only attempt if secondaryClient is present.
471
+ // A 401 from the secondary surfaces immediately — no further retry.
472
+ // @see docs/plans/vendure-plugin-v0.md §D15
473
+ // @see references/viva-docs/md/isv-credentials.txt:107
474
+ if (err instanceof VivaAuthError && err.httpStatus === 401 && this.secondaryClient) {
475
+ raw = await this.secondaryClient.request(requestOpts);
476
+ }
477
+ else {
478
+ throw err;
479
+ }
480
+ }
481
+ return {
482
+ orderCode: raw.OrderCode,
483
+ errorCode: raw.ErrorCode,
484
+ errorText: raw.ErrorText,
485
+ };
486
+ }
487
+ }
488
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/payments/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAeH,OAAO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E,uCAAuC;QACvC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnF,MAAM,WAAW,GAAG;YAClB,MAAM,EAAE,QAAiB;YACzB,IAAI;YACJ,KAAK;YACL,UAAU,EAAE,IAAa,EAAE,2BAA2B;YACtD,QAAQ,EAAE,wCAAwC;SACnD,CAAC;QAEF,IAAI,GAAc,CAAC;QACnB,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAY,WAAW,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,6EAA6E;YAC7E,oEAAoE;YACpE,4CAA4C;YAC5C,uDAAuD;YACvD,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBACnF,GAAG,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAY,WAAW,CAAC,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * viva-payments-core/payments — barrel export.
3
+ *
4
+ * Subpath: `viva-payments-core/payments`
5
+ *
6
+ * The Payments client wraps Viva's payment surface (createOrder,
7
+ * retrieveTransaction, refundPayment, cancelOrder). Constructed with an
8
+ * IsvHttpClient (OAuth2) and optionally a BasicAuthClient (for refund).
9
+ *
10
+ * @see references/viva-docs/md/payment-isv-api.txt:1
11
+ */
12
+ export { Payments } from './client.js';
13
+ export type { PaymentsMode, PaymentsConfig } from './client.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/payments/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * viva-payments-core/payments — barrel export.
3
+ *
4
+ * Subpath: `viva-payments-core/payments`
5
+ *
6
+ * The Payments client wraps Viva's payment surface (createOrder,
7
+ * retrieveTransaction, refundPayment, cancelOrder). Constructed with an
8
+ * IsvHttpClient (OAuth2) and optionally a BasicAuthClient (for refund).
9
+ *
10
+ * @see references/viva-docs/md/payment-isv-api.txt:1
11
+ */
12
+ export { Payments } from './client.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/payments/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}