awesome-node-checkout 1.3.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +335 -17
- package/dist/adapters/express/index.d.ts +103 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +213 -30
- package/dist/adapters/express/index.js.map +1 -1
- package/dist/checkout-configurator.d.ts +106 -0
- package/dist/checkout-configurator.d.ts.map +1 -1
- package/dist/checkout-configurator.js +515 -0
- package/dist/checkout-configurator.js.map +1 -1
- package/dist/events/checkout-event-bus.d.ts +11 -1
- package/dist/events/checkout-event-bus.d.ts.map +1 -1
- package/dist/events/checkout-event-bus.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/mandate-provider.interface.d.ts +40 -0
- package/dist/interfaces/mandate-provider.interface.d.ts.map +1 -0
- package/dist/interfaces/mandate-provider.interface.js +18 -0
- package/dist/interfaces/mandate-provider.interface.js.map +1 -0
- package/dist/models/checkout-config.model.d.ts +16 -0
- package/dist/models/checkout-config.model.d.ts.map +1 -1
- package/dist/models/errors.d.ts +1 -1
- package/dist/models/errors.d.ts.map +1 -1
- package/dist/models/errors.js.map +1 -1
- package/dist/models/mandate.model.d.ts +166 -0
- package/dist/models/mandate.model.d.ts.map +1 -0
- package/dist/models/mandate.model.js +19 -0
- package/dist/models/mandate.model.js.map +1 -0
- package/dist/providers/nexi/nexi.provider.d.ts +125 -1
- package/dist/providers/nexi/nexi.provider.d.ts.map +1 -1
- package/dist/providers/nexi/nexi.provider.js +677 -13
- package/dist/providers/nexi/nexi.provider.js.map +1 -1
- package/dist/providers/paypal/paypal.provider.d.ts +44 -1
- package/dist/providers/paypal/paypal.provider.d.ts.map +1 -1
- package/dist/providers/paypal/paypal.provider.js +529 -2
- package/dist/providers/paypal/paypal.provider.js.map +1 -1
- package/dist/providers/satispay/satispay.provider.d.ts +86 -1
- package/dist/providers/satispay/satispay.provider.d.ts.map +1 -1
- package/dist/providers/satispay/satispay.provider.js +440 -3
- package/dist/providers/satispay/satispay.provider.js.map +1 -1
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -0
- package/dist/utils/ids.js +16 -0
- package/dist/utils/ids.js.map +1 -0
- package/dist/utils/money.d.ts +20 -0
- package/dist/utils/money.d.ts.map +1 -0
- package/dist/utils/money.js +68 -0
- package/dist/utils/money.js.map +1 -0
- package/dist/utils/redact.d.ts +15 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/dist/utils/redact.js +60 -0
- package/dist/utils/redact.js.map +1 -0
- package/dist/utils/url.d.ts +12 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +19 -0
- package/dist/utils/url.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BasePaymentProvider } from '../../abstract/base-payment-provider.abstract';
|
|
2
2
|
import { PaymentRequest } from '../../models/payment-request.model';
|
|
3
3
|
import { PaymentResult, WebhookResult } from '../../models/payment-result.model';
|
|
4
|
+
import { IMandateProvider } from '../../interfaces/mandate-provider.interface';
|
|
5
|
+
import { ChargeRequest, ChargeResult, Mandate, MandateCallbackInput, MandatePendingState, MandateRevokeResult, MandateSetupOutcome, MandateSetupRequest, MandateSetupStart, MandateStatusResult } from '../../models/mandate.model';
|
|
4
6
|
export interface NexiProviderConfig {
|
|
5
7
|
merchantId: string;
|
|
6
8
|
macKey: string;
|
|
@@ -8,20 +10,37 @@ export interface NexiProviderConfig {
|
|
|
8
10
|
group?: string;
|
|
9
11
|
/** @default 'sandbox' */
|
|
10
12
|
environment?: 'sandbox' | 'production';
|
|
13
|
+
/**
|
|
14
|
+
* Timeout of the recurring-payment and contract API calls (`pagamentoRicorrente`,
|
|
15
|
+
* `situazioneOrdine` replay guard, `dettagliContratto`, `cancellaContratto`), in ms.
|
|
16
|
+
* @default 30000
|
|
17
|
+
*/
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Mandates: contract type sent as `tipo_contratto` at setup (`S` scheduled, `U` unscheduled) and
|
|
21
|
+
* included in the setup MAC. Only needed when the terminal is enabled for both kinds.
|
|
22
|
+
*/
|
|
23
|
+
contractType?: 'S' | 'U';
|
|
11
24
|
}
|
|
12
25
|
/**
|
|
13
26
|
* Nexi eCommerce provider.
|
|
14
27
|
* Flow: `redirect` — builds a signed checkout URL, redirects the user to Nexi,
|
|
15
28
|
* then handles the POST-back via `handleRedirect`.
|
|
16
29
|
*
|
|
30
|
+
* Recurring payments (`IMandateProvider`): the setup is a hosted-page first payment that
|
|
31
|
+
* registers a contract (`num_contratto` = `mandateRef`, `tipo_servizio=paga_multi`,
|
|
32
|
+
* `tipo_richiesta=PP`); later charges use `pagamentoRicorrente`; `cancellaContratto` revokes.
|
|
33
|
+
* EUR only. See "Specifiche tecniche di integrazione con il gateway di pagamento XPay" v20.4.
|
|
34
|
+
*
|
|
17
35
|
* Note: Nexi XPay mandates SHA-1 for MAC computation. This is a requirement of
|
|
18
36
|
* the Nexi API and cannot be changed on the client side.
|
|
19
37
|
*/
|
|
20
|
-
export declare class NexiProvider extends BasePaymentProvider {
|
|
38
|
+
export declare class NexiProvider extends BasePaymentProvider implements IMandateProvider {
|
|
21
39
|
private readonly config;
|
|
22
40
|
readonly name = "nexi";
|
|
23
41
|
readonly flow: "redirect";
|
|
24
42
|
private readonly apiUrl;
|
|
43
|
+
private readonly timeoutMs;
|
|
25
44
|
constructor(config: NexiProviderConfig);
|
|
26
45
|
/**
|
|
27
46
|
* Computes the SHA-1 MAC required by Nexi to authenticate the payment request.
|
|
@@ -58,6 +77,57 @@ export declare class NexiProvider extends BasePaymentProvider {
|
|
|
58
77
|
*/
|
|
59
78
|
private verifyResponseMac;
|
|
60
79
|
private safeVerifyResponseMac;
|
|
80
|
+
/**
|
|
81
|
+
* Extracts the fields of a hosted-page outcome (redirect query or `urlpost` form). Missing
|
|
82
|
+
* fields are `''`; `codTrans` falls back to `fallbackCodTrans` when given. `mac` is returned as
|
|
83
|
+
* is, to be checked with `isValidHexMac`.
|
|
84
|
+
*/
|
|
85
|
+
private extractOutcomeFields;
|
|
86
|
+
/** True when the 7-field outcome MAC of `fields` is present and valid (constant time). */
|
|
87
|
+
private outcomeMacValid;
|
|
88
|
+
/** Constant-time comparison of a hex MAC against the expected SHA-1 hex digest. */
|
|
89
|
+
private hexMacEquals;
|
|
90
|
+
/**
|
|
91
|
+
* Verifies the standard XPay REST response MAC:
|
|
92
|
+
* `esito={esito}idOperazione={idOperazione}timeStamp={timeStamp}{macKey}`.
|
|
93
|
+
*/
|
|
94
|
+
private responseMacValid;
|
|
95
|
+
/**
|
|
96
|
+
* MAC policy of the recurring and contract APIs: a present `mac` must be valid whatever the
|
|
97
|
+
* `esito`; a missing one is tolerated only on `KO` (an error answer may carry none).
|
|
98
|
+
*/
|
|
99
|
+
private responseAuthentic;
|
|
100
|
+
/**
|
|
101
|
+
* Classifies a "Tabella Codici errore API Restful" code (pp. 883-885). A missing or
|
|
102
|
+
* non-numeric code is `merchant`: without a code nothing says the customer is at fault.
|
|
103
|
+
*/
|
|
104
|
+
private classifyApiError;
|
|
105
|
+
/** `errore.codice` / `errore.messaggio` of a response, when present. */
|
|
106
|
+
private apiError;
|
|
107
|
+
/**
|
|
108
|
+
* Computes the MAC of `pagamentoRicorrente` (p. 191). `scadenza` is not sent, so it is in the
|
|
109
|
+
* string with an empty value, as the manual requires:
|
|
110
|
+
* `apiKey=…numeroContratto=…codiceTransazione=…importo=…divisa=978scadenza=timeStamp=…{macKey}`.
|
|
111
|
+
*/
|
|
112
|
+
private generateRecurringMac;
|
|
113
|
+
/**
|
|
114
|
+
* POSTs a JSON body to an XPay REST endpoint with the configured timeout. Never throws; the
|
|
115
|
+
* error never contains the response body.
|
|
116
|
+
*/
|
|
117
|
+
private postApi;
|
|
118
|
+
/**
|
|
119
|
+
* Reads `situazioneOrdine` for `codTrans` (same request as `getPaymentDetails`) and classifies
|
|
120
|
+
* the raw response, over every report entry for `codTrans`:
|
|
121
|
+
* - `paid`: some entry shows the money was taken (`NEXI_CHARGED_STATUSES`: paid, partly captured,
|
|
122
|
+
* refunded or partly refunded);
|
|
123
|
+
* - `pending`: otherwise, some entry is in progress (`In Corso`), has an unrecognised `stato`, or
|
|
124
|
+
* has none. Fail safe: such a code may still be charged, so it is never reported as refused;
|
|
125
|
+
* - `refused`: every entry is a clear refusal (`Negato`, `Annullato`, `Non Creato`);
|
|
126
|
+
* - `absent`: OK with no matching report entry, or KO "not found" 2/13;
|
|
127
|
+
* - `error`: anything else (HTTP, network, timeout, non-JSON, bad MAC, a missing MAC on OK, no
|
|
128
|
+
* `report` array, any other KO).
|
|
129
|
+
*/
|
|
130
|
+
private lookupTransaction;
|
|
61
131
|
createPayment(request: PaymentRequest): Promise<PaymentResult>;
|
|
62
132
|
/**
|
|
63
133
|
* Validates the POST-back data from Nexi.
|
|
@@ -81,5 +151,59 @@ export declare class NexiProvider extends BasePaymentProvider {
|
|
|
81
151
|
* The outcome MAC is mandatory and verified over all 7 fields to ensure authenticity.
|
|
82
152
|
*/
|
|
83
153
|
handleRedirect(query: Record<string, string>): Promise<PaymentResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Starts a contract registration: a hosted-page first payment with `num_contratto` =
|
|
156
|
+
* `mandateRef`, `tipo_servizio=paga_multi`, `tipo_richiesta=PP` (pp. 59-65), charging the first
|
|
157
|
+
* period. `codTrans` is `orderId`. EUR only. `mandate_ref` is appended to `url`, `url_back` and
|
|
158
|
+
* `urlpost`.
|
|
159
|
+
*/
|
|
160
|
+
createMandate(request: MandateSetupRequest): Promise<MandateSetupStart>;
|
|
161
|
+
/**
|
|
162
|
+
* Confirms a setup from the hosted-page outcome: the redirect on `url` (GET query) or the
|
|
163
|
+
* `urlpost` notification (form POST). Pure function of its inputs, hence idempotent.
|
|
164
|
+
*
|
|
165
|
+
* - The 7-field outcome MAC must be valid, and the MAC-covered `codTrans`, `importo` and
|
|
166
|
+
* `divisa` must match `pending`; otherwise the outcome is unverified and non-terminal (a forged
|
|
167
|
+
* callback never consumes the pending state). The unsigned `num_contratto`, when present, must
|
|
168
|
+
* be `pending.mandateRef` (and `tipo_servizio` / `tipo_richiesta`, when present, `paga_multi` /
|
|
169
|
+
* `PP`); the contract number used is always `pending.mandateRef`.
|
|
170
|
+
* - `esito=OK` with `num_contratto`: active mandate, first charge `succeeded` (terminal). An OK
|
|
171
|
+
* without `num_contratto` is unverified and non-terminal (no contract may exist).
|
|
172
|
+
* - `esito` `KO`, `ANNULLO` or `ERRORE`: no mandate, first charge `failed` (terminal). Start a
|
|
173
|
+
* new setup with a fresh `mandateRef` and `orderId`: a `codTrans` is never reused. This
|
|
174
|
+
* requires a terminal that allows a single payment attempt per `codTrans`: on a terminal
|
|
175
|
+
* configured for up to 3 attempts (manual, pp. 32-33), a KO then an OK arrive for the same
|
|
176
|
+
* `codTrans`, and the OK finds the pending state already consumed.
|
|
177
|
+
* - Any other `esito` (e.g. a pending one) is unverified and non-terminal: it may still turn OK.
|
|
178
|
+
*
|
|
179
|
+
* An empty input (`{}`) has no MAC, so a re-confirm is unverified and non-terminal: Nexi never
|
|
180
|
+
* reports a terminal outcome with an `unknown` first charge.
|
|
181
|
+
*/
|
|
182
|
+
confirmMandate(pending: MandatePendingState, input: MandateCallbackInput): Promise<MandateSetupOutcome>;
|
|
183
|
+
/**
|
|
184
|
+
* Merchant-initiated charge with `pagamentoRicorrente` (pp. 188-193), EUR only.
|
|
185
|
+
* `codiceTransazione` is `charge.chargeRef`, so `refundPayment(chargeRef, amount)` refunds it.
|
|
186
|
+
*
|
|
187
|
+
* Replay guard: `situazioneOrdine` is read first. A transaction that took the money (paid,
|
|
188
|
+
* partly captured, refunded or partly refunded) is returned as `succeeded` without charging
|
|
189
|
+
* again, with its `stato` in `raw`; one that only Nexi refused (`Negato`, `Annullato`,
|
|
190
|
+
* `Non Creato`) is `failed` (a dunning retry needs a new `chargeRef`: Nexi's own retries of a
|
|
191
|
+
* code after a KO are not used); one still in progress (`In Corso`) or with an unrecognised
|
|
192
|
+
* `stato` is `unknown`, and so is a lookup error: nothing is charged. A Nexi "transaction
|
|
193
|
+
* already present" (9) is re-read.
|
|
194
|
+
* Merchant-side errors (credentials, MAC, technical) are `unknown`, never `failed`.
|
|
195
|
+
*/
|
|
196
|
+
chargeMandate(mandate: Mandate, charge: ChargeRequest): Promise<ChargeResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Re-reads the contract with `dettagliContratto` (pp. 851-853). `active` when it is listed and
|
|
199
|
+
* its first payment is not KO; `revoked` when its first payment is KO or Nexi answers "not
|
|
200
|
+
* found" or "invalid contract"; otherwise `unknown` (unverified).
|
|
201
|
+
*/
|
|
202
|
+
getMandate(mandate: Mandate): Promise<MandateStatusResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Cancels the contract with `cancellaContratto` (pp. 838-840). "Not found" and "invalid
|
|
205
|
+
* contract" count as revoked: the contract is already gone.
|
|
206
|
+
*/
|
|
207
|
+
revokeMandate(mandate: Mandate): Promise<MandateRevokeResult>;
|
|
84
208
|
}
|
|
85
209
|
//# sourceMappingURL=nexi.provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nexi.provider.d.ts","sourceRoot":"","sources":["../../../src/providers/nexi/nexi.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"nexi.provider.d.ts","sourceRoot":"","sources":["../../../src/providers/nexi/nexi.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAGpF,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;A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