@plumbus/payments-stripe 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +60 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/catalog.d.ts +14 -0
  5. package/dist/catalog.d.ts.map +1 -0
  6. package/dist/catalog.js +286 -0
  7. package/dist/catalog.js.map +1 -0
  8. package/dist/charges.d.ts +64 -0
  9. package/dist/charges.d.ts.map +1 -0
  10. package/dist/charges.js +339 -0
  11. package/dist/charges.js.map +1 -0
  12. package/dist/config-rules.d.ts +7 -0
  13. package/dist/config-rules.d.ts.map +1 -0
  14. package/dist/config-rules.js +87 -0
  15. package/dist/config-rules.js.map +1 -0
  16. package/dist/diagnose.d.ts +17 -0
  17. package/dist/diagnose.d.ts.map +1 -0
  18. package/dist/diagnose.js +237 -0
  19. package/dist/diagnose.js.map +1 -0
  20. package/dist/errors.d.ts +4 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +45 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/events.d.ts +38 -0
  25. package/dist/events.d.ts.map +1 -0
  26. package/dist/events.js +167 -0
  27. package/dist/events.js.map +1 -0
  28. package/dist/index.d.ts +7 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +10 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/mapping.d.ts +328 -0
  33. package/dist/mapping.d.ts.map +1 -0
  34. package/dist/mapping.js +437 -0
  35. package/dist/mapping.js.map +1 -0
  36. package/dist/provider.d.ts +33 -0
  37. package/dist/provider.d.ts.map +1 -0
  38. package/dist/provider.js +634 -0
  39. package/dist/provider.js.map +1 -0
  40. package/dist/resolve.d.ts +10 -0
  41. package/dist/resolve.d.ts.map +1 -0
  42. package/dist/resolve.js +171 -0
  43. package/dist/resolve.js.map +1 -0
  44. package/dist/secrets.d.ts +7 -0
  45. package/dist/secrets.d.ts.map +1 -0
  46. package/dist/secrets.js +33 -0
  47. package/dist/secrets.js.map +1 -0
  48. package/dist/testing/index.d.ts +54 -0
  49. package/dist/testing/index.d.ts.map +1 -0
  50. package/dist/testing/index.js +119 -0
  51. package/dist/testing/index.js.map +1 -0
  52. package/instructions/README.md +14 -0
  53. package/instructions/configure-stripe.md +69 -0
  54. package/instructions/framework.md +62 -0
  55. package/instructions/testing.md +41 -0
  56. package/instructions/webhooks.md +44 -0
  57. package/package.json +66 -0
@@ -0,0 +1,14 @@
1
+ import type { CatalogInput, CatalogResult } from '@plumbus/payments';
2
+ import Stripe from 'stripe';
3
+ export declare function featureLookupKey(namespace: string, feature: string): string;
4
+ /** Feature keys of this namespace's lookup keys; other keys are ignored. */
5
+ export declare function featureKeysOf(lookupKeys: readonly string[], namespace?: string): string[];
6
+ /** Product id for a plan or meter: stable per namespace and key, valid as a Stripe id. */
7
+ export declare function catalogProductId(namespace: string, kind: 'plan' | 'meter', key: string): string;
8
+ export declare function findPricesByLookupKey(stripe: Stripe, lookupKeys: readonly string[], options?: Stripe.RequestOptions): Promise<Map<string, Stripe.Price>>;
9
+ /**
10
+ * Bring the catalog to `input` (apply) or report what differs (check). The two
11
+ * share one walk so a check lists exactly what a sync would do.
12
+ */
13
+ export declare function reconcileCatalog(stripe: Stripe, input: CatalogInput, apply: boolean): Promise<CatalogResult>;
14
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAM5B,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CASzF;AAED,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/F;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,GAAE,MAAM,CAAC,cAAmB,GAClC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAYpC;AA2BD;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,aAAa,CAAC,CAwPxB"}
@@ -0,0 +1,286 @@
1
+ // ── The platform's billing catalog on Stripe ──
2
+ // `billing.plans` and `billing.meters` become Stripe objects found again by
3
+ // stable handles, so sync is idempotent and a check can say what is missing:
4
+ // • one Product per plan and per meter, with an id derived from the namespace
5
+ // • one Price per plan price and per meter, by lookup key; a changed amount
6
+ // makes a new price that takes over the lookup key (existing subscribers keep
7
+ // the old one), and the old price is archived
8
+ // • one entitlement Feature per feature key (`plumbus:<namespace>:feature:<key>`),
9
+ // attached to the products of the plans that grant it
10
+ // • one billing Meter per meter, by event name
11
+ import { createHash } from 'node:crypto';
12
+ import { ErrorCode, PlumbusError } from '@plumbus/core';
13
+ import Stripe from 'stripe';
14
+ import { idOf } from './mapping.js';
15
+ /** Stripe filters prices by at most 10 lookup keys per request. */
16
+ const LOOKUP_KEYS_PER_REQUEST = 10;
17
+ export function featureLookupKey(namespace, feature) {
18
+ return `plumbus:${namespace}:feature:${feature}`;
19
+ }
20
+ /** Feature keys of this namespace's lookup keys; other keys are ignored. */
21
+ export function featureKeysOf(lookupKeys, namespace) {
22
+ const keys = [];
23
+ for (const lookupKey of lookupKeys) {
24
+ const parts = lookupKey.split(':');
25
+ if (parts.length < 4 || parts[0] !== 'plumbus' || parts[2] !== 'feature')
26
+ continue;
27
+ if (namespace !== undefined && parts[1] !== namespace)
28
+ continue;
29
+ keys.push(parts.slice(3).join(':'));
30
+ }
31
+ return keys;
32
+ }
33
+ /** Product id for a plan or meter: stable per namespace and key, valid as a Stripe id. */
34
+ export function catalogProductId(namespace, kind, key) {
35
+ const digest = createHash('sha256').update(`${namespace}\u0000${kind}\u0000${key}`).digest('hex');
36
+ return `plumbus_${kind}_${digest.slice(0, 24)}`;
37
+ }
38
+ export async function findPricesByLookupKey(stripe, lookupKeys, options = {}) {
39
+ const found = new Map();
40
+ const unique = [...new Set(lookupKeys)];
41
+ for (let i = 0; i < unique.length; i += LOOKUP_KEYS_PER_REQUEST) {
42
+ const chunk = unique.slice(i, i + LOOKUP_KEYS_PER_REQUEST);
43
+ const page = await stripe.prices.list({ lookup_keys: chunk, limit: LOOKUP_KEYS_PER_REQUEST }, options);
44
+ for (const price of page.data)
45
+ if (price.lookup_key)
46
+ found.set(price.lookup_key, price);
47
+ }
48
+ return found;
49
+ }
50
+ function isMissing(err) {
51
+ return (typeof err === 'object' &&
52
+ err !== null &&
53
+ err.statusCode === 404 &&
54
+ err.code === 'resource_missing');
55
+ }
56
+ async function retrieveProduct(stripe, id) {
57
+ try {
58
+ return await stripe.products.retrieve(id);
59
+ }
60
+ catch (err) {
61
+ if (isMissing(err))
62
+ return null;
63
+ throw err;
64
+ }
65
+ }
66
+ /**
67
+ * Bring the catalog to `input` (apply) or report what differs (check). The two
68
+ * share one walk so a check lists exactly what a sync would do.
69
+ */
70
+ export async function reconcileCatalog(stripe, input, apply) {
71
+ const changes = [];
72
+ const prices = {};
73
+ const ns = input.namespace;
74
+ // Entitlement features.
75
+ const featureIds = new Map();
76
+ for (const feature of input.features) {
77
+ const lookupKey = featureLookupKey(ns, feature.key);
78
+ const [found] = (await stripe.entitlements.features.list({ lookup_key: lookupKey, limit: 1 }))
79
+ .data;
80
+ if (!found) {
81
+ changes.push(`create feature ${feature.key}`);
82
+ if (apply) {
83
+ const created = await stripe.entitlements.features.create({
84
+ lookup_key: lookupKey,
85
+ name: feature.name,
86
+ metadata: { plumbus_catalog: ns, plumbus_feature: feature.key },
87
+ });
88
+ featureIds.set(feature.key, created.id);
89
+ }
90
+ continue;
91
+ }
92
+ featureIds.set(feature.key, found.id);
93
+ if (found.name !== feature.name || !found.active) {
94
+ changes.push(`update feature ${feature.key}`);
95
+ if (apply)
96
+ await stripe.entitlements.features.update(found.id, { name: feature.name, active: true });
97
+ }
98
+ }
99
+ const ensureProduct = async (wanted, label) => {
100
+ const product = await retrieveProduct(stripe, wanted.id);
101
+ if (!product) {
102
+ changes.push(`create product ${label}`);
103
+ if (apply) {
104
+ await stripe.products.create({
105
+ id: wanted.id,
106
+ name: wanted.name,
107
+ ...(wanted.description ? { description: wanted.description } : {}),
108
+ metadata: wanted.metadata,
109
+ });
110
+ }
111
+ return apply;
112
+ }
113
+ if (product.name !== wanted.name ||
114
+ (product.description ?? null) !== wanted.description ||
115
+ !product.active) {
116
+ changes.push(`update product ${label}`);
117
+ if (apply) {
118
+ await stripe.products.update(wanted.id, {
119
+ name: wanted.name,
120
+ description: wanted.description ?? '',
121
+ active: true,
122
+ });
123
+ }
124
+ }
125
+ return true;
126
+ };
127
+ // Plan products and the features each grants.
128
+ const planProducts = new Map();
129
+ for (const plan of input.plans) {
130
+ const productId = catalogProductId(ns, 'plan', plan.key);
131
+ const exists = await ensureProduct({
132
+ id: productId,
133
+ name: plan.name,
134
+ description: plan.description ?? null,
135
+ metadata: { plumbus_catalog: ns, plumbus_plan: plan.key },
136
+ }, `plan ${plan.key}`);
137
+ planProducts.set(plan.key, exists);
138
+ if (!exists) {
139
+ for (const feature of plan.features)
140
+ changes.push(`grant ${feature} with plan ${plan.key}`);
141
+ continue;
142
+ }
143
+ const attached = (await stripe.products.listFeatures(productId, { limit: 100 })).data;
144
+ const wanted = new Set(plan.features);
145
+ for (const attachment of attached) {
146
+ const key = featureKeysOf([attachment.entitlement_feature.lookup_key], ns)[0];
147
+ if (key === undefined || wanted.has(key))
148
+ continue;
149
+ changes.push(`stop granting ${key} with plan ${plan.key}`);
150
+ if (apply)
151
+ await stripe.products.deleteFeature(productId, attachment.id);
152
+ }
153
+ const have = new Set(attached.flatMap((a) => featureKeysOf([a.entitlement_feature.lookup_key], ns)));
154
+ for (const key of plan.features) {
155
+ if (have.has(key))
156
+ continue;
157
+ changes.push(`grant ${key} with plan ${plan.key}`);
158
+ const featureId = featureIds.get(key);
159
+ if (apply && featureId) {
160
+ await stripe.products.createFeature(productId, { entitlement_feature: featureId });
161
+ }
162
+ }
163
+ }
164
+ // Meters, found by event name.
165
+ const meters = new Map();
166
+ if (input.meters.length > 0) {
167
+ for (const meter of (await stripe.billing.meters.list({ status: 'active', limit: 100 })).data) {
168
+ meters.set(meter.event_name, meter);
169
+ }
170
+ }
171
+ const meterIds = new Map();
172
+ const meterProducts = new Map();
173
+ for (const meter of input.meters) {
174
+ const found = meters.get(meter.eventName);
175
+ if (!found) {
176
+ changes.push(`create meter ${meter.key} (event ${meter.eventName})`);
177
+ if (apply) {
178
+ const created = await stripe.billing.meters.create({
179
+ display_name: meter.name,
180
+ event_name: meter.eventName,
181
+ default_aggregation: { formula: meter.aggregation },
182
+ customer_mapping: { type: 'by_id', event_payload_key: 'stripe_customer_id' },
183
+ value_settings: { event_payload_key: 'value' },
184
+ });
185
+ meterIds.set(meter.key, created.id);
186
+ }
187
+ }
188
+ else {
189
+ meterIds.set(meter.key, found.id);
190
+ if (found.default_aggregation.formula !== meter.aggregation) {
191
+ const message = `Meter ${meter.key} (event ${meter.eventName}) aggregates by ${found.default_aggregation.formula} at Stripe, not ${meter.aggregation}; Stripe cannot change a meter's aggregation, so use a new eventName`;
192
+ if (apply) {
193
+ throw new PlumbusError(ErrorCode.Validation, message, {
194
+ reason: 'stripe_meter_aggregation_mismatch',
195
+ meter: meter.key,
196
+ });
197
+ }
198
+ changes.push(message);
199
+ }
200
+ if (found.display_name !== meter.name) {
201
+ changes.push(`rename meter ${meter.key}`);
202
+ if (apply)
203
+ await stripe.billing.meters.update(found.id, { display_name: meter.name });
204
+ }
205
+ }
206
+ meterProducts.set(meter.key, await ensureProduct({
207
+ id: catalogProductId(ns, 'meter', meter.key),
208
+ name: meter.name,
209
+ description: null,
210
+ metadata: { plumbus_catalog: ns, plumbus_meter: meter.key },
211
+ }, `meter ${meter.key}`));
212
+ }
213
+ // Prices, by lookup key.
214
+ const existing = await findPricesByLookupKey(stripe, [
215
+ ...input.plans.flatMap((plan) => plan.prices.map((price) => price.lookupKey)),
216
+ ...input.meters.map((meter) => meter.lookupKey),
217
+ ]);
218
+ const ensurePrice = async (lookupKey, matches, create, label) => {
219
+ const found = existing.get(lookupKey);
220
+ if (found?.active && matches(found)) {
221
+ prices[lookupKey] = found.id;
222
+ return;
223
+ }
224
+ changes.push(found ? `replace price ${label}` : `create price ${label}`);
225
+ if (!apply) {
226
+ if (found)
227
+ prices[lookupKey] = found.id;
228
+ return;
229
+ }
230
+ const created = await stripe.prices.create({
231
+ ...create,
232
+ lookup_key: lookupKey,
233
+ ...(found ? { transfer_lookup_key: true } : {}),
234
+ });
235
+ // New subscriptions take the new price; existing subscribers keep the old one.
236
+ if (found?.active)
237
+ await stripe.prices.update(found.id, { active: false });
238
+ prices[lookupKey] = created.id;
239
+ };
240
+ for (const plan of input.plans) {
241
+ const productId = catalogProductId(ns, 'plan', plan.key);
242
+ for (const price of plan.prices) {
243
+ const label = `${price.lookupKey} (${price.amount} ${price.currency} every ${price.intervalCount} ${price.interval})`;
244
+ if (!planProducts.get(plan.key)) {
245
+ changes.push(`create price ${label}`);
246
+ continue;
247
+ }
248
+ await ensurePrice(price.lookupKey, (found) => found.unit_amount === price.amount &&
249
+ found.currency === price.currency &&
250
+ found.recurring?.interval === price.interval &&
251
+ (found.recurring?.interval_count ?? 1) === price.intervalCount &&
252
+ found.recurring?.usage_type !== 'metered' &&
253
+ idOf(found.product) === productId, {
254
+ currency: price.currency,
255
+ unit_amount: price.amount,
256
+ recurring: { interval: price.interval, interval_count: price.intervalCount },
257
+ product: productId,
258
+ metadata: { plumbus_catalog: ns, plumbus_plan: plan.key, plumbus_price: price.key },
259
+ }, label);
260
+ }
261
+ }
262
+ for (const meter of input.meters) {
263
+ const productId = catalogProductId(ns, 'meter', meter.key);
264
+ const meterId = meterIds.get(meter.key);
265
+ const label = `${meter.lookupKey} (${meter.unitAmountDecimal} ${meter.currency} per unit, every ${meter.interval})`;
266
+ if (!meterId || !meterProducts.get(meter.key)) {
267
+ changes.push(`create price ${label}`);
268
+ continue;
269
+ }
270
+ await ensurePrice(meter.lookupKey, (found) => found.unit_amount_decimal != null &&
271
+ Stripe.Decimal.from(String(found.unit_amount_decimal)).eq(Stripe.Decimal.from(meter.unitAmountDecimal)) &&
272
+ found.currency === meter.currency &&
273
+ found.recurring?.interval === meter.interval &&
274
+ found.recurring?.usage_type === 'metered' &&
275
+ found.recurring?.meter === meterId &&
276
+ idOf(found.product) === productId, {
277
+ currency: meter.currency,
278
+ unit_amount_decimal: Stripe.Decimal.from(meter.unitAmountDecimal),
279
+ recurring: { interval: meter.interval, usage_type: 'metered', meter: meterId },
280
+ product: productId,
281
+ metadata: { plumbus_catalog: ns, plumbus_meter: meter.key },
282
+ }, label);
283
+ }
284
+ return { prices, changes };
285
+ }
286
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,iFAAiF;AACjF,iDAAiD;AACjD,oFAAoF;AACpF,yDAAyD;AACzD,gDAAgD;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM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AAK,CAAC,SAAS,EAAE,UAAU,KAAK,SAAS;YACzC,KAAK,CAAC,SAAS,EAAE,KAAK,KAAK,OAAO;YAClC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,SAAS,EACnC;YACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,mBAAmB,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;YACjE,SAAS,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE;YAC9E,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,GAAG,EAAE;SAC5D,EACD,KAAK,CACN,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { ChargeItem, ChargeRouting, CheckoutOptions, CreateChargeInput, CreateInvoiceChargeInput, ChargeSavedMethodInput, CustomAmount, ProviderCharge } from '@plumbus/payments';
2
+ import Stripe from 'stripe';
3
+ export declare const PRODUCT_NAME_MAX = 250;
4
+ /** Marks PaymentIntents that are charges themselves (a saved method charged off-session). */
5
+ export declare const COLLECTION_METADATA_KEY = "plumbus_collection";
6
+ export declare const SESSION_EXPAND: readonly ["payment_intent.latest_charge", "payment_intent.payment_method"];
7
+ /** Cut to `max` UTF-16 units without splitting a surrogate pair (Stripe rejects half emoji). */
8
+ export declare function clip(text: string, max: number): string;
9
+ export declare function checkoutExpiry(requested: Date): number;
10
+ /** Request options for an object on a seller's account, or on the platform (null). */
11
+ export declare function onAccount(accountId: string | null | undefined): Stripe.RequestOptions;
12
+ /** The account a charge's objects live on: the seller's for direct charges, else the platform. */
13
+ export declare function chargeAccount(routing: ChargeRouting): string | null;
14
+ /** Fee and payee fields shared by PaymentIntents, Checkout's payment_intent_data, and invoices. */
15
+ export declare function moneyRouting(routing: ChargeRouting, platformFeeAmount: number): {
16
+ application_fee_amount?: number;
17
+ transfer_data?: {
18
+ destination: string;
19
+ };
20
+ on_behalf_of?: string;
21
+ transfer_group?: string;
22
+ };
23
+ /** Checkout page options, for payment and subscription pages. */
24
+ export declare function checkoutOptionParams(options: CheckoutOptions, mode: 'payment' | 'subscription', hasCustomer: boolean): Partial<Stripe.Checkout.SessionCreateParams>;
25
+ export declare function lineItemsFor(currency: string, items: readonly ChargeItem[]): Stripe.Checkout.SessionCreateParams.LineItem[];
26
+ /** A price whose amount the client chooses (Checkout takes it only as a saved Price). */
27
+ export declare function customAmountPrice(stripe: Stripe, input: {
28
+ currency: string;
29
+ name: string;
30
+ customAmount: CustomAmount;
31
+ }, options: Stripe.RequestOptions): Promise<Stripe.Price>;
32
+ export declare function createCheckoutCharge(stripe: Stripe, input: CreateChargeInput): Promise<ProviderCharge>;
33
+ /**
34
+ * Email an invoice for a charge. An earlier attempt that crashed part-way may
35
+ * have left the invoice behind (found by the charge id in its metadata); it is
36
+ * finished instead of made twice.
37
+ */
38
+ export declare function createInvoiceCharge(stripe: Stripe, input: CreateInvoiceChargeInput): Promise<ProviderCharge>;
39
+ /**
40
+ * Charge a saved method without the client. A decline or a bank that wants the
41
+ * client present is an outcome (failed / requires_action), not an error.
42
+ */
43
+ export declare function chargeSavedMethod(stripe: Stripe, input: ChargeSavedMethodInput): Promise<ProviderCharge>;
44
+ /**
45
+ * The charge a PaymentIntent belongs to, in the shape its collection reports:
46
+ * the PaymentIntent itself (saved methods), its Checkout Session (payment pages
47
+ * and links), or its invoice (invoices sent as charges). Null = not ours.
48
+ */
49
+ export declare function chargeForPayment(stripe: Stripe, paymentId: string, accountId: string | null): Promise<ProviderCharge | null>;
50
+ export declare function captureCharge(stripe: Stripe, input: {
51
+ routing: ChargeRouting;
52
+ paymentId: string;
53
+ amount?: number;
54
+ platformFeeAmount?: number;
55
+ idempotencyKey: string;
56
+ }): Promise<ProviderCharge>;
57
+ /** Stop a charge: expire its payment page, void its invoice, or release its hold. */
58
+ export declare function cancelCharge(stripe: Stripe, input: {
59
+ routing: ChargeRouting;
60
+ collection: string;
61
+ chargeId: string;
62
+ paymentId: string | null;
63
+ }): Promise<ProviderCharge>;
64
+ //# sourceMappingURL=charges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charges.d.ts","sourceRoot":"","sources":["../src/charges.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAgB5B,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,eAAO,MAAM,cAAc,4EAGjB,CAAC;AAEX,gGAAgG;AAChG,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAItD;AAED,sFAAsF;AACtF,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,cAAc,CAErF;AAED,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAEnE;AAeD,mGAAmG;AACnG,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,iBAAiB,EAAE,MAAM,GACxB;IACD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAA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