@venturekit/billing 0.0.48 → 0.0.51
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 +30 -28
- package/dist/client.d.ts +15 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +21 -10
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/events.d.ts +51 -7
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +3 -3
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +51 -7
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +10 -1
- package/dist/provider.js.map +1 -1
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/{zazu → manza}/adapter.d.ts +15 -15
- package/dist/providers/manza/adapter.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/adapter.js +24 -24
- package/dist/providers/manza/adapter.js.map +1 -0
- package/dist/providers/manza/client.d.ts +76 -0
- package/dist/providers/manza/client.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/client.js +9 -9
- package/dist/providers/manza/client.js.map +1 -0
- package/dist/providers/{zazu → manza}/config.d.ts +21 -21
- package/dist/providers/manza/config.d.ts.map +1 -0
- package/dist/providers/manza/config.js +99 -0
- package/dist/providers/manza/config.js.map +1 -0
- package/dist/providers/{zazu → manza}/correlation.d.ts +7 -7
- package/dist/providers/manza/correlation.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/correlation.js +22 -22
- package/dist/providers/manza/correlation.js.map +1 -0
- package/dist/providers/manza/index.d.ts +19 -0
- package/dist/providers/manza/index.d.ts.map +1 -0
- package/dist/providers/manza/index.js +24 -0
- package/dist/providers/manza/index.js.map +1 -0
- package/dist/providers/manza/maps.d.ts +36 -0
- package/dist/providers/manza/maps.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/maps.js +4 -4
- package/dist/providers/manza/maps.js.map +1 -0
- package/dist/providers/{zazu → manza}/secrets.d.ts +15 -15
- package/dist/providers/manza/secrets.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/secrets.js +13 -13
- package/dist/providers/manza/secrets.js.map +1 -0
- package/dist/providers/{zazu → manza}/types.d.ts +65 -65
- package/dist/providers/manza/types.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/types.js +3 -3
- package/dist/providers/manza/types.js.map +1 -0
- package/dist/providers/{zazu → manza}/webhooks.d.ts +19 -19
- package/dist/providers/manza/webhooks.d.ts.map +1 -0
- package/dist/providers/{zazu → manza}/webhooks.js +57 -46
- package/dist/providers/manza/webhooks.js.map +1 -0
- package/dist/providers/mock.js +3 -3
- package/dist/providers/stripe/adapter.d.ts +28 -0
- package/dist/providers/stripe/adapter.d.ts.map +1 -0
- package/dist/providers/stripe/adapter.js +192 -0
- package/dist/providers/stripe/adapter.js.map +1 -0
- package/dist/providers/stripe/client.d.ts +26 -0
- package/dist/providers/stripe/client.d.ts.map +1 -0
- package/dist/providers/stripe/client.js +84 -0
- package/dist/providers/stripe/client.js.map +1 -0
- package/dist/providers/stripe/config.d.ts +28 -0
- package/dist/providers/stripe/config.d.ts.map +1 -0
- package/dist/providers/stripe/config.js +33 -0
- package/dist/providers/stripe/config.js.map +1 -0
- package/dist/providers/stripe/index.d.ts +13 -0
- package/dist/providers/stripe/index.d.ts.map +1 -0
- package/dist/providers/stripe/index.js +16 -0
- package/dist/providers/stripe/index.js.map +1 -0
- package/dist/providers/stripe/maps.d.ts +165 -0
- package/dist/providers/stripe/maps.d.ts.map +1 -0
- package/dist/providers/stripe/maps.js +179 -0
- package/dist/providers/stripe/maps.js.map +1 -0
- package/dist/providers/stripe/webhooks.d.ts +34 -0
- package/dist/providers/stripe/webhooks.d.ts.map +1 -0
- package/dist/providers/stripe/webhooks.js +123 -0
- package/dist/providers/stripe/webhooks.js.map +1 -0
- package/dist/providers/zazu.d.ts +9 -0
- package/dist/providers/zazu.d.ts.map +1 -0
- package/dist/providers/zazu.js +8 -0
- package/dist/providers/zazu.js.map +1 -0
- package/dist/types.d.ts +139 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/package.json +15 -7
- package/dist/providers/zazu/adapter.d.ts.map +0 -1
- package/dist/providers/zazu/adapter.js.map +0 -1
- package/dist/providers/zazu/client.d.ts +0 -76
- package/dist/providers/zazu/client.d.ts.map +0 -1
- package/dist/providers/zazu/client.js.map +0 -1
- package/dist/providers/zazu/config.d.ts.map +0 -1
- package/dist/providers/zazu/config.js +0 -90
- package/dist/providers/zazu/config.js.map +0 -1
- package/dist/providers/zazu/correlation.d.ts.map +0 -1
- package/dist/providers/zazu/correlation.js.map +0 -1
- package/dist/providers/zazu/index.d.ts +0 -19
- package/dist/providers/zazu/index.d.ts.map +0 -1
- package/dist/providers/zazu/index.js +0 -22
- package/dist/providers/zazu/index.js.map +0 -1
- package/dist/providers/zazu/maps.d.ts +0 -36
- package/dist/providers/zazu/maps.d.ts.map +0 -1
- package/dist/providers/zazu/maps.js.map +0 -1
- package/dist/providers/zazu/secrets.d.ts.map +0 -1
- package/dist/providers/zazu/secrets.js.map +0 -1
- package/dist/providers/zazu/types.d.ts.map +0 -1
- package/dist/providers/zazu/types.js.map +0 -1
- package/dist/providers/zazu/webhooks.d.ts.map +0 -1
- package/dist/providers/zazu/webhooks.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @venturekit/billing —
|
|
2
|
+
* @venturekit/billing — Manza webhook signature verification & parsing
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Manza signs every webhook with HMAC-SHA256 over
|
|
5
5
|
* `${timestamp}.${rawBody}` and sends the signature in the
|
|
6
|
-
* `X-
|
|
6
|
+
* `X-Manza-Signature` header. Verification uses a constant-time
|
|
7
7
|
* comparison to prevent timing attacks, and rejects signatures whose
|
|
8
8
|
* timestamp falls outside a tolerance window so a captured request
|
|
9
9
|
* can't be replayed indefinitely.
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* After verification, the raw payload is parsed and normalized into a
|
|
12
12
|
* {@link PaymentEvent} (canonical, provider-agnostic shape) so the
|
|
13
13
|
* application can publish it to its event bus without knowing it came
|
|
14
|
-
* from
|
|
14
|
+
* from Manza.
|
|
15
15
|
*
|
|
16
16
|
* Failures are split by cause: {@link WebhookSignatureError} means the
|
|
17
|
-
* request isn't provably from
|
|
17
|
+
* request isn't provably from Manza (auth failure), while
|
|
18
18
|
* {@link WebhookPayloadError} means it is authentic but unusable.
|
|
19
19
|
* Callers must map them to different HTTP statuses — answering 401 to
|
|
20
|
-
* an authentic-but-unmapped event makes
|
|
20
|
+
* an authentic-but-unmapped event makes Manza redeliver it forever.
|
|
21
21
|
*/
|
|
22
22
|
import type { PaymentEvent } from '../../events.js';
|
|
23
23
|
import type { WebhookRequest } from '../../provider.js';
|
|
@@ -25,39 +25,39 @@ import type { WebhookRequest } from '../../provider.js';
|
|
|
25
25
|
* Default replay tolerance: a signature more than five minutes old (or
|
|
26
26
|
* five minutes in the future, allowing for clock skew) is rejected.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
28
|
+
* Manza's docs describe the HMAC construction but do not mandate a
|
|
29
29
|
* freshness check, so this is our own hardening — five minutes is the
|
|
30
|
-
* de-facto standard (Stripe, Slack, GitHub). Note that
|
|
30
|
+
* de-facto standard (Stripe, Slack, GitHub). Note that Manza retries a
|
|
31
31
|
* failed delivery for ~28 hours, so the window must stay comfortably
|
|
32
32
|
* wider than a single delivery attempt.
|
|
33
33
|
*/
|
|
34
34
|
export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
35
35
|
/**
|
|
36
|
-
* Verify a
|
|
36
|
+
* Verify a Manza webhook signature. Throws {@link WebhookSignatureError}
|
|
37
37
|
* if the signature, timestamp, or secret is missing, the timestamp is
|
|
38
38
|
* outside the tolerance window, or the signature does not match.
|
|
39
39
|
*
|
|
40
40
|
* @param secret - The endpoint's signing secret.
|
|
41
|
-
* @param timestamp - `X-
|
|
41
|
+
* @param timestamp - `X-Manza-Timestamp` header value (Unix seconds).
|
|
42
42
|
* @param rawBody - The raw request body exactly as received.
|
|
43
|
-
* @param signature - `X-
|
|
43
|
+
* @param signature - `X-Manza-Signature` header value (hex digest).
|
|
44
44
|
* @param toleranceSeconds - Maximum accepted signature age. Pass `0` to
|
|
45
45
|
* disable the freshness check — only appropriate when replaying
|
|
46
46
|
* captured fixtures in tests.
|
|
47
47
|
*/
|
|
48
|
-
export declare function
|
|
48
|
+
export declare function verifyManzaSignature(secret: string, timestamp: string, rawBody: string, signature: string, toleranceSeconds?: number): void;
|
|
49
49
|
/**
|
|
50
|
-
* Parse and normalize a verified
|
|
50
|
+
* Parse and normalize a verified Manza webhook into a
|
|
51
51
|
* {@link PaymentEvent}. This does NOT verify the signature — call
|
|
52
|
-
* {@link
|
|
52
|
+
* {@link verifyManzaSignature} first (or use {@link handleManzaWebhook}
|
|
53
53
|
* which does both).
|
|
54
54
|
*
|
|
55
55
|
* Throws {@link WebhookPayloadError} if the payload is malformed, the
|
|
56
56
|
* event id is absent, or the event type is unknown.
|
|
57
57
|
*/
|
|
58
|
-
export declare function
|
|
59
|
-
/** Options for {@link
|
|
60
|
-
export interface
|
|
58
|
+
export declare function parseManzaWebhook(rawBody: string, headers: Record<string, string>): PaymentEvent;
|
|
59
|
+
/** Options for {@link handleManzaWebhook}. */
|
|
60
|
+
export interface HandleManzaWebhookOptions {
|
|
61
61
|
/**
|
|
62
62
|
* Maximum accepted signature age in seconds. Defaults to
|
|
63
63
|
* {@link DEFAULT_WEBHOOK_TOLERANCE_SECONDS}; `0` disables the check.
|
|
@@ -65,9 +65,9 @@ export interface HandleZazuWebhookOptions {
|
|
|
65
65
|
toleranceSeconds?: number;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Verify the
|
|
68
|
+
* Verify the Manza webhook signature and parse the payload into a
|
|
69
69
|
* normalized {@link PaymentEvent}. This is what the adapter's
|
|
70
70
|
* `handleWebhookEvent` calls.
|
|
71
71
|
*/
|
|
72
|
-
export declare function
|
|
72
|
+
export declare function handleManzaWebhook(secret: string | undefined, request: WebhookRequest, options?: HandleManzaWebhookOptions): PaymentEvent;
|
|
73
73
|
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/providers/manza/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAiBxD;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,gBAAgB,GAAE,MAA0C,GAC3D,IAAI,CAoCN;AAgDD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CA+HhG;AAMD,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,yBAAyB,GAClC,YAAY,CAad"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @venturekit/billing —
|
|
2
|
+
* @venturekit/billing — Manza webhook signature verification & parsing
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Manza signs every webhook with HMAC-SHA256 over
|
|
5
5
|
* `${timestamp}.${rawBody}` and sends the signature in the
|
|
6
|
-
* `X-
|
|
6
|
+
* `X-Manza-Signature` header. Verification uses a constant-time
|
|
7
7
|
* comparison to prevent timing attacks, and rejects signatures whose
|
|
8
8
|
* timestamp falls outside a tolerance window so a captured request
|
|
9
9
|
* can't be replayed indefinitely.
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
* After verification, the raw payload is parsed and normalized into a
|
|
12
12
|
* {@link PaymentEvent} (canonical, provider-agnostic shape) so the
|
|
13
13
|
* application can publish it to its event bus without knowing it came
|
|
14
|
-
* from
|
|
14
|
+
* from Manza.
|
|
15
15
|
*
|
|
16
16
|
* Failures are split by cause: {@link WebhookSignatureError} means the
|
|
17
|
-
* request isn't provably from
|
|
17
|
+
* request isn't provably from Manza (auth failure), while
|
|
18
18
|
* {@link WebhookPayloadError} means it is authentic but unusable.
|
|
19
19
|
* Callers must map them to different HTTP statuses — answering 401 to
|
|
20
|
-
* an authentic-but-unmapped event makes
|
|
20
|
+
* an authentic-but-unmapped event makes Manza redeliver it forever.
|
|
21
21
|
*/
|
|
22
|
-
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
22
|
+
import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
|
|
23
23
|
import { WebhookPayloadError, WebhookSignatureError } from '../../errors.js';
|
|
24
24
|
import { mapCheckoutTransaction, money, nullToUndefined, } from './maps.js';
|
|
25
25
|
import { decodeCheckoutCorrelation, decodePaymentLinkCorrelation, decodeTransferCorrelation, } from './correlation.js';
|
|
@@ -30,32 +30,32 @@ import { decodeCheckoutCorrelation, decodePaymentLinkCorrelation, decodeTransfer
|
|
|
30
30
|
* Default replay tolerance: a signature more than five minutes old (or
|
|
31
31
|
* five minutes in the future, allowing for clock skew) is rejected.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* Manza's docs describe the HMAC construction but do not mandate a
|
|
34
34
|
* freshness check, so this is our own hardening — five minutes is the
|
|
35
|
-
* de-facto standard (Stripe, Slack, GitHub). Note that
|
|
35
|
+
* de-facto standard (Stripe, Slack, GitHub). Note that Manza retries a
|
|
36
36
|
* failed delivery for ~28 hours, so the window must stay comfortably
|
|
37
37
|
* wider than a single delivery attempt.
|
|
38
38
|
*/
|
|
39
39
|
export const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
40
40
|
/**
|
|
41
|
-
* Verify a
|
|
41
|
+
* Verify a Manza webhook signature. Throws {@link WebhookSignatureError}
|
|
42
42
|
* if the signature, timestamp, or secret is missing, the timestamp is
|
|
43
43
|
* outside the tolerance window, or the signature does not match.
|
|
44
44
|
*
|
|
45
45
|
* @param secret - The endpoint's signing secret.
|
|
46
|
-
* @param timestamp - `X-
|
|
46
|
+
* @param timestamp - `X-Manza-Timestamp` header value (Unix seconds).
|
|
47
47
|
* @param rawBody - The raw request body exactly as received.
|
|
48
|
-
* @param signature - `X-
|
|
48
|
+
* @param signature - `X-Manza-Signature` header value (hex digest).
|
|
49
49
|
* @param toleranceSeconds - Maximum accepted signature age. Pass `0` to
|
|
50
50
|
* disable the freshness check — only appropriate when replaying
|
|
51
51
|
* captured fixtures in tests.
|
|
52
52
|
*/
|
|
53
|
-
export function
|
|
53
|
+
export function verifyManzaSignature(secret, timestamp, rawBody, signature, toleranceSeconds = DEFAULT_WEBHOOK_TOLERANCE_SECONDS) {
|
|
54
54
|
if (!secret) {
|
|
55
|
-
throw new WebhookSignatureError('
|
|
55
|
+
throw new WebhookSignatureError('Manza webhook secret is not configured.');
|
|
56
56
|
}
|
|
57
57
|
if (!timestamp || !signature) {
|
|
58
|
-
throw new WebhookSignatureError('Missing X-
|
|
58
|
+
throw new WebhookSignatureError('Missing X-Manza-Timestamp or X-Manza-Signature header.');
|
|
59
59
|
}
|
|
60
60
|
// Freshness first: the timestamp is inside the signed payload, so an
|
|
61
61
|
// attacker replaying a captured request keeps a valid signature
|
|
@@ -63,11 +63,11 @@ export function verifyZazuSignature(secret, timestamp, rawBody, signature, toler
|
|
|
63
63
|
if (toleranceSeconds > 0) {
|
|
64
64
|
const signedAtSeconds = Number(timestamp);
|
|
65
65
|
if (!Number.isFinite(signedAtSeconds)) {
|
|
66
|
-
throw new WebhookSignatureError(`Malformed X-
|
|
66
|
+
throw new WebhookSignatureError(`Malformed X-Manza-Timestamp header: "${timestamp}" is not a Unix timestamp.`);
|
|
67
67
|
}
|
|
68
68
|
const ageSeconds = Math.abs(Date.now() / 1000 - signedAtSeconds);
|
|
69
69
|
if (ageSeconds > toleranceSeconds) {
|
|
70
|
-
throw new WebhookSignatureError(`
|
|
70
|
+
throw new WebhookSignatureError(`Manza webhook timestamp is outside the ${toleranceSeconds}s tolerance ` +
|
|
71
71
|
`(off by ${Math.round(ageSeconds)}s) — possible replay.`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -77,7 +77,7 @@ export function verifyZazuSignature(secret, timestamp, rawBody, signature, toler
|
|
|
77
77
|
const a = Buffer.from(signature);
|
|
78
78
|
const b = Buffer.from(expected);
|
|
79
79
|
if (a.length !== b.length || !timingSafeEqual(a, b)) {
|
|
80
|
-
throw new WebhookSignatureError('Invalid
|
|
80
|
+
throw new WebhookSignatureError('Invalid Manza webhook signature.');
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
// ---------------------------------------------------------------------------
|
|
@@ -86,7 +86,7 @@ export function verifyZazuSignature(secret, timestamp, rawBody, signature, toler
|
|
|
86
86
|
/**
|
|
87
87
|
* Lower-case every header name once. API Gateway v2 already does this,
|
|
88
88
|
* but REST (v1) events, direct Lambda invocations, and tests do not —
|
|
89
|
-
* and a missed `X-
|
|
89
|
+
* and a missed `X-Manza-Signature` surfaces as a confusing "missing
|
|
90
90
|
* header" rejection. Same normalization the runtime applies in
|
|
91
91
|
* `getRequestHost`.
|
|
92
92
|
*/
|
|
@@ -98,44 +98,55 @@ function normalizeHeaders(headers) {
|
|
|
98
98
|
}
|
|
99
99
|
return normalized;
|
|
100
100
|
}
|
|
101
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Read a header from an already-normalized bag: `X-Manza-<name>`, else the
|
|
103
|
+
* pre-rename `X-Zazu-<name>` — deliveries may carry either while the
|
|
104
|
+
* provider's rename rolls out.
|
|
105
|
+
*/
|
|
102
106
|
function header(headers, name) {
|
|
103
|
-
return headers[name];
|
|
107
|
+
return headers[`x-manza-${name}`] ?? headers[`x-zazu-${name}`];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Deduplication key from SIGNED material. The signature covers
|
|
111
|
+
* `${timestamp}.${rawBody}` and nothing else, so an id taken from a header
|
|
112
|
+
* could be rewritten on a replayed delivery to slip past deduplication.
|
|
113
|
+
* The body (event, `created_at`, data) is identical across the provider's
|
|
114
|
+
* retries of one event, so its digest is a stable key.
|
|
115
|
+
*/
|
|
116
|
+
function eventIdOf(rawBody) {
|
|
117
|
+
return `manza_${createHash('sha256').update(rawBody, 'utf8').digest('hex').slice(0, 32)}`;
|
|
104
118
|
}
|
|
105
119
|
// ---------------------------------------------------------------------------
|
|
106
120
|
// Parsing & normalization
|
|
107
121
|
// ---------------------------------------------------------------------------
|
|
108
122
|
/**
|
|
109
|
-
* Parse and normalize a verified
|
|
123
|
+
* Parse and normalize a verified Manza webhook into a
|
|
110
124
|
* {@link PaymentEvent}. This does NOT verify the signature — call
|
|
111
|
-
* {@link
|
|
125
|
+
* {@link verifyManzaSignature} first (or use {@link handleManzaWebhook}
|
|
112
126
|
* which does both).
|
|
113
127
|
*
|
|
114
128
|
* Throws {@link WebhookPayloadError} if the payload is malformed, the
|
|
115
129
|
* event id is absent, or the event type is unknown.
|
|
116
130
|
*/
|
|
117
|
-
export function
|
|
131
|
+
export function parseManzaWebhook(rawBody, headers) {
|
|
118
132
|
const normalized = normalizeHeaders(headers);
|
|
119
133
|
let payload;
|
|
120
134
|
try {
|
|
121
135
|
payload = JSON.parse(rawBody);
|
|
122
136
|
}
|
|
123
137
|
catch (cause) {
|
|
124
|
-
throw new WebhookPayloadError('Malformed
|
|
138
|
+
throw new WebhookPayloadError('Malformed Manza webhook body (invalid JSON).', cause);
|
|
125
139
|
}
|
|
126
|
-
|
|
140
|
+
// The type comes from the signed body only: an unsigned header must not
|
|
141
|
+
// be able to turn one event into another.
|
|
142
|
+
const eventType = payload.event;
|
|
127
143
|
if (!eventType) {
|
|
128
|
-
throw new WebhookPayloadError('
|
|
144
|
+
throw new WebhookPayloadError('Manza webhook missing event type.');
|
|
129
145
|
}
|
|
130
|
-
|
|
146
|
+
// Informational (tracing); never a key — it is not signed.
|
|
147
|
+
const deliveryId = header(normalized, 'delivery-id') ?? header(normalized, 'event-id');
|
|
131
148
|
// `eventId` is the consumer's deduplication key (see events.ts).
|
|
132
|
-
|
|
133
|
-
// silently drop real events, so fall back to the delivery id and
|
|
134
|
-
// refuse the payload if neither is present.
|
|
135
|
-
const eventId = header(normalized, 'x-zazu-event-id') ?? deliveryId;
|
|
136
|
-
if (!eventId) {
|
|
137
|
-
throw new WebhookPayloadError('Zazu webhook missing X-Zazu-Event-Id and X-Zazu-Delivery-Id — cannot deduplicate.');
|
|
138
|
-
}
|
|
149
|
+
const eventId = eventIdOf(rawBody);
|
|
139
150
|
const createdAt = payload.created_at ?? new Date().toISOString();
|
|
140
151
|
switch (eventType) {
|
|
141
152
|
case 'checkout_session.completed': {
|
|
@@ -145,7 +156,7 @@ export function parseZazuWebhook(rawBody, headers) {
|
|
|
145
156
|
}
|
|
146
157
|
return {
|
|
147
158
|
type: 'checkout_session.completed',
|
|
148
|
-
provider: '
|
|
159
|
+
provider: 'manza',
|
|
149
160
|
eventId,
|
|
150
161
|
deliveryId,
|
|
151
162
|
createdAt,
|
|
@@ -170,7 +181,7 @@ export function parseZazuWebhook(rawBody, headers) {
|
|
|
170
181
|
throw new WebhookPayloadError('payment_link.paid missing payment_link data.');
|
|
171
182
|
return {
|
|
172
183
|
type: 'payment_link.paid',
|
|
173
|
-
provider: '
|
|
184
|
+
provider: 'manza',
|
|
174
185
|
eventId,
|
|
175
186
|
deliveryId,
|
|
176
187
|
createdAt,
|
|
@@ -201,7 +212,7 @@ export function parseZazuWebhook(rawBody, headers) {
|
|
|
201
212
|
throw new WebhookPayloadError('transfer.executed missing transfer data.');
|
|
202
213
|
return {
|
|
203
214
|
type: 'transfer.executed',
|
|
204
|
-
provider: '
|
|
215
|
+
provider: 'manza',
|
|
205
216
|
eventId,
|
|
206
217
|
deliveryId,
|
|
207
218
|
createdAt,
|
|
@@ -228,7 +239,7 @@ export function parseZazuWebhook(rawBody, headers) {
|
|
|
228
239
|
case 'test.ping': {
|
|
229
240
|
return {
|
|
230
241
|
type: 'test.ping',
|
|
231
|
-
provider: '
|
|
242
|
+
provider: 'manza',
|
|
232
243
|
eventId,
|
|
233
244
|
deliveryId,
|
|
234
245
|
createdAt,
|
|
@@ -240,20 +251,20 @@ export function parseZazuWebhook(rawBody, headers) {
|
|
|
240
251
|
};
|
|
241
252
|
}
|
|
242
253
|
default: {
|
|
243
|
-
throw new WebhookPayloadError(`Unknown
|
|
254
|
+
throw new WebhookPayloadError(`Unknown Manza webhook event type: "${eventType}".`);
|
|
244
255
|
}
|
|
245
256
|
}
|
|
246
257
|
}
|
|
247
258
|
/**
|
|
248
|
-
* Verify the
|
|
259
|
+
* Verify the Manza webhook signature and parse the payload into a
|
|
249
260
|
* normalized {@link PaymentEvent}. This is what the adapter's
|
|
250
261
|
* `handleWebhookEvent` calls.
|
|
251
262
|
*/
|
|
252
|
-
export function
|
|
263
|
+
export function handleManzaWebhook(secret, request, options) {
|
|
253
264
|
const normalized = normalizeHeaders(request.headers);
|
|
254
|
-
const timestamp = header(normalized, '
|
|
255
|
-
const signature = header(normalized, '
|
|
256
|
-
|
|
257
|
-
return
|
|
265
|
+
const timestamp = header(normalized, 'timestamp') ?? '';
|
|
266
|
+
const signature = header(normalized, 'signature') ?? '';
|
|
267
|
+
verifyManzaSignature(secret ?? '', timestamp, request.rawBody, signature, options?.toleranceSeconds ?? DEFAULT_WEBHOOK_TOLERANCE_SECONDS);
|
|
268
|
+
return parseManzaWebhook(request.rawBody, normalized);
|
|
258
269
|
}
|
|
259
270
|
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../../src/providers/manza/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG7E,OAAO,EACL,sBAAsB,EACtB,KAAK,EACL,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAG1B,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,SAAiB,EACjB,OAAe,EACf,SAAiB,EACjB,mBAA2B,iCAAiC;IAE5D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,qBAAqB,CAAC,yCAAyC,CAAC,CAAC;IAC7E,CAAC;IACD,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,qBAAqB,CAAC,wDAAwD,CAAC,CAAC;IAC5F,CAAC;IAED,qEAAqE;IACrE,gEAAgE;IAChE,0CAA0C;IAC1C,IAAI,gBAAgB,GAAG,CAAC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CAAC;AACH,CAAC;AAeD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAA0B,EAC1B,OAAuB,EACvB,OAAmC;IAEnC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;IAExD,oBAAoB,CAClB,MAAM,IAAI,EAAE,EACZ,SAAS,EACT,OAAO,CAAC,OAAO,EACf,SAAS,EACT,OAAO,EAAE,gBAAgB,IAAI,iCAAiC,CAC/D,CAAC;IACF,OAAO,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/providers/mock.js
CHANGED
|
@@ -41,7 +41,7 @@ function paginate(items, limit = 25) {
|
|
|
41
41
|
return { data: items.slice(0, limit), hasMore: items.length > limit };
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Reserved metadata key holding the caller's reference. Mirrors the
|
|
44
|
+
* Reserved metadata key holding the caller's reference. Mirrors the Manza
|
|
45
45
|
* adapter's convention without importing it — the mock must not depend on
|
|
46
46
|
* a real provider's module.
|
|
47
47
|
*/
|
|
@@ -155,10 +155,10 @@ export function createMockProvider(options) {
|
|
|
155
155
|
calls: state.calls,
|
|
156
156
|
state,
|
|
157
157
|
/**
|
|
158
|
-
* The mock supports correlation fully on every flow — unlike
|
|
158
|
+
* The mock supports correlation fully on every flow — unlike Manza,
|
|
159
159
|
* whose payment-link and transfer channels hold a single value. Tests
|
|
160
160
|
* that need to exercise the restricted behaviour should assert against
|
|
161
|
-
* the
|
|
161
|
+
* the Manza adapter, not this one.
|
|
162
162
|
*/
|
|
163
163
|
correlationSupport() {
|
|
164
164
|
return { reference: true, metadata: true, channel: 'metadata' };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe adapter
|
|
3
|
+
*
|
|
4
|
+
* Core flows (Checkout sessions, payment links, webhooks) plus three
|
|
5
|
+
* optional capabilities: customers, saved cards (SetupIntents for "card
|
|
6
|
+
* upfront", PaymentIntents for one-off charges) and provider-run
|
|
7
|
+
* subscriptions (Stripe charges every period, retries failed payments and
|
|
8
|
+
* emails the receipts). Prices are created inline against a product
|
|
9
|
+
* (`price_data`), so there is no Stripe price catalogue to keep in sync
|
|
10
|
+
* with yours.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createStripeAdapter } from '@venturekit/billing/providers/stripe';
|
|
14
|
+
* const stripe = createStripeAdapter(); // STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET
|
|
15
|
+
* const intent = await stripe.createSetupIntent({ customerId });
|
|
16
|
+
* // → confirm intent.clientSecret in the browser with Stripe Elements
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import type { CardPaymentCapable, CustomerCapable, PaymentProvider, SubscriptionCapable } from '../../provider.js';
|
|
20
|
+
import type { Money } from '../../types.js';
|
|
21
|
+
import { type StripeConfig } from './config.js';
|
|
22
|
+
export type StripeAdapter = PaymentProvider & CustomerCapable & CardPaymentCapable & SubscriptionCapable & {
|
|
23
|
+
readonly publishableKey: string | null;
|
|
24
|
+
};
|
|
25
|
+
export declare function createStripeAdapter(overrides?: Partial<StripeConfig>): StripeAdapter;
|
|
26
|
+
/** The money a Stripe minor-unit amount stands for (exported for apps reading raw events). */
|
|
27
|
+
export declare const stripeAmount: (minor: number, currency: string) => Money;
|
|
28
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/providers/stripe/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAkB,MAAM,mBAAmB,CAAC;AACnI,OAAO,KAAK,EAAoE,KAAK,EAAqC,MAAM,gBAAgB,CAAC;AAEjJ,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAsBrE,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,eAAe,GAAG,kBAAkB,GAAG,mBAAmB,GAAG;IAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAOtJ,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,aAAa,CAsLxF;AAED,8FAA8F;AAC9F,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,UAAU,MAAM,KAAG,KAAmC,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit/billing — Stripe adapter
|
|
3
|
+
*
|
|
4
|
+
* Core flows (Checkout sessions, payment links, webhooks) plus three
|
|
5
|
+
* optional capabilities: customers, saved cards (SetupIntents for "card
|
|
6
|
+
* upfront", PaymentIntents for one-off charges) and provider-run
|
|
7
|
+
* subscriptions (Stripe charges every period, retries failed payments and
|
|
8
|
+
* emails the receipts). Prices are created inline against a product
|
|
9
|
+
* (`price_data`), so there is no Stripe price catalogue to keep in sync
|
|
10
|
+
* with yours.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createStripeAdapter } from '@venturekit/billing/providers/stripe';
|
|
14
|
+
* const stripe = createStripeAdapter(); // STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET
|
|
15
|
+
* const intent = await stripe.createSetupIntent({ customerId });
|
|
16
|
+
* // → confirm intent.clientSecret in the browser with Stripe Elements
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { MissingConfigError } from '../../errors.js';
|
|
20
|
+
import { createStripeHttpClient } from './client.js';
|
|
21
|
+
import { resolveStripeConfig } from './config.js';
|
|
22
|
+
import { customerParams, mapCheckoutSession, mapCustomer, mapInvoice, mapPaymentIntent, mapPaymentLink, mapPaymentMethod, mapSetupIntent, mapSubscription, metadataOf, priceData, toMinor, unix, fromMinor, } from './maps.js';
|
|
23
|
+
import { handleStripeWebhook } from './webhooks.js';
|
|
24
|
+
export function createStripeAdapter(overrides = {}) {
|
|
25
|
+
const config = resolveStripeConfig(overrides);
|
|
26
|
+
const http = createStripeHttpClient(config);
|
|
27
|
+
const sub = async (path, body) => mapSubscription(await http.post(path, body));
|
|
28
|
+
const getSubscription = async (id) => mapSubscription(await http.get(`/subscriptions/${encodeURIComponent(id)}`));
|
|
29
|
+
return {
|
|
30
|
+
name: 'stripe',
|
|
31
|
+
publishableKey: config.publishableKey ?? null,
|
|
32
|
+
correlationSupport(flow) {
|
|
33
|
+
return flow === 'transfer' ? { reference: false, metadata: false, channel: 'none' } : { reference: true, metadata: true, channel: 'metadata' };
|
|
34
|
+
},
|
|
35
|
+
// ─── Checkout sessions (one-off payments on Stripe's hosted page) ──
|
|
36
|
+
async createCheckoutSession(input) {
|
|
37
|
+
const raw = await http.post('/checkout/sessions', {
|
|
38
|
+
mode: 'payment',
|
|
39
|
+
success_url: input.successUrl,
|
|
40
|
+
cancel_url: input.cancelUrl,
|
|
41
|
+
customer_email: input.customerEmail,
|
|
42
|
+
client_reference_id: input.correlation?.reference,
|
|
43
|
+
metadata: metadataOf(input.correlation),
|
|
44
|
+
payment_intent_data: { metadata: metadataOf(input.correlation), description: input.description },
|
|
45
|
+
line_items: [{ quantity: 1, price_data: { currency: input.amount.currency.toLowerCase(), unit_amount: toMinor(input.amount), product_data: { name: input.description ?? 'Payment' } } }],
|
|
46
|
+
...(input.expiresAt ? { expires_at: unix(input.expiresAt) } : {}),
|
|
47
|
+
});
|
|
48
|
+
return mapCheckoutSession(raw);
|
|
49
|
+
},
|
|
50
|
+
async getCheckoutSession(id) {
|
|
51
|
+
return mapCheckoutSession(await http.get(`/checkout/sessions/${encodeURIComponent(id)}`));
|
|
52
|
+
},
|
|
53
|
+
// ─── Payment links (reusable; a price created inline) ────────────
|
|
54
|
+
async createPaymentLink(input) {
|
|
55
|
+
const price = await http.post('/prices', { currency: input.amount.currency.toLowerCase(), unit_amount: toMinor(input.amount), product_data: { name: input.description ?? 'Payment' } });
|
|
56
|
+
const raw = await http.post('/payment_links', {
|
|
57
|
+
line_items: [{ price: price.id, quantity: 1 }],
|
|
58
|
+
metadata: metadataOf(input.correlation),
|
|
59
|
+
payment_intent_data: { metadata: metadataOf(input.correlation) },
|
|
60
|
+
...(input.redirectUrl ? { after_completion: { type: 'redirect', redirect: { url: input.redirectUrl } } } : {}),
|
|
61
|
+
});
|
|
62
|
+
return mapPaymentLink(raw, input.amount);
|
|
63
|
+
},
|
|
64
|
+
async getPaymentLink(id) {
|
|
65
|
+
const [raw, items] = await Promise.all([
|
|
66
|
+
http.get(`/payment_links/${encodeURIComponent(id)}`),
|
|
67
|
+
http.get(`/payment_links/${encodeURIComponent(id)}/line_items`),
|
|
68
|
+
]);
|
|
69
|
+
const first = items.data[0];
|
|
70
|
+
return mapPaymentLink(raw, first ? fromMinor(first.amount_total, first.currency) : { amount: '0.00', currency: 'USD' });
|
|
71
|
+
},
|
|
72
|
+
async listPaymentLinks(params) {
|
|
73
|
+
const page = await http.get('/payment_links', { limit: params?.limit ?? 20, starting_after: params?.cursor });
|
|
74
|
+
return { data: page.data.map((l) => mapPaymentLink(l, { amount: '0.00', currency: 'USD' })), hasMore: page.has_more, ...(page.has_more && page.data.length ? { nextCursor: page.data.at(-1).id } : {}) };
|
|
75
|
+
},
|
|
76
|
+
async cancelPaymentLink(id) {
|
|
77
|
+
const raw = await http.post(`/payment_links/${encodeURIComponent(id)}`, { active: false });
|
|
78
|
+
return mapPaymentLink(raw, { amount: '0.00', currency: 'USD' });
|
|
79
|
+
},
|
|
80
|
+
// ─── Webhooks ────────────────────────────────────────────────────
|
|
81
|
+
async handleWebhookEvent(request) {
|
|
82
|
+
if (!config.webhookSecret)
|
|
83
|
+
throw new MissingConfigError('STRIPE_WEBHOOK_SECRET', 'Set the webhook endpoint’s signing secret (whsec_…).');
|
|
84
|
+
return handleStripeWebhook(request, { secret: config.webhookSecret, toleranceSeconds: config.webhookToleranceSeconds });
|
|
85
|
+
},
|
|
86
|
+
// ─── Customers ───────────────────────────────────────────────────
|
|
87
|
+
async createCustomer(input) {
|
|
88
|
+
return mapCustomer(await http.post('/customers', customerParams(input)));
|
|
89
|
+
},
|
|
90
|
+
async getCustomer(id) {
|
|
91
|
+
return mapCustomer(await http.get(`/customers/${encodeURIComponent(id)}`));
|
|
92
|
+
},
|
|
93
|
+
async updateCustomer(id, input) {
|
|
94
|
+
return mapCustomer(await http.post(`/customers/${encodeURIComponent(id)}`, customerParams(input)));
|
|
95
|
+
},
|
|
96
|
+
// ─── Saved cards & one-off charges ───────────────────────────────
|
|
97
|
+
async createSetupIntent(input) {
|
|
98
|
+
return mapSetupIntent(await http.post('/setup_intents', { customer: input.customerId, usage: 'off_session', payment_method_types: ['card'], metadata: input.metadata }, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
99
|
+
},
|
|
100
|
+
async getSetupIntent(id) {
|
|
101
|
+
return mapSetupIntent(await http.get(`/setup_intents/${encodeURIComponent(id)}`));
|
|
102
|
+
},
|
|
103
|
+
async createPaymentIntent(input) {
|
|
104
|
+
return mapPaymentIntent(await http.post('/payment_intents', {
|
|
105
|
+
amount: toMinor(input.amount),
|
|
106
|
+
currency: input.amount.currency.toLowerCase(),
|
|
107
|
+
customer: input.customerId,
|
|
108
|
+
payment_method: input.paymentMethodId,
|
|
109
|
+
confirm: input.confirm,
|
|
110
|
+
off_session: input.confirm ? input.offSession : undefined,
|
|
111
|
+
description: input.description,
|
|
112
|
+
receipt_email: input.receiptEmail,
|
|
113
|
+
metadata: metadataOf(input.correlation),
|
|
114
|
+
// Card only: no redirect-based methods to come back from.
|
|
115
|
+
...(input.paymentMethodId || input.confirm ? { payment_method_types: ['card'] } : { automatic_payment_methods: { enabled: true, allow_redirects: 'never' } }),
|
|
116
|
+
}, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
117
|
+
},
|
|
118
|
+
async getPaymentIntent(id) {
|
|
119
|
+
return mapPaymentIntent(await http.get(`/payment_intents/${encodeURIComponent(id)}`));
|
|
120
|
+
},
|
|
121
|
+
async getPaymentMethod(id) {
|
|
122
|
+
return mapPaymentMethod(await http.get(`/payment_methods/${encodeURIComponent(id)}`));
|
|
123
|
+
},
|
|
124
|
+
async setDefaultPaymentMethod(customerId, paymentMethodId) {
|
|
125
|
+
await http.post(`/customers/${encodeURIComponent(customerId)}`, { invoice_settings: { default_payment_method: paymentMethodId } });
|
|
126
|
+
},
|
|
127
|
+
// ─── Subscriptions ───────────────────────────────────────────────
|
|
128
|
+
async ensureProduct({ id, name }) {
|
|
129
|
+
try {
|
|
130
|
+
return await http.get(`/products/${encodeURIComponent(id)}`);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e.status !== 404)
|
|
134
|
+
throw e;
|
|
135
|
+
return http.post('/products', { id, name }, { idempotencyKey: `vk-product-${id}` });
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
async createSubscription(input) {
|
|
139
|
+
return mapSubscription(await http.post('/subscriptions', {
|
|
140
|
+
customer: input.customerId,
|
|
141
|
+
items: [{ price_data: priceData(input.price) }],
|
|
142
|
+
...(input.trialEnd ? { trial_end: unix(input.trialEnd) } : input.trialDays ? { trial_period_days: input.trialDays } : {}),
|
|
143
|
+
default_payment_method: input.defaultPaymentMethodId,
|
|
144
|
+
collection_method: input.collectionMethod,
|
|
145
|
+
days_until_due: input.collectionMethod === 'send_invoice' ? (input.daysUntilDue ?? 30) : undefined,
|
|
146
|
+
metadata: metadataOf(input.correlation),
|
|
147
|
+
// No card yet (a sales-led invoice account): don't fail on the first charge.
|
|
148
|
+
payment_behavior: input.defaultPaymentMethodId || input.collectionMethod === 'send_invoice' ? undefined : 'default_incomplete',
|
|
149
|
+
...(input.trialDays || input.trialEnd ? { trial_settings: { end_behavior: { missing_payment_method: 'pause' } } } : {}),
|
|
150
|
+
}, input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}));
|
|
151
|
+
},
|
|
152
|
+
getSubscription,
|
|
153
|
+
async updateSubscription(id, input) {
|
|
154
|
+
let itemId;
|
|
155
|
+
if (input.price)
|
|
156
|
+
itemId = (await getSubscription(id)).itemId;
|
|
157
|
+
return sub(`/subscriptions/${encodeURIComponent(id)}`, {
|
|
158
|
+
...(input.price ? { items: [{ ...(itemId ? { id: itemId } : {}), price_data: priceData(input.price) }], proration_behavior: input.prorate === false ? 'none' : 'create_prorations' } : {}),
|
|
159
|
+
cancel_at_period_end: input.cancelAtPeriodEnd,
|
|
160
|
+
default_payment_method: input.defaultPaymentMethodId,
|
|
161
|
+
trial_end: input.trialEnd === 'now' ? 'now' : input.trialEnd ? unix(input.trialEnd) : undefined,
|
|
162
|
+
metadata: metadataOf(input.correlation),
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
async cancelSubscription(id, options) {
|
|
166
|
+
if (options?.atPeriodEnd)
|
|
167
|
+
return sub(`/subscriptions/${encodeURIComponent(id)}`, { cancel_at_period_end: true });
|
|
168
|
+
return mapSubscription(await http.delete(`/subscriptions/${encodeURIComponent(id)}`));
|
|
169
|
+
},
|
|
170
|
+
async createSubscriptionCheckout(input) {
|
|
171
|
+
const raw = await http.post('/checkout/sessions', {
|
|
172
|
+
mode: 'subscription',
|
|
173
|
+
success_url: input.successUrl,
|
|
174
|
+
cancel_url: input.cancelUrl,
|
|
175
|
+
customer: input.customerId,
|
|
176
|
+
customer_email: input.customerId ? undefined : input.customerEmail,
|
|
177
|
+
client_reference_id: input.correlation?.reference,
|
|
178
|
+
metadata: metadataOf(input.correlation),
|
|
179
|
+
line_items: [{ quantity: 1, price_data: priceData(input.price) }],
|
|
180
|
+
subscription_data: { metadata: metadataOf(input.correlation), ...(input.trialDays ? { trial_period_days: input.trialDays } : {}) },
|
|
181
|
+
});
|
|
182
|
+
return { id: raw.id, url: raw.url };
|
|
183
|
+
},
|
|
184
|
+
async listSubscriptionInvoices({ customerId, limit }) {
|
|
185
|
+
const page = await http.get('/invoices', { customer: customerId, limit: limit ?? 12 });
|
|
186
|
+
return page.data.map(mapInvoice);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** The money a Stripe minor-unit amount stands for (exported for apps reading raw events). */
|
|
191
|
+
export const stripeAmount = (minor, currency) => fromMinor(minor, currency);
|
|
192
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/providers/stripe/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,sBAAsB,EAAkB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,UAAU,EACV,SAAS,EACT,OAAO,EACP,IAAI,EACJ,SAAS,GAIV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AASpD,MAAM,UAAU,mBAAmB,CAAC,YAAmC,EAAE;IACvE,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,KAAK,EAAE,IAAY,EAAE,IAAgC,EAAE,EAAE,CAAC,eAAe,CAAC,MA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