@fastaar/nextjs 0.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/README.md +159 -0
- package/dist/actions.cjs +36 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +10 -0
- package/dist/actions.d.ts +10 -0
- package/dist/actions.js +12 -0
- package/dist/actions.js.map +1 -0
- package/dist/client.cjs +145 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +61 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.js +119 -0
- package/dist/client.js.map +1 -0
- package/dist/components.cjs +37 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +21 -0
- package/dist/components.d.ts +21 -0
- package/dist/components.js +13 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +17 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +129 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook.cjs +79 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +28 -0
- package/dist/webhook.d.ts +28 -0
- package/dist/webhook.js +44 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var components_exports = {};
|
|
20
|
+
__export(components_exports, {
|
|
21
|
+
CheckoutButton: () => CheckoutButton
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(components_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_actions = require("./actions");
|
|
26
|
+
function CheckoutButton({
|
|
27
|
+
paymentParams,
|
|
28
|
+
children,
|
|
29
|
+
...buttonProps
|
|
30
|
+
}) {
|
|
31
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { action: import_actions.createCheckoutRedirect.bind(null, paymentParams), style: { display: "inline-block" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "submit", ...buttonProps, children: children ?? "Pay with Fastaar" }) });
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
CheckoutButton
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=components.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components.tsx"],"sourcesContent":["import React from 'react';\nimport { createCheckoutRedirect } from './actions';\nimport { CreatePaymentParams } from './types';\n\nexport interface CheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n * Payment parameters such as amount, invoice_id, success_url, cancel_url, and metadata.\n */\n paymentParams: CreatePaymentParams;\n\n /**\n * Content of the button. Defaults to 'Pay with Fastaar'.\n */\n children?: React.ReactNode;\n}\n\n/**\n * A React Server Component that renders a checkout button.\n * Clicking the button invokes a Server Action that creates a payment\n * and redirects the user to the Fastaar checkout page.\n */\nexport function CheckoutButton({\n paymentParams,\n children,\n ...buttonProps\n}: CheckoutButtonProps) {\n return (\n <form action={createCheckoutRedirect.bind(null, paymentParams)} style={{ display: 'inline-block' }}>\n <button type=\"submit\" {...buttonProps}>\n {children ?? 'Pay with Fastaar'}\n </button>\n </form>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BM;AA3BN,qBAAuC;AAoBhC,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,SACE,4CAAC,UAAK,QAAQ,sCAAuB,KAAK,MAAM,aAAa,GAAG,OAAO,EAAE,SAAS,eAAe,GAC/F,sDAAC,YAAO,MAAK,UAAU,GAAG,aACvB,sBAAY,oBACf,GACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CreatePaymentParams } from './types.cjs';
|
|
3
|
+
|
|
4
|
+
interface CheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Payment parameters such as amount, invoice_id, success_url, cancel_url, and metadata.
|
|
7
|
+
*/
|
|
8
|
+
paymentParams: CreatePaymentParams;
|
|
9
|
+
/**
|
|
10
|
+
* Content of the button. Defaults to 'Pay with Fastaar'.
|
|
11
|
+
*/
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A React Server Component that renders a checkout button.
|
|
16
|
+
* Clicking the button invokes a Server Action that creates a payment
|
|
17
|
+
* and redirects the user to the Fastaar checkout page.
|
|
18
|
+
*/
|
|
19
|
+
declare function CheckoutButton({ paymentParams, children, ...buttonProps }: CheckoutButtonProps): React.JSX.Element;
|
|
20
|
+
|
|
21
|
+
export { CheckoutButton, type CheckoutButtonProps };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CreatePaymentParams } from './types.js';
|
|
3
|
+
|
|
4
|
+
interface CheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Payment parameters such as amount, invoice_id, success_url, cancel_url, and metadata.
|
|
7
|
+
*/
|
|
8
|
+
paymentParams: CreatePaymentParams;
|
|
9
|
+
/**
|
|
10
|
+
* Content of the button. Defaults to 'Pay with Fastaar'.
|
|
11
|
+
*/
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A React Server Component that renders a checkout button.
|
|
16
|
+
* Clicking the button invokes a Server Action that creates a payment
|
|
17
|
+
* and redirects the user to the Fastaar checkout page.
|
|
18
|
+
*/
|
|
19
|
+
declare function CheckoutButton({ paymentParams, children, ...buttonProps }: CheckoutButtonProps): React.JSX.Element;
|
|
20
|
+
|
|
21
|
+
export { CheckoutButton, type CheckoutButtonProps };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createCheckoutRedirect } from "./actions";
|
|
3
|
+
function CheckoutButton({
|
|
4
|
+
paymentParams,
|
|
5
|
+
children,
|
|
6
|
+
...buttonProps
|
|
7
|
+
}) {
|
|
8
|
+
return /* @__PURE__ */ jsx("form", { action: createCheckoutRedirect.bind(null, paymentParams), style: { display: "inline-block" }, children: /* @__PURE__ */ jsx("button", { type: "submit", ...buttonProps, children: children ?? "Pay with Fastaar" }) });
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
CheckoutButton
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components.tsx"],"sourcesContent":["import React from 'react';\nimport { createCheckoutRedirect } from './actions';\nimport { CreatePaymentParams } from './types';\n\nexport interface CheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n * Payment parameters such as amount, invoice_id, success_url, cancel_url, and metadata.\n */\n paymentParams: CreatePaymentParams;\n\n /**\n * Content of the button. Defaults to 'Pay with Fastaar'.\n */\n children?: React.ReactNode;\n}\n\n/**\n * A React Server Component that renders a checkout button.\n * Clicking the button invokes a Server Action that creates a payment\n * and redirects the user to the Fastaar checkout page.\n */\nexport function CheckoutButton({\n paymentParams,\n children,\n ...buttonProps\n}: CheckoutButtonProps) {\n return (\n <form action={createCheckoutRedirect.bind(null, paymentParams)} style={{ display: 'inline-block' }}>\n <button type=\"submit\" {...buttonProps}>\n {children ?? 'Pay with Fastaar'}\n </button>\n </form>\n );\n}\n"],"mappings":"AA4BM;AA3BN,SAAS,8BAA8B;AAoBhC,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,SACE,oBAAC,UAAK,QAAQ,uBAAuB,KAAK,MAAM,aAAa,GAAG,OAAO,EAAE,SAAS,eAAe,GAC/F,8BAAC,YAAO,MAAK,UAAU,GAAG,aACvB,sBAAY,oBACf,GACF;AAEJ;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./types"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./client"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./webhook"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./actions"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./components"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./types"),
|
|
26
|
+
...require("./client"),
|
|
27
|
+
...require("./webhook"),
|
|
28
|
+
...require("./actions"),
|
|
29
|
+
...require("./components")
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './client';\nexport * from './webhook';\nexport * from './actions';\nexport * from './components';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,oBAAd;AACA,0BAAc,qBADd;AAEA,0BAAc,sBAFd;AAGA,0BAAc,sBAHd;AAIA,0BAAc,yBAJd;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent } from './types.cjs';
|
|
2
|
+
export { FastaarClient, FastaarError, getFastaarClient } from './client.cjs';
|
|
3
|
+
export { verifyNextWebhook, verifyWebhookSignature } from './webhook.cjs';
|
|
4
|
+
export { createCheckoutRedirect } from './actions.cjs';
|
|
5
|
+
export { CheckoutButton, CheckoutButtonProps } from './components.cjs';
|
|
6
|
+
import 'react';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent } from './types.js';
|
|
2
|
+
export { FastaarClient, FastaarError, getFastaarClient } from './client.js';
|
|
3
|
+
export { verifyNextWebhook, verifyWebhookSignature } from './webhook.js';
|
|
4
|
+
export { createCheckoutRedirect } from './actions.js';
|
|
5
|
+
export { CheckoutButton, CheckoutButtonProps } from './components.js';
|
|
6
|
+
import 'react';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './client';\nexport * from './webhook';\nexport * from './actions';\nexport * from './components';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Configuration options for the Fastaar client.\n */\nexport interface FastaarClientOptions {\n /**\n * Timeout in milliseconds for API requests. Defaults to 15000.\n */\n timeoutMs?: number;\n}\n\n/**\n * Parameters for creating a new payment.\n */\nexport interface CreatePaymentParams {\n /**\n * The amount to charge (can be a number or string representation of a decimal).\n */\n amount: number | string;\n\n /**\n * Your custom reference identifier for the invoice/order.\n * Supplying the same invoice_id will retrieve the existing payment intent\n * instead of creating a duplicate, ensuring idempotency.\n */\n invoice_id?: string;\n\n /**\n * The URL to redirect the customer to upon successful payment completion.\n */\n success_url?: string;\n\n /**\n * The URL to redirect the customer to if they cancel the checkout process.\n */\n cancel_url?: string;\n\n /**\n * Arbitrary key-value metadata to attach to the payment.\n */\n metadata?: Record<string, string>;\n}\n\n/**\n * Parameters for querying the list of payments.\n */\nexport interface ListPaymentsParams extends Record<string, string | number | undefined> {\n /**\n * Filter payments by status (e.g., 'completed', 'pending', 'cancelled').\n */\n status?: string;\n\n /**\n * Filter payments by your custom invoice/order reference.\n */\n invoice_id?: string;\n\n /**\n * Number of payments to return per page.\n */\n per_page?: number;\n\n /**\n * Page number to retrieve (for pagination).\n */\n page?: number;\n}\n\n/**\n * Representation of a payment object returned by the Fastaar API.\n */\nexport interface Payment {\n /**\n * Unique Fastaar transaction identifier.\n */\n id: string;\n\n /**\n * The transaction amount.\n */\n amount: string;\n\n /**\n * The associated invoice ID supplied when the payment was created.\n */\n invoice_id?: string;\n\n /**\n * The current status of the payment (e.g., 'completed', 'pending', 'cancelled').\n */\n status: string;\n\n /**\n * The secure hosted checkout URL where the customer completes payment.\n */\n checkout_url: string;\n\n /**\n * The customer's mobile number, if paid (e.g. bKash or Nagad wallet number).\n */\n wallet_number?: string;\n\n /**\n * The payment method used (e.g., 'bkash', 'nagad').\n */\n payment_method?: string;\n\n /**\n * Transaction ID from the mobile operator/gateway (e.g. bKash trxID).\n */\n trx_id?: string;\n\n /**\n * Indicates whether this payment is live or test mode.\n */\n livemode: boolean;\n\n /**\n * Arbitrary metadata stored on the payment.\n */\n metadata?: Record<string, string>;\n\n /**\n * Payment creation timestamp.\n */\n created_at: string;\n\n /**\n * Payment completion timestamp (if completed).\n */\n completed_at?: string;\n}\n\n/**\n * Structure of a Fastaar Webhook event request body.\n */\nexport interface WebhookEvent {\n /**\n * The type of event (e.g., 'payment.completed').\n */\n event: string;\n\n /**\n * Indicates whether this event occurred in live mode or test mode.\n */\n livemode: boolean;\n\n /**\n * The payment object details associated with this event.\n */\n data: Payment;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the Fastaar client.
|
|
3
|
+
*/
|
|
4
|
+
interface FastaarClientOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Timeout in milliseconds for API requests. Defaults to 15000.
|
|
7
|
+
*/
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for creating a new payment.
|
|
12
|
+
*/
|
|
13
|
+
interface CreatePaymentParams {
|
|
14
|
+
/**
|
|
15
|
+
* The amount to charge (can be a number or string representation of a decimal).
|
|
16
|
+
*/
|
|
17
|
+
amount: number | string;
|
|
18
|
+
/**
|
|
19
|
+
* Your custom reference identifier for the invoice/order.
|
|
20
|
+
* Supplying the same invoice_id will retrieve the existing payment intent
|
|
21
|
+
* instead of creating a duplicate, ensuring idempotency.
|
|
22
|
+
*/
|
|
23
|
+
invoice_id?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The URL to redirect the customer to upon successful payment completion.
|
|
26
|
+
*/
|
|
27
|
+
success_url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The URL to redirect the customer to if they cancel the checkout process.
|
|
30
|
+
*/
|
|
31
|
+
cancel_url?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Arbitrary key-value metadata to attach to the payment.
|
|
34
|
+
*/
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parameters for querying the list of payments.
|
|
39
|
+
*/
|
|
40
|
+
interface ListPaymentsParams extends Record<string, string | number | undefined> {
|
|
41
|
+
/**
|
|
42
|
+
* Filter payments by status (e.g., 'completed', 'pending', 'cancelled').
|
|
43
|
+
*/
|
|
44
|
+
status?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Filter payments by your custom invoice/order reference.
|
|
47
|
+
*/
|
|
48
|
+
invoice_id?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Number of payments to return per page.
|
|
51
|
+
*/
|
|
52
|
+
per_page?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Page number to retrieve (for pagination).
|
|
55
|
+
*/
|
|
56
|
+
page?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Representation of a payment object returned by the Fastaar API.
|
|
60
|
+
*/
|
|
61
|
+
interface Payment {
|
|
62
|
+
/**
|
|
63
|
+
* Unique Fastaar transaction identifier.
|
|
64
|
+
*/
|
|
65
|
+
id: string;
|
|
66
|
+
/**
|
|
67
|
+
* The transaction amount.
|
|
68
|
+
*/
|
|
69
|
+
amount: string;
|
|
70
|
+
/**
|
|
71
|
+
* The associated invoice ID supplied when the payment was created.
|
|
72
|
+
*/
|
|
73
|
+
invoice_id?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The current status of the payment (e.g., 'completed', 'pending', 'cancelled').
|
|
76
|
+
*/
|
|
77
|
+
status: string;
|
|
78
|
+
/**
|
|
79
|
+
* The secure hosted checkout URL where the customer completes payment.
|
|
80
|
+
*/
|
|
81
|
+
checkout_url: string;
|
|
82
|
+
/**
|
|
83
|
+
* The customer's mobile number, if paid (e.g. bKash or Nagad wallet number).
|
|
84
|
+
*/
|
|
85
|
+
wallet_number?: string;
|
|
86
|
+
/**
|
|
87
|
+
* The payment method used (e.g., 'bkash', 'nagad').
|
|
88
|
+
*/
|
|
89
|
+
payment_method?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Transaction ID from the mobile operator/gateway (e.g. bKash trxID).
|
|
92
|
+
*/
|
|
93
|
+
trx_id?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Indicates whether this payment is live or test mode.
|
|
96
|
+
*/
|
|
97
|
+
livemode: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Arbitrary metadata stored on the payment.
|
|
100
|
+
*/
|
|
101
|
+
metadata?: Record<string, string>;
|
|
102
|
+
/**
|
|
103
|
+
* Payment creation timestamp.
|
|
104
|
+
*/
|
|
105
|
+
created_at: string;
|
|
106
|
+
/**
|
|
107
|
+
* Payment completion timestamp (if completed).
|
|
108
|
+
*/
|
|
109
|
+
completed_at?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Structure of a Fastaar Webhook event request body.
|
|
113
|
+
*/
|
|
114
|
+
interface WebhookEvent {
|
|
115
|
+
/**
|
|
116
|
+
* The type of event (e.g., 'payment.completed').
|
|
117
|
+
*/
|
|
118
|
+
event: string;
|
|
119
|
+
/**
|
|
120
|
+
* Indicates whether this event occurred in live mode or test mode.
|
|
121
|
+
*/
|
|
122
|
+
livemode: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* The payment object details associated with this event.
|
|
125
|
+
*/
|
|
126
|
+
data: Payment;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the Fastaar client.
|
|
3
|
+
*/
|
|
4
|
+
interface FastaarClientOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Timeout in milliseconds for API requests. Defaults to 15000.
|
|
7
|
+
*/
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for creating a new payment.
|
|
12
|
+
*/
|
|
13
|
+
interface CreatePaymentParams {
|
|
14
|
+
/**
|
|
15
|
+
* The amount to charge (can be a number or string representation of a decimal).
|
|
16
|
+
*/
|
|
17
|
+
amount: number | string;
|
|
18
|
+
/**
|
|
19
|
+
* Your custom reference identifier for the invoice/order.
|
|
20
|
+
* Supplying the same invoice_id will retrieve the existing payment intent
|
|
21
|
+
* instead of creating a duplicate, ensuring idempotency.
|
|
22
|
+
*/
|
|
23
|
+
invoice_id?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The URL to redirect the customer to upon successful payment completion.
|
|
26
|
+
*/
|
|
27
|
+
success_url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The URL to redirect the customer to if they cancel the checkout process.
|
|
30
|
+
*/
|
|
31
|
+
cancel_url?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Arbitrary key-value metadata to attach to the payment.
|
|
34
|
+
*/
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parameters for querying the list of payments.
|
|
39
|
+
*/
|
|
40
|
+
interface ListPaymentsParams extends Record<string, string | number | undefined> {
|
|
41
|
+
/**
|
|
42
|
+
* Filter payments by status (e.g., 'completed', 'pending', 'cancelled').
|
|
43
|
+
*/
|
|
44
|
+
status?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Filter payments by your custom invoice/order reference.
|
|
47
|
+
*/
|
|
48
|
+
invoice_id?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Number of payments to return per page.
|
|
51
|
+
*/
|
|
52
|
+
per_page?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Page number to retrieve (for pagination).
|
|
55
|
+
*/
|
|
56
|
+
page?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Representation of a payment object returned by the Fastaar API.
|
|
60
|
+
*/
|
|
61
|
+
interface Payment {
|
|
62
|
+
/**
|
|
63
|
+
* Unique Fastaar transaction identifier.
|
|
64
|
+
*/
|
|
65
|
+
id: string;
|
|
66
|
+
/**
|
|
67
|
+
* The transaction amount.
|
|
68
|
+
*/
|
|
69
|
+
amount: string;
|
|
70
|
+
/**
|
|
71
|
+
* The associated invoice ID supplied when the payment was created.
|
|
72
|
+
*/
|
|
73
|
+
invoice_id?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The current status of the payment (e.g., 'completed', 'pending', 'cancelled').
|
|
76
|
+
*/
|
|
77
|
+
status: string;
|
|
78
|
+
/**
|
|
79
|
+
* The secure hosted checkout URL where the customer completes payment.
|
|
80
|
+
*/
|
|
81
|
+
checkout_url: string;
|
|
82
|
+
/**
|
|
83
|
+
* The customer's mobile number, if paid (e.g. bKash or Nagad wallet number).
|
|
84
|
+
*/
|
|
85
|
+
wallet_number?: string;
|
|
86
|
+
/**
|
|
87
|
+
* The payment method used (e.g., 'bkash', 'nagad').
|
|
88
|
+
*/
|
|
89
|
+
payment_method?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Transaction ID from the mobile operator/gateway (e.g. bKash trxID).
|
|
92
|
+
*/
|
|
93
|
+
trx_id?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Indicates whether this payment is live or test mode.
|
|
96
|
+
*/
|
|
97
|
+
livemode: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Arbitrary metadata stored on the payment.
|
|
100
|
+
*/
|
|
101
|
+
metadata?: Record<string, string>;
|
|
102
|
+
/**
|
|
103
|
+
* Payment creation timestamp.
|
|
104
|
+
*/
|
|
105
|
+
created_at: string;
|
|
106
|
+
/**
|
|
107
|
+
* Payment completion timestamp (if completed).
|
|
108
|
+
*/
|
|
109
|
+
completed_at?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Structure of a Fastaar Webhook event request body.
|
|
113
|
+
*/
|
|
114
|
+
interface WebhookEvent {
|
|
115
|
+
/**
|
|
116
|
+
* The type of event (e.g., 'payment.completed').
|
|
117
|
+
*/
|
|
118
|
+
event: string;
|
|
119
|
+
/**
|
|
120
|
+
* Indicates whether this event occurred in live mode or test mode.
|
|
121
|
+
*/
|
|
122
|
+
livemode: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* The payment object details associated with this event.
|
|
125
|
+
*/
|
|
126
|
+
data: Payment;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type { CreatePaymentParams, FastaarClientOptions, ListPaymentsParams, Payment, WebhookEvent };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var webhook_exports = {};
|
|
30
|
+
__export(webhook_exports, {
|
|
31
|
+
verifyNextWebhook: () => verifyNextWebhook,
|
|
32
|
+
verifyWebhookSignature: () => verifyWebhookSignature
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(webhook_exports);
|
|
35
|
+
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
36
|
+
function verifyWebhookSignature(secret, rawBody, signatureHeader, toleranceSeconds = 300) {
|
|
37
|
+
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signatureHeader ?? "");
|
|
38
|
+
if (!match) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const timestamp = Number(match[1]);
|
|
42
|
+
if (Math.abs(Date.now() / 1e3 - timestamp) > toleranceSeconds) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const expected = import_node_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
|
|
46
|
+
try {
|
|
47
|
+
return import_node_crypto.default.timingSafeEqual(Buffer.from(expected), Buffer.from(match[2]));
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function verifyNextWebhook(req, secret) {
|
|
53
|
+
const webhookSecret = secret ?? process.env.FASTAAR_WEBHOOK_SECRET;
|
|
54
|
+
if (!webhookSecret) {
|
|
55
|
+
throw new Error("Fastaar webhook secret is required for verification.");
|
|
56
|
+
}
|
|
57
|
+
const signature = req.headers.get("x-fastaar-signature") || req.headers.get("X-Fastaar-Signature");
|
|
58
|
+
if (!signature) {
|
|
59
|
+
return { isValid: false, event: null };
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const clonedReq = req.clone();
|
|
63
|
+
const rawBody = await clonedReq.text();
|
|
64
|
+
const isValid = verifyWebhookSignature(webhookSecret, rawBody, signature);
|
|
65
|
+
if (!isValid) {
|
|
66
|
+
return { isValid: false, event: null };
|
|
67
|
+
}
|
|
68
|
+
const event = JSON.parse(rawBody);
|
|
69
|
+
return { isValid: true, event };
|
|
70
|
+
} catch {
|
|
71
|
+
return { isValid: false, event: null };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
verifyNextWebhook,
|
|
77
|
+
verifyWebhookSignature
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=webhook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhook.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport { WebhookEvent } from './types';\n\n/**\n * Verify the X-Fastaar-Signature header (`t=<ts>,v1=<hmac>`) against the\n * raw request body using your merchant webhook secret.\n *\n * @param secret Your merchant webhook secret\n * @param rawBody The raw request body string or Buffer\n * @param signatureHeader The value of the X-Fastaar-Signature header\n * @param toleranceSeconds Allowed drift in seconds. Defaults to 300 (5 minutes).\n * @returns boolean\n */\nexport function verifyWebhookSignature(\n secret: string,\n rawBody: string | Buffer,\n signatureHeader: string | null | undefined,\n toleranceSeconds = 300\n): boolean {\n const match = /^t=(\\d+),v1=([a-f0-9]{64})$/.exec(signatureHeader ?? '');\n\n if (!match) {\n return false;\n }\n\n const timestamp = Number(match[1]);\n\n if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) {\n return false;\n }\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(`${timestamp}.${rawBody}`)\n .digest('hex');\n\n try {\n return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(match[2]));\n } catch {\n return false;\n }\n}\n\n/**\n * Verifies and parses a webhook event request from a Next.js App Router Route Handler.\n * It automatically reads the request's raw text body, verifies the signature, and\n * returns the parsed event object.\n *\n * @param req The Request (or NextRequest) object from the Route Handler\n * @param secret The webhook secret. Defaults to process.env.FASTAAR_WEBHOOK_SECRET.\n * @returns {Promise<{ isValid: boolean; event: WebhookEvent | null }>}\n */\nexport async function verifyNextWebhook(\n req: Request,\n secret?: string\n): Promise<{ isValid: boolean; event: WebhookEvent | null }> {\n const webhookSecret = secret ?? process.env.FASTAAR_WEBHOOK_SECRET;\n if (!webhookSecret) {\n throw new Error('Fastaar webhook secret is required for verification.');\n }\n\n const signature = req.headers.get('x-fastaar-signature') || req.headers.get('X-Fastaar-Signature');\n if (!signature) {\n return { isValid: false, event: null };\n }\n\n try {\n // Clone the request to avoid locking the stream if accessed again\n const clonedReq = req.clone();\n const rawBody = await clonedReq.text();\n\n const isValid = verifyWebhookSignature(webhookSecret, rawBody, signature);\n if (!isValid) {\n return { isValid: false, event: null };\n }\n\n const event = JSON.parse(rawBody) as WebhookEvent;\n return { isValid: true, event };\n } catch {\n return { isValid: false, event: null };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AAaZ,SAAS,uBACd,QACA,SACA,iBACA,mBAAmB,KACV;AACT,QAAM,QAAQ,8BAA8B,KAAK,mBAAmB,EAAE;AAEtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,MAAM,CAAC,CAAC;AAEjC,MAAI,KAAK,IAAI,KAAK,IAAI,IAAI,MAAO,SAAS,IAAI,kBAAkB;AAC9D,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,mBAAAA,QACd,WAAW,UAAU,MAAM,EAC3B,OAAO,GAAG,SAAS,IAAI,OAAO,EAAE,EAChC,OAAO,KAAK;AAEf,MAAI;AACF,WAAO,mBAAAA,QAAO,gBAAgB,OAAO,KAAK,QAAQ,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC;AAAA,EAC5E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAWA,eAAsB,kBACpB,KACA,QAC2D;AAC3D,QAAM,gBAAgB,UAAU,QAAQ,IAAI;AAC5C,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB,KAAK,IAAI,QAAQ,IAAI,qBAAqB;AACjG,MAAI,CAAC,WAAW;AACd,WAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,EACvC;AAEA,MAAI;AAEF,UAAM,YAAY,IAAI,MAAM;AAC5B,UAAM,UAAU,MAAM,UAAU,KAAK;AAErC,UAAM,UAAU,uBAAuB,eAAe,SAAS,SAAS;AACxE,QAAI,CAAC,SAAS;AACZ,aAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,IACvC;AAEA,UAAM,QAAQ,KAAK,MAAM,OAAO;AAChC,WAAO,EAAE,SAAS,MAAM,MAAM;AAAA,EAChC,QAAQ;AACN,WAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,EACvC;AACF;","names":["crypto"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebhookEvent } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verify the X-Fastaar-Signature header (`t=<ts>,v1=<hmac>`) against the
|
|
5
|
+
* raw request body using your merchant webhook secret.
|
|
6
|
+
*
|
|
7
|
+
* @param secret Your merchant webhook secret
|
|
8
|
+
* @param rawBody The raw request body string or Buffer
|
|
9
|
+
* @param signatureHeader The value of the X-Fastaar-Signature header
|
|
10
|
+
* @param toleranceSeconds Allowed drift in seconds. Defaults to 300 (5 minutes).
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
declare function verifyWebhookSignature(secret: string, rawBody: string | Buffer, signatureHeader: string | null | undefined, toleranceSeconds?: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Verifies and parses a webhook event request from a Next.js App Router Route Handler.
|
|
16
|
+
* It automatically reads the request's raw text body, verifies the signature, and
|
|
17
|
+
* returns the parsed event object.
|
|
18
|
+
*
|
|
19
|
+
* @param req The Request (or NextRequest) object from the Route Handler
|
|
20
|
+
* @param secret The webhook secret. Defaults to process.env.FASTAAR_WEBHOOK_SECRET.
|
|
21
|
+
* @returns {Promise<{ isValid: boolean; event: WebhookEvent | null }>}
|
|
22
|
+
*/
|
|
23
|
+
declare function verifyNextWebhook(req: Request, secret?: string): Promise<{
|
|
24
|
+
isValid: boolean;
|
|
25
|
+
event: WebhookEvent | null;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export { verifyNextWebhook, verifyWebhookSignature };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebhookEvent } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verify the X-Fastaar-Signature header (`t=<ts>,v1=<hmac>`) against the
|
|
5
|
+
* raw request body using your merchant webhook secret.
|
|
6
|
+
*
|
|
7
|
+
* @param secret Your merchant webhook secret
|
|
8
|
+
* @param rawBody The raw request body string or Buffer
|
|
9
|
+
* @param signatureHeader The value of the X-Fastaar-Signature header
|
|
10
|
+
* @param toleranceSeconds Allowed drift in seconds. Defaults to 300 (5 minutes).
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
declare function verifyWebhookSignature(secret: string, rawBody: string | Buffer, signatureHeader: string | null | undefined, toleranceSeconds?: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Verifies and parses a webhook event request from a Next.js App Router Route Handler.
|
|
16
|
+
* It automatically reads the request's raw text body, verifies the signature, and
|
|
17
|
+
* returns the parsed event object.
|
|
18
|
+
*
|
|
19
|
+
* @param req The Request (or NextRequest) object from the Route Handler
|
|
20
|
+
* @param secret The webhook secret. Defaults to process.env.FASTAAR_WEBHOOK_SECRET.
|
|
21
|
+
* @returns {Promise<{ isValid: boolean; event: WebhookEvent | null }>}
|
|
22
|
+
*/
|
|
23
|
+
declare function verifyNextWebhook(req: Request, secret?: string): Promise<{
|
|
24
|
+
isValid: boolean;
|
|
25
|
+
event: WebhookEvent | null;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export { verifyNextWebhook, verifyWebhookSignature };
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
function verifyWebhookSignature(secret, rawBody, signatureHeader, toleranceSeconds = 300) {
|
|
3
|
+
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signatureHeader ?? "");
|
|
4
|
+
if (!match) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const timestamp = Number(match[1]);
|
|
8
|
+
if (Math.abs(Date.now() / 1e3 - timestamp) > toleranceSeconds) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
|
|
12
|
+
try {
|
|
13
|
+
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(match[2]));
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function verifyNextWebhook(req, secret) {
|
|
19
|
+
const webhookSecret = secret ?? process.env.FASTAAR_WEBHOOK_SECRET;
|
|
20
|
+
if (!webhookSecret) {
|
|
21
|
+
throw new Error("Fastaar webhook secret is required for verification.");
|
|
22
|
+
}
|
|
23
|
+
const signature = req.headers.get("x-fastaar-signature") || req.headers.get("X-Fastaar-Signature");
|
|
24
|
+
if (!signature) {
|
|
25
|
+
return { isValid: false, event: null };
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const clonedReq = req.clone();
|
|
29
|
+
const rawBody = await clonedReq.text();
|
|
30
|
+
const isValid = verifyWebhookSignature(webhookSecret, rawBody, signature);
|
|
31
|
+
if (!isValid) {
|
|
32
|
+
return { isValid: false, event: null };
|
|
33
|
+
}
|
|
34
|
+
const event = JSON.parse(rawBody);
|
|
35
|
+
return { isValid: true, event };
|
|
36
|
+
} catch {
|
|
37
|
+
return { isValid: false, event: null };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
verifyNextWebhook,
|
|
42
|
+
verifyWebhookSignature
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=webhook.js.map
|