@happyvertical/payments 0.92.0 → 0.95.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 +47 -0
- package/dist/adapters/btcpay-client.d.ts +175 -0
- package/dist/adapters/btcpay-client.d.ts.map +1 -0
- package/dist/adapters/btcpay-gateway.d.ts +26 -0
- package/dist/adapters/btcpay-gateway.d.ts.map +1 -0
- package/dist/adapters/btcpay.d.ts +4 -167
- package/dist/adapters/btcpay.d.ts.map +1 -1
- package/dist/adapters/btcpay.js +310 -5
- package/dist/adapters/btcpay.js.map +1 -1
- package/dist/checkout-gateway.d.ts +119 -0
- package/dist/checkout-gateway.d.ts.map +1 -0
- package/dist/chunks/checkout-gateway-DG-LY0oG.js +42 -0
- package/dist/chunks/checkout-gateway-DG-LY0oG.js.map +1 -0
- package/dist/chunks/errors-feZrwnTy.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PaymentError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* `getCheckout` was asked for a checkout this gateway did not create (for
|
|
4
|
+
* example a webhook for an invoice made by hand at the provider). Callers
|
|
5
|
+
* acknowledge and ignore it, like an event with `checkoutId: null`. Its code
|
|
6
|
+
* is `PAYMENT_NOT_OWNED` — routine, and distinct from the
|
|
7
|
+
* `PAYMENT_VERIFICATION_FAILED` of a forged or foreign-store delivery.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CryptoCheckoutNotOwnedError extends PaymentError {
|
|
10
|
+
readonly checkoutId: string;
|
|
11
|
+
constructor(checkoutId: string);
|
|
12
|
+
}
|
|
13
|
+
/** Where a checkout is in its lifecycle. */
|
|
14
|
+
export type CryptoCheckoutStatus =
|
|
15
|
+
/** Awaiting payment; the rate is locked until `expiresAt`. */
|
|
16
|
+
'open'
|
|
17
|
+
/** Enough has been paid but is not yet settled (for example 0-conf). */
|
|
18
|
+
| 'confirming'
|
|
19
|
+
/** Settled under the gateway's confirmation policy. */
|
|
20
|
+
| 'settled'
|
|
21
|
+
/** The rate lock ran out without a full, settled payment. */
|
|
22
|
+
| 'expired'
|
|
23
|
+
/** The gateway invalidated it (for example a payment was double-spent or reorganized away). */
|
|
24
|
+
| 'invalid';
|
|
25
|
+
/** A qualifier that needs a decision beyond the status. */
|
|
26
|
+
export type CryptoCheckoutException = 'none'
|
|
27
|
+
/** Less than the price was received. */
|
|
28
|
+
| 'underpaid'
|
|
29
|
+
/** More than the price was received. */
|
|
30
|
+
| 'overpaid'
|
|
31
|
+
/** Payment arrived after the rate lock expired. */
|
|
32
|
+
| 'paid_late'
|
|
33
|
+
/** An operator marked it settled by hand at the gateway. */
|
|
34
|
+
| 'manually_marked';
|
|
35
|
+
export interface CryptoCheckoutPayment {
|
|
36
|
+
id: string;
|
|
37
|
+
/** The asset paid, for example `BTC`. */
|
|
38
|
+
asset: string;
|
|
39
|
+
/** `onchain`, `lightning`, or a gateway-specific rail name. */
|
|
40
|
+
rail: string;
|
|
41
|
+
/** Decimal amount of `asset`. */
|
|
42
|
+
amount: string;
|
|
43
|
+
/** Decimal network or processing fee in `asset`, when reported. */
|
|
44
|
+
fee?: string;
|
|
45
|
+
status: 'confirming' | 'settled' | 'invalid';
|
|
46
|
+
/** Chain transaction id, for on-chain payments. */
|
|
47
|
+
transactionId?: string;
|
|
48
|
+
receivedAt?: Date;
|
|
49
|
+
}
|
|
50
|
+
export interface CryptoCheckout {
|
|
51
|
+
/** The gateway implementation id (`btcpay`, …). */
|
|
52
|
+
gateway: string;
|
|
53
|
+
id: string;
|
|
54
|
+
orderId?: string;
|
|
55
|
+
status: CryptoCheckoutStatus;
|
|
56
|
+
exception: CryptoCheckoutException;
|
|
57
|
+
/** Locked fiat price, integer minor units of `currency`. */
|
|
58
|
+
amount: number;
|
|
59
|
+
currency: string;
|
|
60
|
+
/** Fiat value received at the locked rate, minor units, rounded down. */
|
|
61
|
+
amountPaid: number;
|
|
62
|
+
/** The asset the price was quoted in (`BTC`), when known. */
|
|
63
|
+
settlementAsset?: string;
|
|
64
|
+
/** Decimal amount of `settlementAsset` the price required. */
|
|
65
|
+
nativeAmountDue?: string;
|
|
66
|
+
/** Decimal amount of `settlementAsset` received across payments. */
|
|
67
|
+
nativeAmountPaid?: string;
|
|
68
|
+
/** Decimal price of one `settlementAsset` in `currency`, as locked. */
|
|
69
|
+
rate?: string;
|
|
70
|
+
/** Where the rate came from, when the gateway or its operator says. */
|
|
71
|
+
rateSource?: string;
|
|
72
|
+
checkoutUrl?: string;
|
|
73
|
+
createdAt?: Date;
|
|
74
|
+
expiresAt?: Date;
|
|
75
|
+
metadata: Record<string, string>;
|
|
76
|
+
payments: CryptoCheckoutPayment[];
|
|
77
|
+
/** The gateway's own representation, for audit only. */
|
|
78
|
+
raw: unknown;
|
|
79
|
+
}
|
|
80
|
+
export interface CreateCryptoCheckoutInput {
|
|
81
|
+
/** Caller-owned order id; creation is idempotent by it. */
|
|
82
|
+
orderId: string;
|
|
83
|
+
/** Price in integer minor units of `currency`. */
|
|
84
|
+
amount: number;
|
|
85
|
+
currency: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
buyerEmail?: string;
|
|
88
|
+
/** String metadata stored on the checkout and returned verbatim (only these keys). */
|
|
89
|
+
metadata?: Record<string, string>;
|
|
90
|
+
/** Where the payer is sent after paying. */
|
|
91
|
+
redirectUrl?: string;
|
|
92
|
+
}
|
|
93
|
+
/** An authenticated webhook delivery. Re-read the checkout to act on it. */
|
|
94
|
+
export interface CryptoCheckoutEvent {
|
|
95
|
+
/** Stable across redeliveries of the same event. */
|
|
96
|
+
eventId: string;
|
|
97
|
+
/** The checkout the event is about; `null` for events about no checkout (acknowledge and ignore). */
|
|
98
|
+
checkoutId: string | null;
|
|
99
|
+
/** The gateway's event type, for logging. */
|
|
100
|
+
type: string;
|
|
101
|
+
redelivery: boolean;
|
|
102
|
+
}
|
|
103
|
+
export interface CryptoCheckoutGateway {
|
|
104
|
+
readonly id: string;
|
|
105
|
+
/** Return the live checkout for `orderId`, or create one. */
|
|
106
|
+
createCheckout(input: CreateCryptoCheckoutInput): Promise<CryptoCheckout>;
|
|
107
|
+
/** Throws `CryptoCheckoutNotOwnedError` for a checkout it did not create. */
|
|
108
|
+
getCheckout(checkoutId: string): Promise<CryptoCheckout>;
|
|
109
|
+
listCheckouts(input: {
|
|
110
|
+
orderId: string;
|
|
111
|
+
}): Promise<CryptoCheckout[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Authenticate and parse a webhook delivery. Throws
|
|
114
|
+
* `PaymentVerificationError` for a bad signature or a delivery that does
|
|
115
|
+
* not belong to this gateway.
|
|
116
|
+
*/
|
|
117
|
+
verifyWebhook(rawBody: string, headers: Headers | Record<string, string | undefined>): CryptoCheckoutEvent;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=checkout-gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-gateway.d.ts","sourceRoot":"","sources":["../src/checkout-gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,qBAAa,2BAA4B,SAAQ,YAAY;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,MAAM;CAQ/B;AAED,4CAA4C;AAC5C,MAAM,MAAM,oBAAoB;AAC9B,8DAA8D;AAC5D,MAAM;AACR,wEAAwE;GACtE,YAAY;AACd,uDAAuD;GACrD,SAAS;AACX,6DAA6D;GAC3D,SAAS;AACX,+FAA+F;GAC7F,SAAS,CAAC;AAEd,2DAA2D;AAC3D,MAAM,MAAM,uBAAuB,GAC/B,MAAM;AACR,w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aymentError } from "./errors-feZrwnTy.js";
|
|
2
|
+
//#region src/checkout-gateway.ts
|
|
3
|
+
/**
|
|
4
|
+
* A provider-neutral port for **hosted crypto checkouts priced in fiat**.
|
|
5
|
+
*
|
|
6
|
+
* Billing code (for example smrt-commerce) talks only to this interface. The
|
|
7
|
+
* BTCPay implementation (`createBtcpayCheckoutGateway` in
|
|
8
|
+
* `@happyvertical/payments/btcpay`) is one adapter; a dedicated crypto-payments
|
|
9
|
+
* service client can implement the same port later without changing callers.
|
|
10
|
+
*
|
|
11
|
+
* Rules every implementation keeps:
|
|
12
|
+
*
|
|
13
|
+
* - **Settlement belongs to the gateway.** `status: 'settled'` means the
|
|
14
|
+
* gateway's own confirmation policy is met. Callers never count
|
|
15
|
+
* confirmations.
|
|
16
|
+
* - **Fiat is exact.** `amount` and `amountPaid` are integer minor units of
|
|
17
|
+
* `currency`; `amountPaid` is rounded down.
|
|
18
|
+
* - **Webhooks carry ids only.** `verifyWebhook` authenticates a delivery and
|
|
19
|
+
* names the checkout; callers act on `getCheckout()`, never on the body.
|
|
20
|
+
* - **Creation is idempotent by `orderId`.** A live checkout for the order is
|
|
21
|
+
* returned instead of creating another; an expired or invalid one is not
|
|
22
|
+
* revived.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* `getCheckout` was asked for a checkout this gateway did not create (for
|
|
26
|
+
* example a webhook for an invoice made by hand at the provider). Callers
|
|
27
|
+
* acknowledge and ignore it, like an event with `checkoutId: null`. Its code
|
|
28
|
+
* is `PAYMENT_NOT_OWNED` — routine, and distinct from the
|
|
29
|
+
* `PAYMENT_VERIFICATION_FAILED` of a forged or foreign-store delivery.
|
|
30
|
+
*/
|
|
31
|
+
var CryptoCheckoutNotOwnedError = class extends PaymentError {
|
|
32
|
+
checkoutId;
|
|
33
|
+
constructor(checkoutId) {
|
|
34
|
+
super(`Checkout ${checkoutId} was not created by this gateway.`, "PAYMENT_NOT_OWNED");
|
|
35
|
+
this.name = "CryptoCheckoutNotOwnedError";
|
|
36
|
+
this.checkoutId = checkoutId;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { CryptoCheckoutNotOwnedError as t };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=checkout-gateway-DG-LY0oG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-gateway-DG-LY0oG.js","names":[],"sources":["../../src/checkout-gateway.ts"],"sourcesContent":["/**\n * A provider-neutral port for **hosted crypto checkouts priced in fiat**.\n *\n * Billing code (for example smrt-commerce) talks only to this interface. The\n * BTCPay implementation (`createBtcpayCheckoutGateway` in\n * `@happyvertical/payments/btcpay`) is one adapter; a dedicated crypto-payments\n * service client can implement the same port later without changing callers.\n *\n * Rules every implementation keeps:\n *\n * - **Settlement belongs to the gateway.** `status: 'settled'` means the\n * gateway's own confirmation policy is met. Callers never count\n * confirmations.\n * - **Fiat is exact.** `amount` and `amountPaid` are integer minor units of\n * `currency`; `amountPaid` is rounded down.\n * - **Webhooks carry ids only.** `verifyWebhook` authenticates a delivery and\n * names the checkout; callers act on `getCheckout()`, never on the body.\n * - **Creation is idempotent by `orderId`.** A live checkout for the order is\n * returned instead of creating another; an expired or invalid one is not\n * revived.\n */\n\nimport { PaymentError } from './errors.js';\n\n/**\n * `getCheckout` was asked for a checkout this gateway did not create (for\n * example a webhook for an invoice made by hand at the provider). Callers\n * acknowledge and ignore it, like an event with `checkoutId: null`. Its code\n * is `PAYMENT_NOT_OWNED` — routine, and distinct from the\n * `PAYMENT_VERIFICATION_FAILED` of a forged or foreign-store delivery.\n */\nexport class CryptoCheckoutNotOwnedError extends PaymentError {\n readonly checkoutId: string;\n\n constructor(checkoutId: string) {\n super(\n `Checkout ${checkoutId} was not created by this gateway.`,\n 'PAYMENT_NOT_OWNED',\n );\n this.name = 'CryptoCheckoutNotOwnedError';\n this.checkoutId = checkoutId;\n }\n}\n\n/** Where a checkout is in its lifecycle. */\nexport type CryptoCheckoutStatus =\n /** Awaiting payment; the rate is locked until `expiresAt`. */\n | 'open'\n /** Enough has been paid but is not yet settled (for example 0-conf). */\n | 'confirming'\n /** Settled under the gateway's confirmation policy. */\n | 'settled'\n /** The rate lock ran out without a full, settled payment. */\n | 'expired'\n /** The gateway invalidated it (for example a payment was double-spent or reorganized away). */\n | 'invalid';\n\n/** A qualifier that needs a decision beyond the status. */\nexport type CryptoCheckoutException =\n | 'none'\n /** Less than the price was received. */\n | 'underpaid'\n /** More than the price was received. */\n | 'overpaid'\n /** Payment arrived after the rate lock expired. */\n | 'paid_late'\n /** An operator marked it settled by hand at the gateway. */\n | 'manually_marked';\n\nexport interface CryptoCheckoutPayment {\n id: string;\n /** The asset paid, for example `BTC`. */\n asset: string;\n /** `onchain`, `lightning`, or a gateway-specific rail name. */\n rail: string;\n /** Decimal amount of `asset`. */\n amount: string;\n /** Decimal network or processing fee in `asset`, when reported. */\n fee?: string;\n status: 'confirming' | 'settled' | 'invalid';\n /** Chain transaction id, for on-chain payments. */\n transactionId?: string;\n receivedAt?: Date;\n}\n\nexport interface CryptoCheckout {\n /** The gateway implementation id (`btcpay`, …). */\n gateway: string;\n id: string;\n orderId?: string;\n status: CryptoCheckoutStatus;\n exception: CryptoCheckoutException;\n /** Locked fiat price, integer minor units of `currency`. */\n amount: number;\n currency: string;\n /** Fiat value received at the locked rate, minor units, rounded down. */\n amountPaid: number;\n /** The asset the price was quoted in (`BTC`), when known. */\n settlementAsset?: string;\n /** Decimal amount of `settlementAsset` the price required. */\n nativeAmountDue?: string;\n /** Decimal amount of `settlementAsset` received across payments. */\n nativeAmountPaid?: string;\n /** Decimal price of one `settlementAsset` in `currency`, as locked. */\n rate?: string;\n /** Where the rate came from, when the gateway or its operator says. */\n rateSource?: string;\n checkoutUrl?: string;\n createdAt?: Date;\n expiresAt?: Date;\n metadata: Record<string, string>;\n payments: CryptoCheckoutPayment[];\n /** The gateway's own representation, for audit only. */\n raw: unknown;\n}\n\nexport interface CreateCryptoCheckoutInput {\n /** Caller-owned order id; creation is idempotent by it. */\n orderId: string;\n /** Price in integer minor units of `currency`. */\n amount: number;\n currency: string;\n description?: string;\n buyerEmail?: string;\n /** String metadata stored on the checkout and returned verbatim (only these keys). */\n metadata?: Record<string, string>;\n /** Where the payer is sent after paying. */\n redirectUrl?: string;\n}\n\n/** An authenticated webhook delivery. Re-read the checkout to act on it. */\nexport interface CryptoCheckoutEvent {\n /** Stable across redeliveries of the same event. */\n eventId: string;\n /** The checkout the event is about; `null` for events about no checkout (acknowledge and ignore). */\n checkoutId: string | null;\n /** The gateway's event type, for logging. */\n type: string;\n redelivery: boolean;\n}\n\nexport interface CryptoCheckoutGateway {\n readonly id: string;\n /** Return the live checkout for `orderId`, or create one. */\n createCheckout(input: CreateCryptoCheckoutInput): Promise<CryptoCheckout>;\n /** Throws `CryptoCheckoutNotOwnedError` for a checkout it did not create. */\n getCheckout(checkoutId: string): Promise<CryptoCheckout>;\n listCheckouts(input: { orderId: string }): Promise<CryptoCheckout[]>;\n /**\n * Authenticate and parse a webhook delivery. Throws\n * `PaymentVerificationError` for a bad signature or a delivery that does\n * not belong to this gateway.\n */\n verifyWebhook(\n rawBody: string,\n headers: Headers | Record<string, string | undefined>,\n ): CryptoCheckoutEvent;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,8BAAb,cAAiD,aAAa;CAC5D;CAEA,YAAY,YAAoB;EAC9B,MACE,YAAY,WAAW,oCACvB,mBACF;EACA,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-feZrwnTy.js","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["export type PaymentErrorCode =\n | 'PAYMENT_CONFIGURATION_ERROR'\n | 'PAYMENT_PROVIDER_ERROR'\n | 'PAYMENT_UNSUPPORTED'\n | 'PAYMENT_VERIFICATION_FAILED'\n | 'PAYMENT_TIMEOUT'\n | 'PAYMENT_INVALID_INPUT';\n\nexport class PaymentError extends Error {\n readonly code: PaymentErrorCode;\n readonly retryable: boolean;\n\n constructor(\n message: string,\n code: PaymentErrorCode = 'PAYMENT_PROVIDER_ERROR',\n options: { cause?: unknown; retryable?: boolean } = {},\n ) {\n super(\n message,\n options.cause === undefined ? undefined : { cause: options.cause },\n );\n this.name = 'PaymentError';\n this.code = code;\n this.retryable = options.retryable ?? false;\n }\n}\n\nexport class PaymentConfigurationError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_CONFIGURATION_ERROR', options);\n this.name = 'PaymentConfigurationError';\n }\n}\n\nexport class PaymentProviderError extends PaymentError {\n constructor(\n message: string,\n options: { cause?: unknown; retryable?: boolean } = {},\n ) {\n super(message, 'PAYMENT_PROVIDER_ERROR', options);\n this.name = 'PaymentProviderError';\n }\n}\n\nexport class PaymentUnsupportedError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_UNSUPPORTED', options);\n this.name = 'PaymentUnsupportedError';\n }\n}\n\nexport class PaymentVerificationError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_VERIFICATION_FAILED', options);\n this.name = 'PaymentVerificationError';\n }\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"errors-feZrwnTy.js","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["export type PaymentErrorCode =\n | 'PAYMENT_CONFIGURATION_ERROR'\n | 'PAYMENT_PROVIDER_ERROR'\n | 'PAYMENT_UNSUPPORTED'\n | 'PAYMENT_VERIFICATION_FAILED'\n | 'PAYMENT_NOT_OWNED'\n | 'PAYMENT_TIMEOUT'\n | 'PAYMENT_INVALID_INPUT';\n\nexport class PaymentError extends Error {\n readonly code: PaymentErrorCode;\n readonly retryable: boolean;\n\n constructor(\n message: string,\n code: PaymentErrorCode = 'PAYMENT_PROVIDER_ERROR',\n options: { cause?: unknown; retryable?: boolean } = {},\n ) {\n super(\n message,\n options.cause === undefined ? undefined : { cause: options.cause },\n );\n this.name = 'PaymentError';\n this.code = code;\n this.retryable = options.retryable ?? false;\n }\n}\n\nexport class PaymentConfigurationError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_CONFIGURATION_ERROR', options);\n this.name = 'PaymentConfigurationError';\n }\n}\n\nexport class PaymentProviderError extends PaymentError {\n constructor(\n message: string,\n options: { cause?: unknown; retryable?: boolean } = {},\n ) {\n super(message, 'PAYMENT_PROVIDER_ERROR', options);\n this.name = 'PaymentProviderError';\n }\n}\n\nexport class PaymentUnsupportedError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_UNSUPPORTED', options);\n this.name = 'PaymentUnsupportedError';\n }\n}\n\nexport class PaymentVerificationError extends PaymentError {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, 'PAYMENT_VERIFICATION_FAILED', options);\n this.name = 'PaymentVerificationError';\n }\n}\n"],"mappings":";AASA,IAAa,eAAb,cAAkC,MAAM;CACtC;CACA;CAEA,YACE,SACA,OAAyB,0BACzB,UAAoD,CAAC,GACrD;EACA,MACE,SACA,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CACnE;EACA,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,YAAY,QAAQ,aAAa;CACxC;AACF;AAEA,IAAa,4BAAb,cAA+C,aAAa;CAC1D,YAAY,SAAiB,UAA+B,CAAC,GAAG;EAC9D,MAAM,SAAS,+BAA+B,OAAO;EACrD,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,aAAa;CACrD,YACE,SACA,UAAoD,CAAC,GACrD;EACA,MAAM,SAAS,0BAA0B,OAAO;EAChD,KAAK,OAAO;CACd;AACF;AAEA,IAAa,0BAAb,cAA6C,aAAa;CACxD,YAAY,SAAiB,UAA+B,CAAC,GAAG;EAC9D,MAAM,SAAS,uBAAuB,OAAO;EAC7C,KAAK,OAAO;CACd;AACF;AAEA,IAAa,2BAAb,cAA8C,aAAa;CACzD,YAAY,SAAiB,UAA+B,CAAC,GAAG;EAC9D,MAAM,SAAS,+BAA+B,OAAO;EACrD,KAAK,OAAO;CACd;AACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type PaymentErrorCode = 'PAYMENT_CONFIGURATION_ERROR' | 'PAYMENT_PROVIDER_ERROR' | 'PAYMENT_UNSUPPORTED' | 'PAYMENT_VERIFICATION_FAILED' | 'PAYMENT_TIMEOUT' | 'PAYMENT_INVALID_INPUT';
|
|
1
|
+
export type PaymentErrorCode = 'PAYMENT_CONFIGURATION_ERROR' | 'PAYMENT_PROVIDER_ERROR' | 'PAYMENT_UNSUPPORTED' | 'PAYMENT_VERIFICATION_FAILED' | 'PAYMENT_NOT_OWNED' | 'PAYMENT_TIMEOUT' | 'PAYMENT_INVALID_INPUT';
|
|
2
2
|
export declare class PaymentError extends Error {
|
|
3
3
|
readonly code: PaymentErrorCode;
|
|
4
4
|
readonly retryable: boolean;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,6BAA6B,GAC7B,wBAAwB,GACxB,qBAAqB,GACrB,6BAA6B,GAC7B,iBAAiB,GACjB,uBAAuB,CAAC;AAE5B,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,gBAA2C,EACjD,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO;CAUzD;AAED,qB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AAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO;CAKzD;AAED,qBAAa,uBAAwB,SAAQ,YAAY;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAI/D;AAED,qBAAa,wBAAyB,SAAQ,YAAY;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAI/D"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as PaymentVerificationError, i as PaymentUnsupportedError, n as PaymentError, r as PaymentProviderError, t as PaymentConfigurationError } from "./chunks/errors-feZrwnTy.js";
|
|
2
|
+
import { t as CryptoCheckoutNotOwnedError } from "./chunks/checkout-gateway-DG-LY0oG.js";
|
|
2
3
|
//#region src/factory.ts
|
|
3
4
|
async function createPaymentBackend(options) {
|
|
4
5
|
if (!options || typeof options !== "object" || Array.isArray(options)) throw new PaymentConfigurationError("Payment backend options must be an object.");
|
|
@@ -30,6 +31,6 @@ async function createPaymentBackend(options) {
|
|
|
30
31
|
/** @internal */
|
|
31
32
|
var PACKAGE_VERSION_INITIALIZED = true;
|
|
32
33
|
//#endregion
|
|
33
|
-
export { PACKAGE_VERSION_INITIALIZED, PaymentConfigurationError, PaymentError, PaymentProviderError, PaymentUnsupportedError, PaymentVerificationError, createPaymentBackend };
|
|
34
|
+
export { CryptoCheckoutNotOwnedError, PACKAGE_VERSION_INITIALIZED, PaymentConfigurationError, PaymentError, PaymentProviderError, PaymentUnsupportedError, PaymentVerificationError, createPaymentBackend };
|
|
34
35
|
|
|
35
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/factory.ts","../src/index.ts"],"sourcesContent":["import type { BaseUsdcAdapterOptions } from './adapters/base-usdc.js';\nimport type { BtcAdapterOptions } from './adapters/btc.js';\nimport type { StripeAdapterOptions } from './adapters/stripe.js';\nimport { PaymentConfigurationError } from './errors.js';\nimport type { PaymentBackend } from './types.js';\n\nexport type PaymentBackendOptions =\n | ({ type: 'base-usdc' } & BaseUsdcAdapterOptions)\n | ({ type: 'btc' } & BtcAdapterOptions)\n | ({ type: 'stripe' } & StripeAdapterOptions);\n\nexport async function createPaymentBackend(\n options: PaymentBackendOptions,\n): Promise<PaymentBackend> {\n if (!options || typeof options !== 'object' || Array.isArray(options)) {\n throw new PaymentConfigurationError(\n 'Payment backend options must be an object.',\n );\n }\n\n const type = (options as { type?: unknown }).type;\n\n if (typeof type !== 'string' || !type.trim()) {\n throw new PaymentConfigurationError(\n 'Payment backend type must be a string.',\n );\n }\n\n const normalizedType = type.trim();\n const backendOptions = {\n ...options,\n type: normalizedType,\n } as PaymentBackendOptions;\n\n switch (backendOptions.type) {\n case 'base-usdc': {\n const { BaseUsdcAdapter } = await import('./adapters/base-usdc.js');\n return new BaseUsdcAdapter(backendOptions);\n }\n case 'btc': {\n const { BtcAdapter } = await import('./adapters/btc.js');\n return new BtcAdapter(backendOptions);\n }\n case 'stripe': {\n const { StripeAdapter } = await import('./adapters/stripe.js');\n return new StripeAdapter(backendOptions);\n }\n default:\n throw new PaymentConfigurationError(\n `Unknown payment backend type: ${normalizedType}`,\n );\n }\n}\n","/**\n * @happyvertical/payments - Multi-backend payment provider abstraction.\n *\n * The default entrypoint exports only provider contracts, shared errors, and\n * the dynamic factory. Adapter implementations live behind subpath exports:\n * `@happyvertical/payments/base-usdc`, `@happyvertical/payments/btc`,\n * `@happyvertical/payments/btcpay` (BTCPay Greenfield client), and\n * `@happyvertical/payments/stripe`.\n */\n\nexport * from './errors.js';\nexport * from './factory.js';\nexport * from './types.js';\n\n/** @internal */\nexport const PACKAGE_VERSION_INITIALIZED = true;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/factory.ts","../src/index.ts"],"sourcesContent":["import type { BaseUsdcAdapterOptions } from './adapters/base-usdc.js';\nimport type { BtcAdapterOptions } from './adapters/btc.js';\nimport type { StripeAdapterOptions } from './adapters/stripe.js';\nimport { PaymentConfigurationError } from './errors.js';\nimport type { PaymentBackend } from './types.js';\n\nexport type PaymentBackendOptions =\n | ({ type: 'base-usdc' } & BaseUsdcAdapterOptions)\n | ({ type: 'btc' } & BtcAdapterOptions)\n | ({ type: 'stripe' } & StripeAdapterOptions);\n\nexport async function createPaymentBackend(\n options: PaymentBackendOptions,\n): Promise<PaymentBackend> {\n if (!options || typeof options !== 'object' || Array.isArray(options)) {\n throw new PaymentConfigurationError(\n 'Payment backend options must be an object.',\n );\n }\n\n const type = (options as { type?: unknown }).type;\n\n if (typeof type !== 'string' || !type.trim()) {\n throw new PaymentConfigurationError(\n 'Payment backend type must be a string.',\n );\n }\n\n const normalizedType = type.trim();\n const backendOptions = {\n ...options,\n type: normalizedType,\n } as PaymentBackendOptions;\n\n switch (backendOptions.type) {\n case 'base-usdc': {\n const { BaseUsdcAdapter } = await import('./adapters/base-usdc.js');\n return new BaseUsdcAdapter(backendOptions);\n }\n case 'btc': {\n const { BtcAdapter } = await import('./adapters/btc.js');\n return new BtcAdapter(backendOptions);\n }\n case 'stripe': {\n const { StripeAdapter } = await import('./adapters/stripe.js');\n return new StripeAdapter(backendOptions);\n }\n default:\n throw new PaymentConfigurationError(\n `Unknown payment backend type: ${normalizedType}`,\n );\n }\n}\n","/**\n * @happyvertical/payments - Multi-backend payment provider abstraction.\n *\n * The default entrypoint exports only provider contracts, shared errors, and\n * the dynamic factory. Adapter implementations live behind subpath exports:\n * `@happyvertical/payments/base-usdc`, `@happyvertical/payments/btc`,\n * `@happyvertical/payments/btcpay` (BTCPay Greenfield client), and\n * `@happyvertical/payments/stripe`.\n */\n\nexport * from './checkout-gateway.js';\nexport * from './errors.js';\nexport * from './factory.js';\nexport * from './types.js';\n\n/** @internal */\nexport const PACKAGE_VERSION_INITIALIZED = true;\n"],"mappings":";;;AAWA,eAAsB,qBACpB,SACyB;CACzB,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAClE,MAAM,IAAI,0BACR,4CACF;CAGF,MAAM,OAAQ,QAA+B;CAE7C,IAAI,OAAO,SAAS,YAAY,CAAC,KAAK,KAAK,GACzC,MAAM,IAAI,0BACR,wCACF;CAGF,MAAM,iBAAiB,KAAK,KAAK;CACjC,MAAM,iBAAiB;EACrB,GAAG;EACH,MAAM;CACR;CAEA,QAAQ,eAAe,MAAvB;EACE,KAAK,aAAa;GAChB,MAAM,EAAE,oBAAoB,MAAM,OAAO;GACzC,OAAO,IAAI,gBAAgB,cAAc;EAC3C;EACA,KAAK,OAAO;GACV,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,OAAO,IAAI,WAAW,cAAc;EACtC;EACA,KAAK,UAAU;GACb,MAAM,EAAE,kBAAkB,MAAM,OAAO;GACvC,OAAO,IAAI,cAAc,cAAc;EACzC;EACA,SACE,MAAM,IAAI,0BACR,iCAAiC,gBACnC;CACJ;AACF;;;;ACpCA,IAAa,8BAA8B"}
|