awesome-node-checkout 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/abstract/base-payment-provider.abstract.d.ts +30 -0
  2. package/dist/abstract/base-payment-provider.abstract.d.ts.map +1 -0
  3. package/dist/abstract/base-payment-provider.abstract.js +28 -0
  4. package/dist/abstract/base-payment-provider.abstract.js.map +1 -0
  5. package/dist/adapters/express/index.d.ts +35 -0
  6. package/dist/adapters/express/index.d.ts.map +1 -0
  7. package/dist/adapters/express/index.js +129 -0
  8. package/dist/adapters/express/index.js.map +1 -0
  9. package/dist/checkout-configurator.d.ts +66 -0
  10. package/dist/checkout-configurator.d.ts.map +1 -0
  11. package/dist/checkout-configurator.js +148 -0
  12. package/dist/checkout-configurator.js.map +1 -0
  13. package/dist/events/checkout-event-bus.d.ts +29 -0
  14. package/dist/events/checkout-event-bus.d.ts.map +1 -0
  15. package/dist/events/checkout-event-bus.js +37 -0
  16. package/dist/events/checkout-event-bus.js.map +1 -0
  17. package/dist/index.d.ts +19 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +25 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/interfaces/payment-provider.interface.d.ts +33 -0
  22. package/dist/interfaces/payment-provider.interface.d.ts.map +1 -0
  23. package/dist/interfaces/payment-provider.interface.js +3 -0
  24. package/dist/interfaces/payment-provider.interface.js.map +1 -0
  25. package/dist/interfaces/transaction-store.interface.d.ts +24 -0
  26. package/dist/interfaces/transaction-store.interface.d.ts.map +1 -0
  27. package/dist/interfaces/transaction-store.interface.js +3 -0
  28. package/dist/interfaces/transaction-store.interface.js.map +1 -0
  29. package/dist/models/checkout-config.model.d.ts +12 -0
  30. package/dist/models/checkout-config.model.d.ts.map +1 -0
  31. package/dist/models/checkout-config.model.js +3 -0
  32. package/dist/models/checkout-config.model.js.map +1 -0
  33. package/dist/models/errors.d.ts +7 -0
  34. package/dist/models/errors.d.ts.map +1 -0
  35. package/dist/models/errors.js +17 -0
  36. package/dist/models/errors.js.map +1 -0
  37. package/dist/models/payment-request.model.d.ts +21 -0
  38. package/dist/models/payment-request.model.d.ts.map +1 -0
  39. package/dist/models/payment-request.model.js +3 -0
  40. package/dist/models/payment-request.model.js.map +1 -0
  41. package/dist/models/payment-result.model.d.ts +23 -0
  42. package/dist/models/payment-result.model.d.ts.map +1 -0
  43. package/dist/models/payment-result.model.js +3 -0
  44. package/dist/models/payment-result.model.js.map +1 -0
  45. package/dist/providers/nexi/nexi.provider.d.ts +64 -0
  46. package/dist/providers/nexi/nexi.provider.d.ts.map +1 -0
  47. package/dist/providers/nexi/nexi.provider.js +227 -0
  48. package/dist/providers/nexi/nexi.provider.js.map +1 -0
  49. package/dist/providers/paypal/paypal.provider.d.ts +33 -0
  50. package/dist/providers/paypal/paypal.provider.d.ts.map +1 -0
  51. package/dist/providers/paypal/paypal.provider.js +167 -0
  52. package/dist/providers/paypal/paypal.provider.js.map +1 -0
  53. package/dist/providers/satispay/satispay.provider.d.ts +79 -0
  54. package/dist/providers/satispay/satispay.provider.d.ts.map +1 -0
  55. package/dist/providers/satispay/satispay.provider.js +301 -0
  56. package/dist/providers/satispay/satispay.provider.js.map +1 -0
  57. package/dist/stores/in-memory-transaction.store.d.ts +17 -0
  58. package/dist/stores/in-memory-transaction.store.d.ts.map +1 -0
  59. package/dist/stores/in-memory-transaction.store.js +30 -0
  60. package/dist/stores/in-memory-transaction.store.js.map +1 -0
  61. package/package.json +2 -2
@@ -0,0 +1,30 @@
1
+ import { IPaymentProvider, PaymentFlow } from '../interfaces/payment-provider.interface';
2
+ import { PaymentRequest } from '../models/payment-request.model';
3
+ import { PaymentResult } from '../models/payment-result.model';
4
+ /**
5
+ * Convenience base class for building custom payment providers.
6
+ * Provides the `errorResult` helper to normalize error handling.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * export class MyProvider extends BasePaymentProvider {
11
+ * readonly name = 'myprovider';
12
+ * readonly flow = 'redirect' as const;
13
+ * // ... implement abstract methods
14
+ * }
15
+ * ```
16
+ */
17
+ export declare abstract class BasePaymentProvider implements IPaymentProvider {
18
+ abstract readonly name: string;
19
+ abstract readonly flow: PaymentFlow;
20
+ abstract createPayment(request: PaymentRequest): Promise<PaymentResult>;
21
+ abstract executePayment(paymentId: string, data?: Record<string, string>): Promise<PaymentResult>;
22
+ abstract getPaymentDetails(paymentId: string): Promise<PaymentResult>;
23
+ abstract refundPayment(paymentId: string, amount?: number): Promise<PaymentResult>;
24
+ /**
25
+ * Helper to produce a normalized error PaymentResult.
26
+ * Extracts message from Error instances automatically.
27
+ */
28
+ protected errorResult(error: unknown, fallback?: string): PaymentResult;
29
+ }
30
+ //# sourceMappingURL=base-payment-provider.abstract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-payment-provider.abstract.d.ts","sourceRoot":"","sources":["../../src/abstract/base-payment-provider.abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,8BAAsB,mBAAoB,YAAW,gBAAgB;IACnE,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAEpC,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IACvE,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IACjG,QAAQ,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACrE,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAElF;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAkB,GAAG,aAAa;CAIjF"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePaymentProvider = void 0;
4
+ /**
5
+ * Convenience base class for building custom payment providers.
6
+ * Provides the `errorResult` helper to normalize error handling.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * export class MyProvider extends BasePaymentProvider {
11
+ * readonly name = 'myprovider';
12
+ * readonly flow = 'redirect' as const;
13
+ * // ... implement abstract methods
14
+ * }
15
+ * ```
16
+ */
17
+ class BasePaymentProvider {
18
+ /**
19
+ * Helper to produce a normalized error PaymentResult.
20
+ * Extracts message from Error instances automatically.
21
+ */
22
+ errorResult(error, fallback = 'Unknown error') {
23
+ const message = error instanceof Error ? error.message : fallback;
24
+ return { success: false, error: message };
25
+ }
26
+ }
27
+ exports.BasePaymentProvider = BasePaymentProvider;
28
+ //# sourceMappingURL=base-payment-provider.abstract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-payment-provider.abstract.js","sourceRoot":"","sources":["../../src/abstract/base-payment-provider.abstract.ts"],"names":[],"mappings":";;;AAIA;;;;;;;;;;;;GAYG;AACH,MAAsB,mBAAmB;IASvC;;;OAGG;IACO,WAAW,CAAC,KAAc,EAAE,QAAQ,GAAG,eAAe;QAC9D,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;QAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;CACF;AAjBD,kDAiBC"}
@@ -0,0 +1,35 @@
1
+ import { Router, RequestHandler } from 'express';
2
+ import { CheckoutConfigurator } from '../../checkout-configurator';
3
+ export interface ExpressCheckoutOptions {
4
+ /**
5
+ * Middleware applied to ALL checkout routes (e.g. API key auth).
6
+ * Webhooks are typically public — use `publicPaths` to exclude them.
7
+ */
8
+ middleware?: RequestHandler[];
9
+ /**
10
+ * Route suffixes that bypass `middleware` (e.g. [':provider/webhook']).
11
+ * Matched against the path suffix after the mount point.
12
+ */
13
+ publicPaths?: string[];
14
+ }
15
+ /**
16
+ * Creates an Express Router with all checkout endpoints pre-wired.
17
+ *
18
+ * Routes mounted:
19
+ * ```
20
+ * POST /:provider → createPayment
21
+ * POST /:provider/execute → executePayment
22
+ * GET /:provider/redirect → handleRedirect (must come before /:provider/:id)
23
+ * GET /:provider/:id → getPaymentDetails
24
+ * POST /:provider/refund → refundPayment
25
+ * POST /:provider/webhook → handleWebhook
26
+ * ```
27
+ *
28
+ * Usage:
29
+ * ```typescript
30
+ * import { createCheckoutRouter } from 'awesome-node-checkout/express';
31
+ * app.use('/checkout', createCheckoutRouter(checkout));
32
+ * ```
33
+ */
34
+ export declare function createCheckoutRouter(checkout: CheckoutConfigurator, options?: ExpressCheckoutOptions): Router;
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,cAAc,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGnE,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAE9B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,GAAE,sBAA2B,GACnC,MAAM,CA8FR"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCheckoutRouter = createCheckoutRouter;
4
+ const express_1 = require("express");
5
+ const errors_1 = require("../../models/errors");
6
+ /**
7
+ * Creates an Express Router with all checkout endpoints pre-wired.
8
+ *
9
+ * Routes mounted:
10
+ * ```
11
+ * POST /:provider → createPayment
12
+ * POST /:provider/execute → executePayment
13
+ * GET /:provider/redirect → handleRedirect (must come before /:provider/:id)
14
+ * GET /:provider/:id → getPaymentDetails
15
+ * POST /:provider/refund → refundPayment
16
+ * POST /:provider/webhook → handleWebhook
17
+ * ```
18
+ *
19
+ * Usage:
20
+ * ```typescript
21
+ * import { createCheckoutRouter } from 'awesome-node-checkout/express';
22
+ * app.use('/checkout', createCheckoutRouter(checkout));
23
+ * ```
24
+ */
25
+ function createCheckoutRouter(checkout, options = {}) {
26
+ const router = (0, express_1.Router)();
27
+ // Apply shared middleware (skipping public paths)
28
+ if (options.middleware?.length) {
29
+ const publicPaths = options.publicPaths ?? [];
30
+ router.use((req, res, next) => {
31
+ const providerParam = String(req.params?.provider ?? '');
32
+ const isPublic = publicPaths.some((p) => req.path.endsWith(p) || req.path.includes(p.replace(':provider', providerParam)));
33
+ if (isPublic)
34
+ return next();
35
+ // Chain all middleware in sequence
36
+ const handlers = options.middleware;
37
+ const run = (i) => {
38
+ if (i >= handlers.length)
39
+ return next();
40
+ handlers[i](req, res, () => run(i + 1));
41
+ };
42
+ run(0);
43
+ });
44
+ }
45
+ // ---- POST /:provider — create payment ------------------------------------
46
+ router.post('/:provider', async (req, res) => {
47
+ try {
48
+ const result = await checkout.createPayment(String(req.params.provider), req.body);
49
+ res.status(result.success ? 201 : 400).json(result);
50
+ }
51
+ catch (err) {
52
+ sendError(res, err);
53
+ }
54
+ });
55
+ // ---- POST /:provider/execute — execute payment ---------------------------
56
+ router.post('/:provider/execute', async (req, res) => {
57
+ try {
58
+ const { paymentId, data } = req.body;
59
+ const result = await checkout.executePayment(String(req.params.provider), paymentId, data);
60
+ res.status(result.success ? 200 : 400).json(result);
61
+ }
62
+ catch (err) {
63
+ sendError(res, err);
64
+ }
65
+ });
66
+ // ---- POST /:provider/refund — refund payment -----------------------------
67
+ router.post('/:provider/refund', async (req, res) => {
68
+ try {
69
+ const { paymentId, amount } = req.body;
70
+ const result = await checkout.refundPayment(String(req.params.provider), paymentId, amount);
71
+ res.status(result.success ? 200 : 400).json(result);
72
+ }
73
+ catch (err) {
74
+ sendError(res, err);
75
+ }
76
+ });
77
+ // ---- POST /:provider/webhook — handle webhook ----------------------------
78
+ router.post('/:provider/webhook', async (req, res) => {
79
+ try {
80
+ const result = await checkout.handleWebhook(String(req.params.provider), req.body, req.headers);
81
+ res.status(result.success ? 200 : 400).json(result);
82
+ }
83
+ catch (err) {
84
+ sendError(res, err);
85
+ }
86
+ });
87
+ // ---- GET /:provider/redirect — handle redirect callback ------------------
88
+ // NOTE: must be defined BEFORE /:provider/:id to avoid "redirect" being
89
+ // treated as a paymentId.
90
+ router.get('/:provider/redirect', async (req, res) => {
91
+ try {
92
+ const result = await checkout.handleRedirect(String(req.params.provider), req.query);
93
+ res.status(result.success ? 200 : 400).json(result);
94
+ }
95
+ catch (err) {
96
+ sendError(res, err);
97
+ }
98
+ });
99
+ // ---- GET /:provider/:id — get payment details ----------------------------
100
+ router.get('/:provider/:id', async (req, res) => {
101
+ try {
102
+ const result = await checkout.getPaymentDetails(String(req.params.provider), String(req.params.id));
103
+ res.status(result.success ? 200 : 404).json(result);
104
+ }
105
+ catch (err) {
106
+ sendError(res, err);
107
+ }
108
+ });
109
+ return router;
110
+ }
111
+ // ---------------------------------------------------------------------------
112
+ // Helpers
113
+ // ---------------------------------------------------------------------------
114
+ function sendError(res, err) {
115
+ if (err instanceof errors_1.CheckoutError) {
116
+ const statusMap = {
117
+ PROVIDER_NOT_FOUND: 404,
118
+ WEBHOOK_NOT_SUPPORTED: 422,
119
+ REDIRECT_NOT_SUPPORTED: 422,
120
+ };
121
+ const status = statusMap[err.code] ?? 500;
122
+ res.status(status).json({ success: false, error: err.message, code: err.code });
123
+ }
124
+ else {
125
+ const message = err instanceof Error ? err.message : 'Internal server error';
126
+ res.status(500).json({ success: false, error: message });
127
+ }
128
+ }
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":";;AAqCA,oDAiGC;AAtID,qCAAoE;AAEpE,gDAAoD;AAgBpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,oBAAoB,CAClC,QAA8B,EAC9B,UAAkC,EAAE;IAEpC,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;IAExB,kDAAkD;IAClD,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QAC9C,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC5B,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;YACzD,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACtC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CACjF,CAAC;YACF,IAAI,QAAQ;gBAAE,OAAO,IAAI,EAAE,CAAC;YAC5B,mCAAmC;YACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAW,CAAC;YACrC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAQ,EAAE;gBAC9B,IAAI,CAAC,I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E,UAAU;AACV,8EAA8E;AAE9E,SAAS,SAAS,CAAC,GAAa,EAAE,GAAY;IAC5C,IAAI,GAAG,YAAY,sBAAa,EAAE,CAAC;QACjC,MAAM,SAAS,GAA2B;YACxC,kBAAkB,EAAE,GAAG;YACvB,qBAAqB,EAAE,GAAG;YAC1B,sBAAsB,EAAE,GAAG;SAC5B,CAAC;QACF,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;QAC1C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAClF,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC;QAC7E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { IPaymentProvider } from './interfaces/payment-provider.interface';
2
+ import { PaymentRequest } from './models/payment-request.model';
3
+ import { PaymentResult, WebhookResult } from './models/payment-result.model';
4
+ import { CheckoutConfig } from './models/checkout-config.model';
5
+ import { CheckoutEventBus } from './events/checkout-event-bus';
6
+ /**
7
+ * Main entry point for awesome-node-checkout.
8
+ *
9
+ * Usage (framework-agnostic):
10
+ * ```typescript
11
+ * const checkout = new CheckoutConfigurator();
12
+ * checkout
13
+ * .registerProvider(new PayPalProvider({ clientId, clientSecret }))
14
+ * .registerProvider(new NexiProvider({ merchantId, macKey }))
15
+ * .registerProvider(new SatispayProvider({ keyId, privateKey }));
16
+ *
17
+ * // Use directly in any framework
18
+ * const result = await checkout.createPayment('paypal', request);
19
+ * ```
20
+ *
21
+ * Usage with Express adapter:
22
+ * ```typescript
23
+ * import { createCheckoutRouter } from 'awesome-node-checkout/express';
24
+ * app.use('/checkout', createCheckoutRouter(checkout));
25
+ * ```
26
+ */
27
+ export declare class CheckoutConfigurator {
28
+ private readonly config;
29
+ private readonly providers;
30
+ /** Event bus — subscribe to payment lifecycle events */
31
+ readonly events: CheckoutEventBus;
32
+ constructor(config?: CheckoutConfig);
33
+ /** Emits an event only when `config.emitEvents` is not explicitly `false`. */
34
+ private emit;
35
+ /**
36
+ * Register a payment provider. Chainable.
37
+ * @throws CheckoutError if a provider with the same name is already registered.
38
+ */
39
+ registerProvider(provider: IPaymentProvider): this;
40
+ /**
41
+ * Retrieve a registered provider by name.
42
+ * @throws CheckoutError if the provider is not found.
43
+ */
44
+ getProvider(name: string): IPaymentProvider;
45
+ /** Returns the names of all registered providers */
46
+ getRegisteredProviders(): string[];
47
+ /** Create a new payment via the specified provider */
48
+ createPayment(providerName: string, request: PaymentRequest): Promise<PaymentResult>;
49
+ /** Execute/capture a previously created payment */
50
+ executePayment(providerName: string, paymentId: string, data?: Record<string, string>): Promise<PaymentResult>;
51
+ /** Retrieve the current status and details of a payment */
52
+ getPaymentDetails(providerName: string, paymentId: string): Promise<PaymentResult>;
53
+ /** Issue a full or partial refund */
54
+ refundPayment(providerName: string, paymentId: string, amount?: number): Promise<PaymentResult>;
55
+ /**
56
+ * Handle an incoming webhook from the provider.
57
+ * @throws CheckoutError if the provider does not support webhooks.
58
+ */
59
+ handleWebhook(providerName: string, body: Record<string, unknown>, headers: Record<string, string>): Promise<WebhookResult>;
60
+ /**
61
+ * Handle the redirect callback from the provider (query params).
62
+ * @throws CheckoutError if the provider does not support redirect handling.
63
+ */
64
+ handleRedirect(providerName: string, query: Record<string, string>): Promise<PaymentResult>;
65
+ }
66
+ //# sourceMappingURL=checkout-configurator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-configur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AAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,CAAC;IAYzB;;;OAGG;IACG,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,aAAa,CAAC;IAoBzB;;;OAGG;IACG,cAAc,CAClB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,aAAa,CAAC;CAkB1B"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckoutConfigurator = void 0;
4
+ const errors_1 = require("./models/errors");
5
+ const checkout_event_bus_1 = require("./events/checkout-event-bus");
6
+ /**
7
+ * Main entry point for awesome-node-checkout.
8
+ *
9
+ * Usage (framework-agnostic):
10
+ * ```typescript
11
+ * const checkout = new CheckoutConfigurator();
12
+ * checkout
13
+ * .registerProvider(new PayPalProvider({ clientId, clientSecret }))
14
+ * .registerProvider(new NexiProvider({ merchantId, macKey }))
15
+ * .registerProvider(new SatispayProvider({ keyId, privateKey }));
16
+ *
17
+ * // Use directly in any framework
18
+ * const result = await checkout.createPayment('paypal', request);
19
+ * ```
20
+ *
21
+ * Usage with Express adapter:
22
+ * ```typescript
23
+ * import { createCheckoutRouter } from 'awesome-node-checkout/express';
24
+ * app.use('/checkout', createCheckoutRouter(checkout));
25
+ * ```
26
+ */
27
+ class CheckoutConfigurator {
28
+ constructor(config = {}) {
29
+ this.config = config;
30
+ this.providers = new Map();
31
+ /** Event bus — subscribe to payment lifecycle events */
32
+ this.events = new checkout_event_bus_1.CheckoutEventBus();
33
+ }
34
+ /** Emits an event only when `config.emitEvents` is not explicitly `false`. */
35
+ async emit(event, data) {
36
+ if (this.config.emitEvents !== false) {
37
+ await this.events.emit(event, data);
38
+ }
39
+ }
40
+ /**
41
+ * Register a payment provider. Chainable.
42
+ * @throws CheckoutError if a provider with the same name is already registered.
43
+ */
44
+ registerProvider(provider) {
45
+ const key = provider.name.toLowerCase();
46
+ if (this.providers.has(key)) {
47
+ throw new errors_1.CheckoutError(`Provider '${provider.name}' is already registered`, 'PROVIDER_ALREADY_REGISTERED', provider.name);
48
+ }
49
+ this.providers.set(key, provider);
50
+ return this;
51
+ }
52
+ /**
53
+ * Retrieve a registered provider by name.
54
+ * @throws CheckoutError if the provider is not found.
55
+ */
56
+ getProvider(name) {
57
+ const provider = this.providers.get(name.toLowerCase());
58
+ if (!provider) {
59
+ throw new errors_1.CheckoutError(`Payment provider '${name}' not found. Did you call registerProvider()?`, 'PROVIDER_NOT_FOUND', name);
60
+ }
61
+ return provider;
62
+ }
63
+ /** Returns the names of all registered providers */
64
+ getRegisteredProviders() {
65
+ return Array.from(this.providers.keys());
66
+ }
67
+ /** Create a new payment via the specified provider */
68
+ async createPayment(providerName, request) {
69
+ const provider = this.getProvider(providerName);
70
+ const result = await provider.createPayment(request);
71
+ await this.emit(result.success ? 'payment.created' : 'payment.failed', {
72
+ provider: providerName,
73
+ paymentId: result.paymentId,
74
+ orderId: request.orderId,
75
+ status: result.status,
76
+ error: result.error,
77
+ });
78
+ return result;
79
+ }
80
+ /** Execute/capture a previously created payment */
81
+ async executePayment(providerName, paymentId, data) {
82
+ const provider = this.getProvider(providerName);
83
+ const result = await provider.executePayment(paymentId, data);
84
+ await this.emit(result.success ? 'payment.completed' : 'payment.failed', {
85
+ provider: providerName,
86
+ paymentId,
87
+ status: result.status,
88
+ error: result.error,
89
+ });
90
+ return result;
91
+ }
92
+ /** Retrieve the current status and details of a payment */
93
+ async getPaymentDetails(providerName, paymentId) {
94
+ const provider = this.getProvider(providerName);
95
+ return provider.getPaymentDetails(paymentId);
96
+ }
97
+ /** Issue a full or partial refund */
98
+ async refundPayment(providerName, paymentId, amount) {
99
+ const provider = this.getProvider(providerName);
100
+ const result = await provider.refundPayment(paymentId, amount);
101
+ await this.emit('payment.refunded', {
102
+ provider: providerName,
103
+ paymentId,
104
+ status: result.status,
105
+ error: result.error,
106
+ });
107
+ return result;
108
+ }
109
+ /**
110
+ * Handle an incoming webhook from the provider.
111
+ * @throws CheckoutError if the provider does not support webhooks.
112
+ */
113
+ async handleWebhook(providerName, body, headers) {
114
+ const provider = this.getProvider(providerName);
115
+ if (!provider.handleWebhook) {
116
+ throw new errors_1.CheckoutError(`Provider '${providerName}' does not support webhook handling`, 'WEBHOOK_NOT_SUPPORTED', providerName);
117
+ }
118
+ const result = await provider.handleWebhook(body, headers);
119
+ await this.emit('webhook.received', {
120
+ provider: providerName,
121
+ paymentId: result.paymentId,
122
+ status: result.status,
123
+ error: result.error,
124
+ data: body,
125
+ });
126
+ return result;
127
+ }
128
+ /**
129
+ * Handle the redirect callback from the provider (query params).
130
+ * @throws CheckoutError if the provider does not support redirect handling.
131
+ */
132
+ async handleRedirect(providerName, query) {
133
+ const provider = this.getProvider(providerName);
134
+ if (!provider.handleRedirect) {
135
+ throw new errors_1.CheckoutError(`Provider '${providerName}' does not support redirect handling`, 'REDIRECT_NOT_SUPPORTED', providerName);
136
+ }
137
+ const result = await provider.handleRedirect(query);
138
+ await this.emit(result.success ? 'payment.completed' : 'payment.failed', {
139
+ provider: providerName,
140
+ paymentId: result.paymentId,
141
+ status: result.status,
142
+ error: result.error,
143
+ });
144
+ return result;
145
+ }
146
+ }
147
+ exports.CheckoutConfigurator = CheckoutConfigurator;
148
+ //# sourceMappingURL=checkout-configurator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-configurator.js","sourceRoot":"","sources":["../src/checkout-configurator.ts"],"names":[],"mappings":";;;AAIA,4CAAgD;AAChD,oEAAwG;AAExG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,oBAAoB;IAM/B,YAA6B,SAAyB,EAAE;QAA3B,WAAM,GAAN,MAAM,CAAqB;QALvC,cAAS,GAAkC,IAAI,GAA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;YAC7B,MAAM,IAAI,sBAAa,CACrB,aAAa,YAAY,sCAAsC,EAC/D,wBAAwB,EACxB,YAAY,CACb,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,gBAAgB,EAAE;YACvE,QAAQ,EAAE,YAAY;YACtB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAnKD,oDAmKC"}
@@ -0,0 +1,29 @@
1
+ export type CheckoutEventName = 'payment.created' | 'payment.completed' | 'payment.failed' | 'payment.refunded' | 'webhook.received';
2
+ export interface CheckoutEventPayload {
3
+ provider: string;
4
+ paymentId?: string;
5
+ orderId?: string;
6
+ status?: string;
7
+ error?: string;
8
+ data?: any;
9
+ timestamp: Date;
10
+ }
11
+ type EventListener = (payload: CheckoutEventPayload) => void | Promise<void>;
12
+ /**
13
+ * Simple event bus for checkout lifecycle events.
14
+ *
15
+ * Usage:
16
+ * ```typescript
17
+ * checkout.events.on('payment.completed', ({ provider, paymentId }) => {
18
+ * console.log(`Payment ${paymentId} completed via ${provider}`);
19
+ * });
20
+ * ```
21
+ */
22
+ export declare class CheckoutEventBus {
23
+ private readonly listeners;
24
+ on(event: CheckoutEventName, listener: EventListener): this;
25
+ off(event: CheckoutEventName, listener: EventListener): this;
26
+ emit(event: CheckoutEventName, payload: Omit<CheckoutEventPayload, 'timestamp'>): Promise<void>;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=checkout-event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-event-bus.d.ts","sourceRoot":"","sources":["../../src/events/checkout-event-bus.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,KAAK,aAAa,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE7E;;;;;;;;;GASG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsD;IAEhF,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAM3D,GAAG,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAQtD,IAAI,CACR,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC;CAKjB"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckoutEventBus = void 0;
4
+ /**
5
+ * Simple event bus for checkout lifecycle events.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * checkout.events.on('payment.completed', ({ provider, paymentId }) => {
10
+ * console.log(`Payment ${paymentId} completed via ${provider}`);
11
+ * });
12
+ * ```
13
+ */
14
+ class CheckoutEventBus {
15
+ constructor() {
16
+ this.listeners = new Map();
17
+ }
18
+ on(event, listener) {
19
+ const handlers = this.listeners.get(event) ?? [];
20
+ this.listeners.set(event, [...handlers, listener]);
21
+ return this;
22
+ }
23
+ off(event, listener) {
24
+ const handlers = this.listeners.get(event);
25
+ if (handlers) {
26
+ this.listeners.set(event, handlers.filter((h) => h !== listener));
27
+ }
28
+ return this;
29
+ }
30
+ async emit(event, payload) {
31
+ const handlers = this.listeners.get(event) ?? [];
32
+ const fullPayload = { ...payload, timestamp: new Date() };
33
+ await Promise.all(handlers.map((h) => h(fullPayload)));
34
+ }
35
+ }
36
+ exports.CheckoutEventBus = CheckoutEventBus;
37
+ //# sourceMappingURL=checkout-event-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-event-bus.js","sourceRoot":"","sources":["../../src/events/checkout-event-bus.ts"],"names":[],"mappings":";;;AAmBA;;;;;;;;;GASG;AACH,MAAa,gBAAgB;IAA7B;QACmB,cAAS,GAA4C,IAAI,GAAG,EAAE,CAAC;IAwBlF,CAAC;IAtBC,EAAE,CAAC,KAAwB,EAAE,QAAuB;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,KAAwB,EAAE,QAAuB;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI,CACR,KAAwB,EACxB,OAAgD;QAEhD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACjD,MAAM,WAAW,GAAyB,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;QAChF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAzBD,4CAyBC"}
@@ -0,0 +1,19 @@
1
+ export { CheckoutConfigurator } from './checkout-configurator';
2
+ export type { IPaymentProvider, PaymentFlow } from './interfaces/payment-provider.interface';
3
+ export type { ITransactionStore, TransactionData } from './interfaces/transaction-store.interface';
4
+ export type { PaymentRequest } from './models/payment-request.model';
5
+ export type { PaymentResult, WebhookResult } from './models/payment-result.model';
6
+ export type { CheckoutConfig } from './models/checkout-config.model';
7
+ export { CheckoutError } from './models/errors';
8
+ export type { CheckoutErrorCode } from './models/errors';
9
+ export { BasePaymentProvider } from './abstract/base-payment-provider.abstract';
10
+ export { CheckoutEventBus } from './events/checkout-event-bus';
11
+ export type { CheckoutEventName, CheckoutEventPayload } from './events/checkout-event-bus';
12
+ export { InMemoryTransactionStore } from './stores/in-memory-transaction.store';
13
+ export { PayPalProvider } from './providers/paypal/paypal.provider';
14
+ export type { PayPalProviderConfig } from './providers/paypal/paypal.provider';
15
+ export { NexiProvider } from './providers/nexi/nexi.provider';
16
+ export type { NexiProviderConfig } from './providers/nexi/nexi.provider';
17
+ export { SatispayProvider } from './providers/satispay/satispay.provider';
18
+ export type { SatispayProviderConfig } from './providers/satispay/satispay.provider';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAC7F,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAGnG,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClF,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAGhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAG3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAGhF,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,YAAY,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SatispayProvider = exports.NexiProvider = exports.PayPalProvider = exports.InMemoryTransactionStore = exports.CheckoutEventBus = exports.BasePaymentProvider = exports.CheckoutError = exports.CheckoutConfigurator = void 0;
4
+ // ---- Configurator ----------------------------------------------------------
5
+ var checkout_configurator_1 = require("./checkout-configurator");
6
+ Object.defineProperty(exports, "CheckoutConfigurator", { enumerable: true, get: function () { return checkout_configurator_1.CheckoutConfigurator; } });
7
+ var errors_1 = require("./models/errors");
8
+ Object.defineProperty(exports, "CheckoutError", { enumerable: true, get: function () { return errors_1.CheckoutError; } });
9
+ // ---- Abstract --------------------------------------------------------------
10
+ var base_payment_provider_abstract_1 = require("./abstract/base-payment-provider.abstract");
11
+ Object.defineProperty(exports, "BasePaymentProvider", { enumerable: true, get: function () { return base_payment_provider_abstract_1.BasePaymentProvider; } });
12
+ // ---- Events ----------------------------------------------------------------
13
+ var checkout_event_bus_1 = require("./events/checkout-event-bus");
14
+ Object.defineProperty(exports, "CheckoutEventBus", { enumerable: true, get: function () { return checkout_event_bus_1.CheckoutEventBus; } });
15
+ // ---- Stores ----------------------------------------------------------------
16
+ var in_memory_transaction_store_1 = require("./stores/in-memory-transaction.store");
17
+ Object.defineProperty(exports, "InMemoryTransactionStore", { enumerable: true, get: function () { return in_memory_transaction_store_1.InMemoryTransactionStore; } });
18
+ // ---- Providers -------------------------------------------------------------
19
+ var paypal_provider_1 = require("./providers/paypal/paypal.provider");
20
+ Object.defineProperty(exports, "PayPalProvider", { enumerable: true, get: function () { return paypal_provider_1.PayPalProvider; } });
21
+ var nexi_provider_1 = require("./providers/nexi/nexi.provider");
22
+ Object.defineProperty(exports, "NexiProvider", { enumerable: true, get: function () { return nexi_provider_1.NexiProvider; } });
23
+ var satispay_provider_1 = require("./providers/satispay/satispay.provider");
24
+ Object.defineProperty(exports, "SatispayProvider", { enumerable: true, get: function () { return satispay_provider_1.SatispayProvider; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA+E;AAC/E,iEAA+D;AAAtD,6HAAA,oBAAoB,OAAA;AAU7B,0CAAgD;AAAvC,uGAAA,aAAa,OAAA;AAGtB,+EAA+E;AAC/E,4FAAgF;AAAvE,qIAAA,mBAAmB,OAAA;AAE5B,+EAA+E;AAC/E,kEAA+D;AAAtD,sHAAA,gBAAgB,OAAA;AAGzB,+EAA+E;AAC/E,oFAAgF;AAAvE,uIAAA,wBAAwB,OAAA;AAEjC,+EAA+E;AAC/E,sEAAoE;AAA3D,iHAAA,cAAc,OAAA;AAGvB,gEAA8D;AAArD,6GAAA,YAAY,OAAA;AAGrB,4EAA0E;AAAjE,qHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,33 @@
1
+ import { PaymentRequest } from '../models/payment-request.model';
2
+ import { PaymentResult, WebhookResult } from '../models/payment-result.model';
3
+ export type PaymentFlow = 'redirect' | 'webhook' | 'direct';
4
+ export interface IPaymentProvider {
5
+ /** Unique provider name, lowercase (e.g. 'paypal', 'nexi', 'satispay') */
6
+ readonly name: string;
7
+ /**
8
+ * Declares the confirmation flow used by this provider:
9
+ * - `redirect`: user is redirected to provider and returns with query params
10
+ * - `webhook`: provider calls a webhook URL asynchronously after payment
11
+ * - `direct`: payment is processed synchronously (e.g. card tokenization)
12
+ */
13
+ readonly flow: PaymentFlow;
14
+ /** Create a new payment and return a result (may include an approvalUrl for redirect flow) */
15
+ createPayment(request: PaymentRequest): Promise<PaymentResult>;
16
+ /** Execute/capture a previously created payment */
17
+ executePayment(paymentId: string, data?: Record<string, string>): Promise<PaymentResult>;
18
+ /** Retrieve the current status and details of a payment */
19
+ getPaymentDetails(paymentId: string): Promise<PaymentResult>;
20
+ /** Issue a full or partial refund on a completed payment */
21
+ refundPayment(paymentId: string, amount?: number): Promise<PaymentResult>;
22
+ /**
23
+ * Handle an incoming webhook notification from the provider.
24
+ * Optional — implement only for providers that use the `webhook` flow.
25
+ */
26
+ handleWebhook?(body: Record<string, unknown>, headers: Record<string, string>): Promise<WebhookResult>;
27
+ /**
28
+ * Handle the redirect callback from the provider (query params from returnUrl).
29
+ * Optional — implement only for providers that use the `redirect` flow.
30
+ */
31
+ handleRedirect?(query: Record<string, string>): Promise<PaymentResult>;
32
+ }
33
+ //# sourceMappingURL=payment-provider.interface.d.ts.map