awesome-node-checkout 1.0.1 → 1.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +44 -10
  3. package/dist/abstract/base-payment-provider.abstract.d.ts +30 -0
  4. package/dist/abstract/base-payment-provider.abstract.d.ts.map +1 -0
  5. package/dist/abstract/base-payment-provider.abstract.js +28 -0
  6. package/dist/abstract/base-payment-provider.abstract.js.map +1 -0
  7. package/dist/adapters/express/index.d.ts +65 -0
  8. package/dist/adapters/express/index.d.ts.map +1 -0
  9. package/dist/adapters/express/index.js +176 -0
  10. package/dist/adapters/express/index.js.map +1 -0
  11. package/dist/checkout-configurator.d.ts +66 -0
  12. package/dist/checkout-configurator.d.ts.map +1 -0
  13. package/dist/checkout-configurator.js +148 -0
  14. package/dist/checkout-configurator.js.map +1 -0
  15. package/dist/events/checkout-event-bus.d.ts +29 -0
  16. package/dist/events/checkout-event-bus.d.ts.map +1 -0
  17. package/dist/events/checkout-event-bus.js +37 -0
  18. package/dist/events/checkout-event-bus.js.map +1 -0
  19. package/dist/index.d.ts +19 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +25 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/interfaces/payment-provider.interface.d.ts +33 -0
  24. package/dist/interfaces/payment-provider.interface.d.ts.map +1 -0
  25. package/dist/interfaces/payment-provider.interface.js +3 -0
  26. package/dist/interfaces/payment-provider.interface.js.map +1 -0
  27. package/dist/interfaces/transaction-store.interface.d.ts +24 -0
  28. package/dist/interfaces/transaction-store.interface.d.ts.map +1 -0
  29. package/dist/interfaces/transaction-store.interface.js +3 -0
  30. package/dist/interfaces/transaction-store.interface.js.map +1 -0
  31. package/dist/models/checkout-config.model.d.ts +12 -0
  32. package/dist/models/checkout-config.model.d.ts.map +1 -0
  33. package/dist/models/checkout-config.model.js +3 -0
  34. package/dist/models/checkout-config.model.js.map +1 -0
  35. package/dist/models/errors.d.ts +7 -0
  36. package/dist/models/errors.d.ts.map +1 -0
  37. package/dist/models/errors.js +17 -0
  38. package/dist/models/errors.js.map +1 -0
  39. package/dist/models/payment-request.model.d.ts +21 -0
  40. package/dist/models/payment-request.model.d.ts.map +1 -0
  41. package/dist/models/payment-request.model.js +3 -0
  42. package/dist/models/payment-request.model.js.map +1 -0
  43. package/dist/models/payment-result.model.d.ts +23 -0
  44. package/dist/models/payment-result.model.d.ts.map +1 -0
  45. package/dist/models/payment-result.model.js +3 -0
  46. package/dist/models/payment-result.model.js.map +1 -0
  47. package/dist/providers/nexi/nexi.provider.d.ts +64 -0
  48. package/dist/providers/nexi/nexi.provider.d.ts.map +1 -0
  49. package/dist/providers/nexi/nexi.provider.js +227 -0
  50. package/dist/providers/nexi/nexi.provider.js.map +1 -0
  51. package/dist/providers/paypal/paypal.provider.d.ts +33 -0
  52. package/dist/providers/paypal/paypal.provider.d.ts.map +1 -0
  53. package/dist/providers/paypal/paypal.provider.js +167 -0
  54. package/dist/providers/paypal/paypal.provider.js.map +1 -0
  55. package/dist/providers/satispay/satispay.provider.d.ts +79 -0
  56. package/dist/providers/satispay/satispay.provider.d.ts.map +1 -0
  57. package/dist/providers/satispay/satispay.provider.js +301 -0
  58. package/dist/providers/satispay/satispay.provider.js.map +1 -0
  59. package/dist/stores/in-memory-transaction.store.d.ts +17 -0
  60. package/dist/stores/in-memory-transaction.store.d.ts.map +1 -0
  61. package/dist/stores/in-memory-transaction.store.js +30 -0
  62. package/dist/stores/in-memory-transaction.store.js.map +1 -0
  63. package/package.json +12 -3
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.NexiProvider = void 0;
37
+ const crypto = __importStar(require("crypto"));
38
+ const base_payment_provider_abstract_1 = require("../../abstract/base-payment-provider.abstract");
39
+ /**
40
+ * Nexi eCommerce provider.
41
+ * Flow: `redirect` — builds a signed checkout URL, redirects the user to Nexi,
42
+ * then handles the POST-back via `handleRedirect`.
43
+ *
44
+ * Note: Nexi XPay mandates SHA-1 for MAC computation. This is a requirement of
45
+ * the Nexi API and cannot be changed on the client side.
46
+ */
47
+ class NexiProvider extends base_payment_provider_abstract_1.BasePaymentProvider {
48
+ constructor(config) {
49
+ super();
50
+ this.config = config;
51
+ this.name = 'nexi';
52
+ this.flow = 'redirect';
53
+ this.apiUrl =
54
+ config.environment === 'production'
55
+ ? 'https://ecommerce.nexi.it'
56
+ : 'https://int-ecommerce.nexi.it';
57
+ }
58
+ /**
59
+ * Computes the SHA-1 MAC required by Nexi to authenticate the payment request.
60
+ * Format: `codTrans={val}divisa={val}importo={val}{macKey}`
61
+ *
62
+ * SHA-1 is used here because Nexi XPay mandates it for MAC computation.
63
+ */
64
+ generateMac(codTrans, divisa, importoCents) {
65
+ const raw = `codTrans=${codTrans}divisa=${divisa}importo=${importoCents}${this.config.macKey}`;
66
+ return crypto.createHash('sha1').update(raw).digest('hex');
67
+ }
68
+ /**
69
+ * Computes the SHA-1 MAC for the status (getPaymentDetails) API call.
70
+ * Format: `alias={alias}codTrans={codTrans}timestamp={timestamp}{macKey}`
71
+ */
72
+ generateStatusMac(alias, codTrans, timestamp) {
73
+ const raw = `alias=${alias}codTrans=${codTrans}timestamp=${timestamp}${this.config.macKey}`;
74
+ return crypto.createHash('sha1').update(raw).digest('hex');
75
+ }
76
+ /**
77
+ * Computes the SHA-1 MAC for the refund (storno) API call.
78
+ * Format: `alias={alias}codTrans={codTrans}importo={importo}timestamp={timestamp}{macKey}`
79
+ */
80
+ generateRefundMac(alias, codTrans, importo, timestamp) {
81
+ const raw = `alias=${alias}codTrans=${codTrans}importo=${importo}timestamp=${timestamp}${this.config.macKey}`;
82
+ return crypto.createHash('sha1').update(raw).digest('hex');
83
+ }
84
+ /**
85
+ * Verifies the SHA-1 MAC included in a Nexi POST-back response.
86
+ * Format: `codTrans={val}esito={val}importo={val}divisa={val}{macKey}`
87
+ */
88
+ verifyResponseMac(codTrans, esito, importo, divisa, mac) {
89
+ const raw = `codTrans=${codTrans}esito=${esito}importo=${importo}divisa=${divisa}${this.config.macKey}`;
90
+ const expected = crypto.createHash('sha1').update(raw).digest('hex');
91
+ return crypto.timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(mac, 'hex'));
92
+ }
93
+ async createPayment(request) {
94
+ try {
95
+ const amountCents = Math.round(request.amount * 100);
96
+ const orderId = request.orderId ?? `ORD-${Date.now()}`;
97
+ const mac = this.generateMac(orderId, request.currency, amountCents);
98
+ const params = {
99
+ alias: this.config.merchantId,
100
+ importo: amountCents.toString(),
101
+ divisa: request.currency,
102
+ codTrans: orderId,
103
+ url: request.returnUrl,
104
+ url_back: request.cancelUrl,
105
+ mac,
106
+ };
107
+ if (this.config.group) {
108
+ params.gruppo = this.config.group;
109
+ }
110
+ const approvalUrl = `${this.apiUrl}/ecomm/ecomm/DispatcherServlet?${new URLSearchParams(params)}`;
111
+ return {
112
+ success: true,
113
+ paymentId: orderId,
114
+ approvalUrl,
115
+ status: 'CREATED',
116
+ };
117
+ }
118
+ catch (error) {
119
+ return this.errorResult(error, 'Failed to create Nexi payment');
120
+ }
121
+ }
122
+ /**
123
+ * Validates the POST-back data from Nexi.
124
+ * `data` is the query/body object sent by Nexi to the returnUrl.
125
+ * The MAC is verified before the result is considered authoritative.
126
+ */
127
+ async executePayment(paymentId, data) {
128
+ try {
129
+ const esito = data?.esito ?? '';
130
+ const codTrans = data?.codTrans ?? paymentId;
131
+ const importo = data?.importo ?? '';
132
+ const divisa = data?.divisa ?? '';
133
+ const mac = data?.mac ?? '';
134
+ if (mac) {
135
+ let macValid;
136
+ try {
137
+ macValid = this.verifyResponseMac(codTrans, esito, importo, divisa, mac);
138
+ }
139
+ catch {
140
+ macValid = false;
141
+ }
142
+ if (!macValid) {
143
+ return {
144
+ success: false,
145
+ paymentId: codTrans,
146
+ status: 'FAILED',
147
+ error: 'MAC verification failed: response may have been tampered with',
148
+ };
149
+ }
150
+ }
151
+ return {
152
+ success: esito === 'OK',
153
+ paymentId: codTrans,
154
+ status: esito === 'OK' ? 'COMPLETED' : 'FAILED',
155
+ raw: data,
156
+ };
157
+ }
158
+ catch (error) {
159
+ return this.errorResult(error, 'Failed to execute Nexi payment');
160
+ }
161
+ }
162
+ async getPaymentDetails(paymentId) {
163
+ try {
164
+ const timestamp = new Date().toISOString();
165
+ const mac = this.generateStatusMac(this.config.merchantId, paymentId, timestamp);
166
+ const params = {
167
+ alias: this.config.merchantId,
168
+ codTrans: paymentId,
169
+ timestamp,
170
+ mac,
171
+ };
172
+ const response = await fetch(`${this.apiUrl}/ecomm/api/vas/igfs/status/plain`, {
173
+ method: 'POST',
174
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
175
+ body: new URLSearchParams(params),
176
+ });
177
+ if (!response.ok)
178
+ throw new Error(`Nexi API error: ${response.statusText}`);
179
+ const result = await response.json();
180
+ return { success: true, paymentId, status: result['status'], raw: result };
181
+ }
182
+ catch (error) {
183
+ return this.errorResult(error, 'Failed to get Nexi payment details');
184
+ }
185
+ }
186
+ async refundPayment(paymentId, amount) {
187
+ try {
188
+ const timestamp = new Date().toISOString();
189
+ const importo = amount ? Math.round(amount * 100).toString() : '';
190
+ const mac = this.generateRefundMac(this.config.merchantId, paymentId, importo, timestamp);
191
+ const params = {
192
+ alias: this.config.merchantId,
193
+ codTrans: paymentId,
194
+ importo,
195
+ timestamp,
196
+ mac,
197
+ };
198
+ const response = await fetch(`${this.apiUrl}/ecomm/api/vas/igfs/storno/plain`, {
199
+ method: 'POST',
200
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
201
+ body: new URLSearchParams(params),
202
+ });
203
+ if (!response.ok)
204
+ throw new Error(`Nexi API error: ${response.statusText}`);
205
+ const result = await response.json();
206
+ return {
207
+ success: result['esito'] === 'OK',
208
+ paymentId,
209
+ status: result['esito'] === 'OK' ? 'REFUNDED' : 'REFUND_FAILED',
210
+ raw: result,
211
+ };
212
+ }
213
+ catch (error) {
214
+ return this.errorResult(error, 'Failed to refund Nexi payment');
215
+ }
216
+ }
217
+ /**
218
+ * Handles the POST-back from Nexi to the returnUrl.
219
+ * Nexi sends `esito`, `codTrans`, `importo`, `divisa`, `mac`, etc. as query/body params.
220
+ * The MAC is verified to ensure the response was not spoofed.
221
+ */
222
+ async handleRedirect(query) {
223
+ return this.executePayment(query['codTrans'] ?? '', query);
224
+ }
225
+ }
226
+ exports.NexiProvider = NexiProvider;
227
+ //# sourceMappingURL=nexi.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexi.provider.js","sourceRoot":"","sources":["../../../src/providers/nexi/nexi.provider.ts"],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,OAAO,CAAC,KAAK,IAAI;gBACjC,SAAS;gBACT,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,eAAe;gBAC/D,GAAG,EAAE,MAAM;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,+BAA+B,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc,CAAC,KAA6B;QAChD,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;CACF;AA/MD,oCA+MC"}
@@ -0,0 +1,33 @@
1
+ import { BasePaymentProvider } from '../../abstract/base-payment-provider.abstract';
2
+ import { PaymentRequest } from '../../models/payment-request.model';
3
+ import { PaymentResult } from '../../models/payment-result.model';
4
+ export interface PayPalProviderConfig {
5
+ clientId: string;
6
+ clientSecret: string;
7
+ /** @default 'sandbox' */
8
+ environment?: 'sandbox' | 'live';
9
+ }
10
+ /**
11
+ * PayPal Checkout provider.
12
+ * Flow: `redirect` — creates an order, redirects the user to PayPal,
13
+ * then captures the payment on return via `handleRedirect`.
14
+ */
15
+ export declare class PayPalProvider extends BasePaymentProvider {
16
+ private readonly config;
17
+ readonly name = "paypal";
18
+ readonly flow: "redirect";
19
+ private client;
20
+ private ordersController;
21
+ private paymentsController;
22
+ constructor(config: PayPalProviderConfig);
23
+ createPayment(request: PaymentRequest): Promise<PaymentResult>;
24
+ executePayment(paymentId: string): Promise<PaymentResult>;
25
+ getPaymentDetails(paymentId: string): Promise<PaymentResult>;
26
+ refundPayment(paymentId: string, amount?: number): Promise<PaymentResult>;
27
+ /**
28
+ * Handles the redirect from PayPal after the user approves the payment.
29
+ * PayPal appends `token` (order ID) and `PayerID` to the returnUrl.
30
+ */
31
+ handleRedirect(query: Record<string, string>): Promise<PaymentResult>;
32
+ }
33
+ //# sourceMappingURL=paypal.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paypal.provider.d.ts","sourceRoot":"","sources":["../../../src/providers/paypal/paypal.provider.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAClC;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,mBAAmB;IAQzC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPnC,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,IAAI,EAAG,UAAU,CAAU;IAEpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,kBAAkB,CAAqB;gBAElB,MAAM,EAAE,oBAAoB;IAoBnD,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA0C9D,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBzD,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAiB5D,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAuD/E;;;OAGG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;CAU5E"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayPalProvider = void 0;
4
+ const paypal_server_sdk_1 = require("@paypal/paypal-server-sdk");
5
+ const base_payment_provider_abstract_1 = require("../../abstract/base-payment-provider.abstract");
6
+ /**
7
+ * PayPal Checkout provider.
8
+ * Flow: `redirect` — creates an order, redirects the user to PayPal,
9
+ * then captures the payment on return via `handleRedirect`.
10
+ */
11
+ class PayPalProvider extends base_payment_provider_abstract_1.BasePaymentProvider {
12
+ constructor(config) {
13
+ super();
14
+ this.config = config;
15
+ this.name = 'paypal';
16
+ this.flow = 'redirect';
17
+ const { clientId, clientSecret, environment = 'sandbox' } = config;
18
+ this.client = new paypal_server_sdk_1.Client({
19
+ clientCredentialsAuthCredentials: {
20
+ oAuthClientId: clientId,
21
+ oAuthClientSecret: clientSecret,
22
+ },
23
+ environment: environment === 'live' ? paypal_server_sdk_1.Environment.Production : paypal_server_sdk_1.Environment.Sandbox,
24
+ logging: {
25
+ logLevel: paypal_server_sdk_1.LogLevel.Error,
26
+ },
27
+ });
28
+ this.ordersController = new paypal_server_sdk_1.OrdersController(this.client);
29
+ this.paymentsController = new paypal_server_sdk_1.PaymentsController(this.client);
30
+ }
31
+ async createPayment(request) {
32
+ try {
33
+ const { result: order } = await this.ordersController.createOrder({
34
+ body: {
35
+ intent: 'CAPTURE',
36
+ purchaseUnits: [
37
+ {
38
+ amount: {
39
+ currencyCode: request.currency,
40
+ value: request.amount.toFixed(2),
41
+ },
42
+ description: request.description,
43
+ },
44
+ ],
45
+ paymentSource: {
46
+ paypal: {
47
+ experienceContext: {
48
+ returnUrl: request.returnUrl,
49
+ cancelUrl: request.cancelUrl,
50
+ },
51
+ },
52
+ },
53
+ },
54
+ prefer: 'return=representation',
55
+ });
56
+ const approvalUrl = order.links?.find((l) => l.rel === 'payer-action' || l.rel === 'approve')?.href;
57
+ return {
58
+ success: true,
59
+ paymentId: order.id,
60
+ approvalUrl,
61
+ status: order.status,
62
+ raw: order,
63
+ };
64
+ }
65
+ catch (error) {
66
+ return this.errorResult(error, 'Failed to create PayPal payment');
67
+ }
68
+ }
69
+ async executePayment(paymentId) {
70
+ try {
71
+ const { result: order } = await this.ordersController.captureOrder({
72
+ id: paymentId,
73
+ body: {},
74
+ });
75
+ return {
76
+ success: order.status === 'COMPLETED',
77
+ paymentId: order.id,
78
+ status: order.status,
79
+ raw: order,
80
+ };
81
+ }
82
+ catch (error) {
83
+ return this.errorResult(error, 'Failed to execute PayPal payment');
84
+ }
85
+ }
86
+ async getPaymentDetails(paymentId) {
87
+ try {
88
+ const { result: order } = await this.ordersController.getOrder({
89
+ id: paymentId,
90
+ });
91
+ return {
92
+ success: true,
93
+ paymentId: order.id,
94
+ status: order.status,
95
+ raw: order,
96
+ };
97
+ }
98
+ catch (error) {
99
+ return this.errorResult(error, 'Failed to get PayPal payment details');
100
+ }
101
+ }
102
+ async refundPayment(paymentId, amount) {
103
+ try {
104
+ // Retrieve order to find the capture ID and currency
105
+ const { result: order } = await this.ordersController.getOrder({ id: paymentId });
106
+ // The PayPal SDK types nested objects as `any`; extract with explicit guards
107
+ const purchaseUnit = Array.isArray(order?.purchaseUnits)
108
+ ? order.purchaseUnits[0]
109
+ : undefined;
110
+ const captureId = Array.isArray(purchaseUnit?.payments?.captures) && purchaseUnit.payments.captures.length > 0
111
+ ? String(purchaseUnit.payments.captures[0].id)
112
+ : undefined;
113
+ if (!captureId) {
114
+ return {
115
+ success: false,
116
+ error: 'No capture found for this order. Ensure the payment has been captured before refunding.',
117
+ paymentId,
118
+ status: 'REFUND_FAILED',
119
+ };
120
+ }
121
+ const refundBody = {};
122
+ if (amount !== undefined) {
123
+ const currencyCode = typeof purchaseUnit?.amount?.currencyCode === 'string'
124
+ ? purchaseUnit.amount.currencyCode
125
+ : undefined;
126
+ if (!currencyCode) {
127
+ return {
128
+ success: false,
129
+ error: 'Cannot determine currency code from order. Refund a specific amount is not possible.',
130
+ paymentId,
131
+ status: 'REFUND_FAILED',
132
+ };
133
+ }
134
+ refundBody['amount'] = { value: amount.toFixed(2), currencyCode };
135
+ }
136
+ const { result: refund } = await this.paymentsController.refundCapturedPayment({
137
+ captureId,
138
+ body: refundBody,
139
+ });
140
+ return {
141
+ success: refund?.status === 'COMPLETED',
142
+ paymentId: String(refund?.id ?? ''),
143
+ status: String(refund?.status ?? ''),
144
+ raw: refund,
145
+ };
146
+ }
147
+ catch (error) {
148
+ return this.errorResult(error, 'Failed to refund PayPal payment');
149
+ }
150
+ }
151
+ /**
152
+ * Handles the redirect from PayPal after the user approves the payment.
153
+ * PayPal appends `token` (order ID) and `PayerID` to the returnUrl.
154
+ */
155
+ async handleRedirect(query) {
156
+ const paymentId = query['token'];
157
+ if (!paymentId) {
158
+ return {
159
+ success: false,
160
+ error: 'Missing token in PayPal redirect query',
161
+ };
162
+ }
163
+ return this.executePayment(paymentId);
164
+ }
165
+ }
166
+ exports.PayPalProvider = PayPalProvider;
167
+ //# sourceMappingURL=paypal.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paypal.provider.js","sourceRoot":"","sources":["../../../src/providers/paypal/paypal.provider.ts"],"names":[],"mappings":";;;AAAA,iEAMmC;AACnC,kGAAoF;AAWpF;;;;GAIG;AACH,MAAa,cAAe,SAAQ,oDAAmB;IAQrD,YAA6B,MAA4B;QACvD,KAAK,EAAE,CAAC;QADmB,WAAM,GAAN,MAAM,CAAsB;QAPhD,SAAI,GAAG,QAAQ,CAAC;QAChB,SAAI,GAAG,UAAmB,CAAC;QAQlC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,GAAG,SAAS,EAAE,GAAG,MAAM,CAAC;QAEnE,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAM,CAAC;YACvB,gCAAgC,EAAE;gBAChC,aAAa,EAAE,QAAQ;gBACvB,iBAAiB,EAAE,YAAY;aAChC;YACD,WAAW,EACT,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,+BAAW,CAAC,UAAU,CAAC,CA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E,CAAC;YACpE,CAAC;YAED,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,qBAAqB,CAAC;gBAC7E,SAAS;gBACT,IAAI,EAAE,UAAiB;aACxB,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAG,MAAc,EAAE,MAAM,KAAK,WAAW;gBAChD,SAAS,EAAE,MAAM,CAAE,MAAc,EAAE,EAAE,IAAI,EAAE,CAAC;gBAC5C,MAAM,EAAE,MAAM,CAAE,MAAc,EAAE,MAAM,IAAI,EAAE,CAAC;gBAC7C,GAAG,EAAE,MAAM;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,iCAAiC,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CAAC,KAA6B;QAChD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,wCAAwC;aAChD,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AA9KD,wCA8KC"}
@@ -0,0 +1,79 @@
1
+ import { BasePaymentProvider } from '../../abstract/base-payment-provider.abstract';
2
+ import { PaymentRequest } from '../../models/payment-request.model';
3
+ import { PaymentResult, WebhookResult } from '../../models/payment-result.model';
4
+ import { ITransactionStore } from '../../interfaces/transaction-store.interface';
5
+ export interface SatispayProviderConfig {
6
+ keyId: string;
7
+ /**
8
+ * RSA private key in PEM format (string content, not a file path).
9
+ * Load with: `fs.readFileSync('private.pem', 'utf8')`
10
+ */
11
+ privateKey: string;
12
+ /**
13
+ * Satispay RSA public key in PEM format, used to verify incoming webhook
14
+ * HTTP Signatures. Obtain it by calling GET /g_business/v1/consumers/{keyId}
15
+ * on Satispay's API for the keyId present in the webhook Authorization header.
16
+ * When provided, every inbound webhook whose signature cannot be verified is
17
+ * rejected before any business logic is executed.
18
+ */
19
+ webhookPublicKey?: string;
20
+ /** @default 'sandbox' */
21
+ environment?: 'sandbox' | 'production';
22
+ /**
23
+ * Base URL of the host application.
24
+ * Used to build the `callback_url` sent to Satispay.
25
+ * Example: 'https://myapp.com'
26
+ */
27
+ serverUrl?: string;
28
+ /**
29
+ * Custom transaction store for correlating webhooks with orders.
30
+ * Defaults to InMemoryTransactionStore.
31
+ * Use a persistent store (Redis, DB) in multi-instance deployments.
32
+ */
33
+ transactionStore?: ITransactionStore;
34
+ }
35
+ /**
36
+ * Satispay Business API provider.
37
+ * Flow: `webhook` — creates a MATCH_CODE payment, user pays via Satispay app,
38
+ * Satispay calls the `callback_url` webhook, which is correlated to the order
39
+ * via the `ITransactionStore`. The redirect is then verified via `handleRedirect`.
40
+ */
41
+ export declare class SatispayProvider extends BasePaymentProvider {
42
+ private readonly config;
43
+ readonly name = "satispay";
44
+ readonly flow: "webhook";
45
+ private readonly apiUrl;
46
+ private readonly transactionStore;
47
+ constructor(config: SatispayProviderConfig);
48
+ private buildSignatureHeaders;
49
+ /**
50
+ * Verifies the HTTP Signature in an inbound Satispay webhook request.
51
+ * Satispay signs webhooks with their own RSA private key; we verify using
52
+ * the corresponding public key supplied in `config.webhookPublicKey`.
53
+ *
54
+ * Returns `true` if the signature is valid, `false` otherwise.
55
+ * If no `webhookPublicKey` is configured the check is skipped and `true`
56
+ * is returned — callers should treat this as an unverified state.
57
+ */
58
+ private verifyWebhookSignature;
59
+ private request;
60
+ createPayment(request: PaymentRequest): Promise<PaymentResult>;
61
+ /** For Satispay, execute is equivalent to a status check */
62
+ executePayment(paymentId: string): Promise<PaymentResult>;
63
+ getPaymentDetails(paymentId: string): Promise<PaymentResult>;
64
+ refundPayment(paymentId: string, amount?: number): Promise<PaymentResult>;
65
+ /**
66
+ * Handles the async webhook notification from Satispay.
67
+ * Satispay calls this URL with `payment_id` (the Satispay payment UUID).
68
+ * The HTTP Signature in the Authorization header is verified against
69
+ * `config.webhookPublicKey` (when configured) before processing.
70
+ * We then confirm the payment status via an authenticated API call.
71
+ */
72
+ handleWebhook(body: Record<string, unknown>, headers: Record<string, string>): Promise<WebhookResult>;
73
+ /**
74
+ * Handles the redirect back to the merchant app after the Satispay flow.
75
+ * Looks up the transaction by `order_id` in the store, then verifies status.
76
+ */
77
+ handleRedirect(query: Record<string, string>): Promise<PaymentResult>;
78
+ }
79
+ //# sourceMappingURL=satispay.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"satispay.provider.d.ts","sourceRoot":"","sources":["../../../src/providers/satispay/satispay.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAGjF,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB;IACzB,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACvC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;CACtC;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,mBAAmB;IAO3C,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnC,QAAQ,CAAC,IAAI,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAU;IAEnC,OAAO,CAAC,QAAQ,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