@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.
- package/LICENSE +21 -0
- package/README.md +413 -0
- package/dist/auth/http.d.ts +44 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +80 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/index.d.ts +19 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +18 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth2-strategy.d.ts +117 -0
- package/dist/auth/oauth2-strategy.d.ts.map +1 -0
- package/dist/auth/oauth2-strategy.js +217 -0
- package/dist/auth/oauth2-strategy.js.map +1 -0
- package/dist/auth/reseller-strategy.d.ts +65 -0
- package/dist/auth/reseller-strategy.d.ts.map +1 -0
- package/dist/auth/reseller-strategy.js +68 -0
- package/dist/auth/reseller-strategy.js.map +1 -0
- package/dist/auth/single-flight.d.ts +81 -0
- package/dist/auth/single-flight.d.ts.map +1 -0
- package/dist/auth/single-flight.js +160 -0
- package/dist/auth/single-flight.js.map +1 -0
- package/dist/auth/token-cache.d.ts +50 -0
- package/dist/auth/token-cache.d.ts.map +1 -0
- package/dist/auth/token-cache.js +59 -0
- package/dist/auth/token-cache.js.map +1 -0
- package/dist/errors/api-error.d.ts +15 -0
- package/dist/errors/api-error.d.ts.map +1 -0
- package/dist/errors/api-error.js +18 -0
- package/dist/errors/api-error.js.map +1 -0
- package/dist/errors/auth-error.d.ts +14 -0
- package/dist/errors/auth-error.d.ts.map +1 -0
- package/dist/errors/auth-error.js +17 -0
- package/dist/errors/auth-error.js.map +1 -0
- package/dist/errors/base.d.ts +59 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +51 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/index.d.ts +18 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +16 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/mode-mismatch-error.d.ts +19 -0
- package/dist/errors/mode-mismatch-error.d.ts.map +1 -0
- package/dist/errors/mode-mismatch-error.js +22 -0
- package/dist/errors/mode-mismatch-error.js.map +1 -0
- package/dist/errors/rate-limit-error.d.ts +20 -0
- package/dist/errors/rate-limit-error.d.ts.map +1 -0
- package/dist/errors/rate-limit-error.js +20 -0
- package/dist/errors/rate-limit-error.js.map +1 -0
- package/dist/errors/validation-error.d.ts +14 -0
- package/dist/errors/validation-error.d.ts.map +1 -0
- package/dist/errors/validation-error.js +17 -0
- package/dist/errors/validation-error.js.map +1 -0
- package/dist/errors/webhook-error.d.ts +14 -0
- package/dist/errors/webhook-error.d.ts.map +1 -0
- package/dist/errors/webhook-error.js +17 -0
- package/dist/errors/webhook-error.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/isv/accounts.d.ts +38 -0
- package/dist/isv/accounts.d.ts.map +1 -0
- package/dist/isv/accounts.js +60 -0
- package/dist/isv/accounts.js.map +1 -0
- package/dist/isv/client.d.ts +187 -0
- package/dist/isv/client.d.ts.map +1 -0
- package/dist/isv/client.js +465 -0
- package/dist/isv/client.js.map +1 -0
- package/dist/isv/index.d.ts +52 -0
- package/dist/isv/index.d.ts.map +1 -0
- package/dist/isv/index.js +53 -0
- package/dist/isv/index.js.map +1 -0
- package/dist/isv/legacy-basic-client.d.ts +122 -0
- package/dist/isv/legacy-basic-client.d.ts.map +1 -0
- package/dist/isv/legacy-basic-client.js +281 -0
- package/dist/isv/legacy-basic-client.js.map +1 -0
- package/dist/isv/payments.d.ts +199 -0
- package/dist/isv/payments.d.ts.map +1 -0
- package/dist/isv/payments.js +385 -0
- package/dist/isv/payments.js.map +1 -0
- package/dist/isv/sources.d.ts +80 -0
- package/dist/isv/sources.d.ts.map +1 -0
- package/dist/isv/sources.js +112 -0
- package/dist/isv/sources.js.map +1 -0
- package/dist/isv/webhooks-api.d.ts +48 -0
- package/dist/isv/webhooks-api.d.ts.map +1 -0
- package/dist/isv/webhooks-api.js +66 -0
- package/dist/isv/webhooks-api.js.map +1 -0
- package/dist/legacy/client.d.ts +199 -0
- package/dist/legacy/client.d.ts.map +1 -0
- package/dist/legacy/client.js +351 -0
- package/dist/legacy/client.js.map +1 -0
- package/dist/legacy/index.d.ts +15 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +14 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/observability/context.d.ts +30 -0
- package/dist/observability/context.d.ts.map +1 -0
- package/dist/observability/context.js +40 -0
- package/dist/observability/context.js.map +1 -0
- package/dist/observability/index.d.ts +15 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +81 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +127 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +37 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +40 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/redact.d.ts +21 -0
- package/dist/observability/redact.d.ts.map +1 -0
- package/dist/observability/redact.js +72 -0
- package/dist/observability/redact.js.map +1 -0
- package/dist/observability/tracer.d.ts +25 -0
- package/dist/observability/tracer.d.ts.map +1 -0
- package/dist/observability/tracer.js +18 -0
- package/dist/observability/tracer.js.map +1 -0
- package/dist/payments/client.d.ts +247 -0
- package/dist/payments/client.d.ts.map +1 -0
- package/dist/payments/client.js +488 -0
- package/dist/payments/client.js.map +1 -0
- package/dist/payments/index.d.ts +14 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +13 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/refunds/fast-refund-client.d.ts +128 -0
- package/dist/refunds/fast-refund-client.d.ts.map +1 -0
- package/dist/refunds/fast-refund-client.js +138 -0
- package/dist/refunds/fast-refund-client.js.map +1 -0
- package/dist/refunds/index.d.ts +19 -0
- package/dist/refunds/index.d.ts.map +1 -0
- package/dist/refunds/index.js +17 -0
- package/dist/refunds/index.js.map +1 -0
- package/dist/refunds/strategy.d.ts +78 -0
- package/dist/refunds/strategy.d.ts.map +1 -0
- package/dist/refunds/strategy.js +75 -0
- package/dist/refunds/strategy.js.map +1 -0
- package/dist/types/auth.d.ts +80 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +12 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/card-types.d.ts +48 -0
- package/dist/types/card-types.d.ts.map +1 -0
- package/dist/types/card-types.js +62 -0
- package/dist/types/card-types.js.map +1 -0
- package/dist/types/common.d.ts +160 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +70 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/isv-accounts.d.ts +109 -0
- package/dist/types/isv-accounts.d.ts.map +1 -0
- package/dist/types/isv-accounts.js +22 -0
- package/dist/types/isv-accounts.js.map +1 -0
- package/dist/types/isv-payments.d.ts +262 -0
- package/dist/types/isv-payments.d.ts.map +1 -0
- package/dist/types/isv-payments.js +19 -0
- package/dist/types/isv-payments.js.map +1 -0
- package/dist/types/status.d.ts +125 -0
- package/dist/types/status.d.ts.map +1 -0
- package/dist/types/status.js +19 -0
- package/dist/types/status.js.map +1 -0
- package/dist/types/webhook-events.d.ts +447 -0
- package/dist/types/webhook-events.d.ts.map +1 -0
- package/dist/types/webhook-events.js +76 -0
- package/dist/types/webhook-events.js.map +1 -0
- package/dist/webhooks/challenge-response.d.ts +28 -0
- package/dist/webhooks/challenge-response.d.ts.map +1 -0
- package/dist/webhooks/challenge-response.js +35 -0
- package/dist/webhooks/challenge-response.js.map +1 -0
- package/dist/webhooks/event-types.d.ts +44 -0
- package/dist/webhooks/event-types.d.ts.map +1 -0
- package/dist/webhooks/event-types.js +50 -0
- package/dist/webhooks/event-types.js.map +1 -0
- package/dist/webhooks/extract-client-ip.d.ts +40 -0
- package/dist/webhooks/extract-client-ip.d.ts.map +1 -0
- package/dist/webhooks/extract-client-ip.js +72 -0
- package/dist/webhooks/extract-client-ip.js.map +1 -0
- package/dist/webhooks/hmac-verify.d.ts +38 -0
- package/dist/webhooks/hmac-verify.d.ts.map +1 -0
- package/dist/webhooks/hmac-verify.js +92 -0
- package/dist/webhooks/hmac-verify.js.map +1 -0
- package/dist/webhooks/index.d.ts +19 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +19 -0
- package/dist/webhooks/index.js.map +1 -0
- package/dist/webhooks/ip-allowlist.d.ts +59 -0
- package/dist/webhooks/ip-allowlist.d.ts.map +1 -0
- package/dist/webhooks/ip-allowlist.js +147 -0
- package/dist/webhooks/ip-allowlist.js.map +1 -0
- package/dist/webhooks/status-lattice.d.ts +72 -0
- package/dist/webhooks/status-lattice.d.ts.map +1 -0
- package/dist/webhooks/status-lattice.js +208 -0
- package/dist/webhooks/status-lattice.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,247 @@
|
|
|
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 type { IsvHttpClient } from '../isv/client.js';
|
|
63
|
+
import type { BasicAuthClient } from '../legacy/client.js';
|
|
64
|
+
import type { CreateOrderRequest, CreateOrderResponse, RetrieveTransactionResponse, RefundResponse, CancelOrderResponse, MerchantId, TransactionId, OrderCode, MinorUnits } from '../types/index.js';
|
|
65
|
+
/**
|
|
66
|
+
* Payment surface mode.
|
|
67
|
+
*
|
|
68
|
+
* - `merchant` — Single-merchant integration. URLs do NOT include the
|
|
69
|
+
* `/isv` segment and do NOT carry `merchantId` query parameter. The
|
|
70
|
+
* OAuth2 token is scoped to a single merchant account.
|
|
71
|
+
* - `isv` — ISV/partner integration. URLs include the `/isv` segment
|
|
72
|
+
* where applicable and carry `merchantId={uuid}` to scope the call to a
|
|
73
|
+
* specific connected merchant.
|
|
74
|
+
*
|
|
75
|
+
* @see docs/AUTH.md §3.1
|
|
76
|
+
* @see docs/ENDPOINTS.md §2.1 / §2.2
|
|
77
|
+
*/
|
|
78
|
+
export type PaymentsMode = 'merchant' | 'isv';
|
|
79
|
+
/**
|
|
80
|
+
* Configuration for the {@link Payments} client.
|
|
81
|
+
*
|
|
82
|
+
* - `mode` REQUIRED. Determines URL paths + query-string contract.
|
|
83
|
+
* - `client` primary OAuth2 client.
|
|
84
|
+
* - `secondaryClient` optional 401-fallback client for retrieveTransaction
|
|
85
|
+
* and cancelOrder (reseller basic-auth scenario; see D15).
|
|
86
|
+
* - `legacyClient` REQUIRED for refundPayment in both modes (legacy host +
|
|
87
|
+
* Basic auth — v2 path returns 405).
|
|
88
|
+
*/
|
|
89
|
+
export interface PaymentsConfig {
|
|
90
|
+
readonly mode: PaymentsMode;
|
|
91
|
+
readonly client: IsvHttpClient;
|
|
92
|
+
readonly secondaryClient?: IsvHttpClient;
|
|
93
|
+
readonly legacyClient?: BasicAuthClient;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Viva Payment API client (mode-aware).
|
|
97
|
+
*
|
|
98
|
+
* Constructed with a {@link PaymentsConfig}. The `mode` field determines URL
|
|
99
|
+
* paths and query-string contract per slice 2 of the multi-mode refactor.
|
|
100
|
+
*
|
|
101
|
+
* - `mode`: `'merchant'` or `'isv'`. Required.
|
|
102
|
+
* - `client`: primary OAuth2 client for createOrder, retrieveTransaction, cancelOrder.
|
|
103
|
+
* - `secondaryClient`: optional 401-fallback for retrieveTransaction and cancelOrder.
|
|
104
|
+
* When undefined, 401 errors propagate normally.
|
|
105
|
+
* - `legacyClient`: REQUIRED for refundPayment. Calls `POST /api/transactions/{id}`
|
|
106
|
+
* on the legacy host with Basic auth (MerchantId + ApiKey). If absent, refundPayment
|
|
107
|
+
* throws `VIVA_REFUND_REJECTED` with a config-missing message.
|
|
108
|
+
*
|
|
109
|
+
* Probe-verified 2026-04-25: refund MUST go through legacy client — v2/OAuth2 path
|
|
110
|
+
* returns 405. cancelOrder is unverified but kept on v2/OAuth2 + 401-fallback defensively.
|
|
111
|
+
*
|
|
112
|
+
* @see docs/plans/multi-mode-v0.md §8.1
|
|
113
|
+
* @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy refund path)
|
|
114
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1
|
|
115
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P1: merchant scoping)
|
|
116
|
+
* @see references/viva-docs/md/isv-credentials.txt:107 (reseller credentials)
|
|
117
|
+
* @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback)
|
|
118
|
+
*/
|
|
119
|
+
export declare class Payments {
|
|
120
|
+
private readonly mode;
|
|
121
|
+
private readonly client;
|
|
122
|
+
private readonly secondaryClient;
|
|
123
|
+
private readonly legacyClient;
|
|
124
|
+
constructor(config: PaymentsConfig);
|
|
125
|
+
/**
|
|
126
|
+
* Create a payment order for a specific ISV merchant.
|
|
127
|
+
*
|
|
128
|
+
* Sends a POST /checkout/v2/orders?merchantId={merchantId} request.
|
|
129
|
+
* The `Idempotency-Key` header is sent on every call but Viva does NOT appear
|
|
130
|
+
* to deduplicate server-side as of 2026-04-25 (probe: same key → two different
|
|
131
|
+
* orderCodes). Local dedup via `viva_transaction` row is the authoritative
|
|
132
|
+
* dedup mechanism. Header retained for forward-compat only.
|
|
133
|
+
*
|
|
134
|
+
* Input validation (throws VivaValidationError before HTTP call):
|
|
135
|
+
* - amountMinor must be > 0 (per plan P15)
|
|
136
|
+
* - currencyCode must be a valid 3-digit numeric string (per plan P15)
|
|
137
|
+
*
|
|
138
|
+
* Non-idempotent: does not retry on 4xx/5xx (only connection-level errors).
|
|
139
|
+
*
|
|
140
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1
|
|
141
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P14 idempotency)
|
|
142
|
+
* @see references/viva-docs/md/isv-partner-program.txt:83 (P15 amounts)
|
|
143
|
+
*/
|
|
144
|
+
createOrder(req: CreateOrderRequest, opts: {
|
|
145
|
+
merchantId?: MerchantId;
|
|
146
|
+
idempotencyKey: string;
|
|
147
|
+
}): Promise<CreateOrderResponse>;
|
|
148
|
+
/**
|
|
149
|
+
* Retrieve transaction details for a specific ISV merchant transaction.
|
|
150
|
+
*
|
|
151
|
+
* Per Viva docs, this SHOULD be called before updating any local transaction
|
|
152
|
+
* status on receipt of a webhook. Validates orderCode and statusId from Viva.
|
|
153
|
+
*
|
|
154
|
+
* Idempotent: safe to retry on 429 and 5xx.
|
|
155
|
+
*
|
|
156
|
+
* Path + auth verified 2026-04-25 (F3):
|
|
157
|
+
* `GET /checkout/v2/transactions/{transactionId}` with OAuth2 Bearer → correct.
|
|
158
|
+
* 404 error envelope shape: `{"status": 404, "message": null, "eventId": "0"}`.
|
|
159
|
+
* Note: `message` can be null — handle defensively.
|
|
160
|
+
*
|
|
161
|
+
* 401 → reseller fallback (D15) — kept DEFENSIVE:
|
|
162
|
+
* If the primary OAuth2 client receives a 401 and secondaryClient is configured,
|
|
163
|
+
* the request is retried once with the secondary (Reseller basic-auth) client.
|
|
164
|
+
* A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
|
|
165
|
+
* The primary path is verified working; fallback is defensive for edge-case tenants.
|
|
166
|
+
*
|
|
167
|
+
* @see references/viva-docs/md/webhooks-for-payments.txt:248 (retrieve before update)
|
|
168
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1
|
|
169
|
+
* @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
|
|
170
|
+
* @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
|
|
171
|
+
*/
|
|
172
|
+
retrieveTransaction(transactionId: TransactionId, opts?: {
|
|
173
|
+
merchantId?: MerchantId;
|
|
174
|
+
}): Promise<RetrieveTransactionResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Issue a full or partial refund for a captured transaction.
|
|
177
|
+
*
|
|
178
|
+
* IMPORTANT — probe-verified 2026-04-25 (F1):
|
|
179
|
+
* Viva returns 405 Method Not Allowed on `POST /checkout/v2/transactions/{id}`
|
|
180
|
+
* (the v2/OAuth2 path). The ONLY working refund path is:
|
|
181
|
+
* `POST /api/transactions/{transactionId}` on the LEGACY HOST
|
|
182
|
+
* (`demo.vivapayments.com` / `www.vivapayments.com`) with Basic auth
|
|
183
|
+
* (MerchantId:ApiKey) and form-urlencoded body.
|
|
184
|
+
*
|
|
185
|
+
* This method calls `legacyClient` DIRECTLY. The 401-fallback (D15) does NOT
|
|
186
|
+
* apply here — Viva returns 405 (not 401) on the v2 path, so no fallback
|
|
187
|
+
* could ever trigger.
|
|
188
|
+
*
|
|
189
|
+
* If `legacyClient` is not configured (absent from constructor), this method
|
|
190
|
+
* throws VivaValidationError with code VIVA_REFUND_REJECTED indicating that
|
|
191
|
+
* the basic-auth credentials are required and missing.
|
|
192
|
+
*
|
|
193
|
+
* Per plan P18:
|
|
194
|
+
* - Full refund: omit amountMinor (no Amount in form body per Viva convention).
|
|
195
|
+
* - Partial refund: provide amountMinor > 0 (Amount sent in form body).
|
|
196
|
+
* - ISV fee reverses automatically on refund (per isv-partner-program.txt:296).
|
|
197
|
+
* - Failed refund (4xx) surfaces as VivaApiError; payment NOT marked refunded.
|
|
198
|
+
*
|
|
199
|
+
* Non-idempotent: does not retry on 4xx/5xx.
|
|
200
|
+
*
|
|
201
|
+
* Viva response fields (PascalCase, mapped to camelCase):
|
|
202
|
+
* StatusId → statusId, Amount → amount, TransactionId → transactionId.
|
|
203
|
+
*
|
|
204
|
+
* @see references/viva-docs/md/tut-create-recurring-payment.txt:288 (legacy path + basic auth)
|
|
205
|
+
* @see references/viva-docs/md/isv-partner-program.txt:296 (ISV fee reversal on refund)
|
|
206
|
+
* @see references/viva-docs/md/merchant-id-and-api-key.txt:1 (basic auth credentials)
|
|
207
|
+
*/
|
|
208
|
+
refundPayment(transactionId: TransactionId, opts: {
|
|
209
|
+
merchantId: MerchantId;
|
|
210
|
+
amountMinor?: MinorUnits;
|
|
211
|
+
sourceCode?: string;
|
|
212
|
+
idempotencyKey: string;
|
|
213
|
+
}): Promise<RefundResponse>;
|
|
214
|
+
/**
|
|
215
|
+
* Cancel an order that has not yet been paid.
|
|
216
|
+
*
|
|
217
|
+
* Idempotent per Viva docs: calling cancel on an already-cancelled or
|
|
218
|
+
* captured order returns the existing Viva response without error.
|
|
219
|
+
*
|
|
220
|
+
* Per plan P18: cancellation triggers webhook 4865 (Order Updated).
|
|
221
|
+
*
|
|
222
|
+
* Path: `DELETE /checkout/v2/orders/{orderCode}?merchantId={merchantId}` (OAuth2).
|
|
223
|
+
*
|
|
224
|
+
* UNVERIFIED against live sandbox as of 2026-04-25 probe. Only
|
|
225
|
+
* cancel-transaction (refund/reverse) was tested; cancel-order was not.
|
|
226
|
+
* Kept on v2/OAuth2 + 401-fallback path defensively.
|
|
227
|
+
*
|
|
228
|
+
* 401 → reseller fallback (D15) — kept DEFENSIVE:
|
|
229
|
+
* If the primary OAuth2 client receives a 401 and secondaryClient is configured,
|
|
230
|
+
* the request is retried once with the secondary (Reseller basic-auth) client.
|
|
231
|
+
* A 401 from the secondary surfaces immediately as VivaAuthError — no further retry.
|
|
232
|
+
*
|
|
233
|
+
* Note: if cancelOrder already succeeded on Viva's side before any 401 is
|
|
234
|
+
* observed, a 4xx from Viva on a subsequent attempt signals the order is
|
|
235
|
+
* already cancelled (idempotent). The fallback does NOT apply to non-401
|
|
236
|
+
* errors — those propagate as VivaApiError unchanged.
|
|
237
|
+
*
|
|
238
|
+
* @see references/viva-docs/md/payment-isv-api.txt:1
|
|
239
|
+
* @see references/viva-docs/md/webhooks-for-payments.txt:205 (4865 Order Updated)
|
|
240
|
+
* @see references/viva-docs/md/isv-credentials.txt:107 (reseller basic-auth)
|
|
241
|
+
* @see docs/plans/vendure-plugin-v0.md §D15 (reseller fallback scope)
|
|
242
|
+
*/
|
|
243
|
+
cancelOrder(orderCode: OrderCode, opts?: {
|
|
244
|
+
merchantId?: MerchantId;
|
|
245
|
+
}): Promise<CancelOrderResponse>;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/payments/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAC3B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACX,MAAM,mBAAmB,CAAC;AAwB3B;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;CACzC;AAuFD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4B;IAC5D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8B;gBAE/C,MAAM,EAAE,cAAc;IAOlC;;;;;;;;;;;;;;;;;;OAkBG;IACG,WAAW,CACf,GAAG,EAAE,kBAAkB,EACvB,IAAI,EAAE;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GACxD,OAAO,CAAC,mBAAmB,CAAC;IAsD/B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,mBAAmB,CACvB,aAAa,EAAE,aAAa,EAC5B,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,UAAU,CAAA;KAAO,GACrC,OAAO,CAAC,2BAA2B,CAAC;IAkFvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,GAAE;QAAE,UAAU,CAAC,EAAE,UAAU,CAAA;KAAO,GACrC,OAAO,CAAC,mBAAmB,CAAC;CAoChC"}
|