@shware/purchase 0.1.3 → 0.1.4
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/dist/stripe/index.cjs +2 -0
- package/dist/stripe/index.cjs.map +1 -1
- package/dist/stripe/index.d.cts +1 -1
- package/dist/stripe/index.d.ts +1 -1
- package/dist/stripe/index.mjs +3 -1
- package/dist/stripe/index.mjs.map +1 -1
- package/dist/stripe/mapper.cjs +18 -3
- package/dist/stripe/mapper.cjs.map +1 -1
- package/dist/stripe/mapper.d.cts +42 -22
- package/dist/stripe/mapper.d.ts +42 -22
- package/dist/stripe/mapper.mjs +17 -3
- package/dist/stripe/mapper.mjs.map +1 -1
- package/package.json +1 -1
package/dist/stripe/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(stripe_exports, {
|
|
|
23
23
|
METADATA_KEYS: () => import_metadata.METADATA_KEYS,
|
|
24
24
|
cancellationDetailsSchema: () => import_schema.cancellationDetailsSchema,
|
|
25
25
|
checkoutSessionSchema: () => import_schema.checkoutSessionSchema,
|
|
26
|
+
getBeginCheckoutProperties: () => import_mapper.getBeginCheckoutProperties,
|
|
26
27
|
getPurchaseProperties: () => import_mapper.getPurchaseProperties,
|
|
27
28
|
mapCheckoutSession: () => import_mapper.mapCheckoutSession,
|
|
28
29
|
mapStatus: () => import_mapper.mapStatus,
|
|
@@ -39,6 +40,7 @@ var import_metadata = require("./metadata.cjs");
|
|
|
39
40
|
METADATA_KEYS,
|
|
40
41
|
cancellationDetailsSchema,
|
|
41
42
|
checkoutSessionSchema,
|
|
43
|
+
getBeginCheckoutProperties,
|
|
42
44
|
getPurchaseProperties,
|
|
43
45
|
mapCheckoutSession,
|
|
44
46
|
mapStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapStatus,\n mapCheckoutSession,\n minorUnits,\n price,\n getPurchaseProperties,\n type CheckoutSession,\n type PurchaseProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapStatus,\n mapCheckoutSession,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AACP,oBAIO;AAEP,sBAA8B;","names":[]}
|
package/dist/stripe/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CheckoutSession, PurchaseProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price } from './mapper.cjs';
|
|
1
|
+
export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price } from './mapper.cjs';
|
|
2
2
|
export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.cjs';
|
|
3
3
|
export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.cjs';
|
|
4
4
|
export { METADATA_KEYS } from './metadata.cjs';
|
package/dist/stripe/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CheckoutSession, PurchaseProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price } from './mapper.js';
|
|
1
|
+
export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price } from './mapper.js';
|
|
2
2
|
export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.js';
|
|
3
3
|
export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.js';
|
|
4
4
|
export { METADATA_KEYS } from './metadata.js';
|
package/dist/stripe/index.mjs
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
mapCheckoutSession,
|
|
6
6
|
minorUnits,
|
|
7
7
|
price,
|
|
8
|
-
getPurchaseProperties
|
|
8
|
+
getPurchaseProperties,
|
|
9
|
+
getBeginCheckoutProperties
|
|
9
10
|
} from "./mapper.mjs";
|
|
10
11
|
import {
|
|
11
12
|
cancellationDetailsSchema,
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
METADATA_KEYS,
|
|
17
18
|
cancellationDetailsSchema,
|
|
18
19
|
checkoutSessionSchema,
|
|
20
|
+
getBeginCheckoutProperties,
|
|
19
21
|
getPurchaseProperties,
|
|
20
22
|
mapCheckoutSession,
|
|
21
23
|
mapStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapStatus,\n mapCheckoutSession,\n minorUnits,\n price,\n getPurchaseProperties,\n type CheckoutSession,\n type PurchaseProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapStatus,\n mapCheckoutSession,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;","names":[]}
|
package/dist/stripe/mapper.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var mapper_exports = {};
|
|
22
22
|
__export(mapper_exports, {
|
|
23
23
|
ZERO_DECIMAL_CURRENCIES: () => ZERO_DECIMAL_CURRENCIES,
|
|
24
|
+
getBeginCheckoutProperties: () => getBeginCheckoutProperties,
|
|
24
25
|
getPurchaseProperties: () => getPurchaseProperties,
|
|
25
26
|
mapCheckoutSession: () => mapCheckoutSession,
|
|
26
27
|
mapStatus: () => mapStatus,
|
|
@@ -56,7 +57,7 @@ function mapCheckoutSession(session) {
|
|
|
56
57
|
currency: session.currency,
|
|
57
58
|
amount_total: session.amount_total,
|
|
58
59
|
line_items: session.line_items?.data.map((item) => ({
|
|
59
|
-
id: item.id,
|
|
60
|
+
id: item.price ? typeof item.price.product === "string" ? item.price.product : item.price.product.id : item.id,
|
|
60
61
|
currency: item.currency,
|
|
61
62
|
quantity: item.quantity,
|
|
62
63
|
description: item.description,
|
|
@@ -65,7 +66,7 @@ function mapCheckoutSession(session) {
|
|
|
65
66
|
amount_subtotal: item.amount_subtotal,
|
|
66
67
|
amount_discount: item.amount_discount,
|
|
67
68
|
price: item.price ? { id: item.price.id } : null
|
|
68
|
-
}))
|
|
69
|
+
}))
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
function mapStatus(status) {
|
|
@@ -131,7 +132,7 @@ function getPurchaseProperties(session) {
|
|
|
131
132
|
value: price(value, currency),
|
|
132
133
|
currency: currency.toUpperCase(),
|
|
133
134
|
coupon: session.coupon,
|
|
134
|
-
items: session.line_items
|
|
135
|
+
items: session.line_items?.map((item, index) => ({
|
|
135
136
|
index,
|
|
136
137
|
item_id: item.id,
|
|
137
138
|
item_name: item.description ?? "",
|
|
@@ -141,9 +142,23 @@ function getPurchaseProperties(session) {
|
|
|
141
142
|
}))
|
|
142
143
|
};
|
|
143
144
|
}
|
|
145
|
+
function getBeginCheckoutProperties(p) {
|
|
146
|
+
return {
|
|
147
|
+
currency: p.currency.toUpperCase(),
|
|
148
|
+
value: price(p.unit_amount, p.currency),
|
|
149
|
+
items: [
|
|
150
|
+
{
|
|
151
|
+
item_id: p.product.id,
|
|
152
|
+
item_name: p.product.name,
|
|
153
|
+
price: price(p.unit_amount, p.currency)
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
144
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
159
|
0 && (module.exports = {
|
|
146
160
|
ZERO_DECIMAL_CURRENCIES,
|
|
161
|
+
getBeginCheckoutProperties,
|
|
147
162
|
getPurchaseProperties,
|
|
148
163
|
mapCheckoutSession,
|
|
149
164
|
mapStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import type Stripe from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import type Stripe from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map((item) => ({\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n })),\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAmC;AAE5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAEO,SAAS,mBAAmB,SAAkC;AACnE,MAAI,SAA6B;AACjC,MAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;AACtE,UAAM,WAAW,QAAQ,UAAU,CAAC;AACpC,QAAI,SAAS,UAAU,OAAO,SAAS,WAAW,UAAU;AAC1D,eAAS,SAAS,OAAO;AAAA,IAC3B,WAAW,OAAO,SAAS,WAAW,UAAU;AAC9C,eAAS,SAAS;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AE,QAAQ;AAAA,QACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/stripe/mapper.d.cts
CHANGED
|
@@ -23,13 +23,45 @@ declare function mapCheckoutSession(session: Stripe.Checkout.Session): {
|
|
|
23
23
|
price: {
|
|
24
24
|
id: string;
|
|
25
25
|
} | null;
|
|
26
|
-
}[];
|
|
26
|
+
}[] | undefined;
|
|
27
27
|
};
|
|
28
28
|
type CheckoutSession = ReturnType<typeof mapCheckoutSession>;
|
|
29
|
+
type ProductPrice = {
|
|
30
|
+
id: string;
|
|
31
|
+
type: Stripe.Price.Type;
|
|
32
|
+
unit_amount: number;
|
|
33
|
+
currency: Stripe.Price['currency'];
|
|
34
|
+
product: {
|
|
35
|
+
id: Stripe.Product['id'];
|
|
36
|
+
name: Stripe.Product['name'];
|
|
37
|
+
description: Stripe.Product['description'];
|
|
38
|
+
livemode: Stripe.Product['livemode'];
|
|
39
|
+
};
|
|
40
|
+
};
|
|
29
41
|
declare function mapStatus(status: Stripe.Subscription.Status): SubscriptionStatus;
|
|
30
42
|
declare const ZERO_DECIMAL_CURRENCIES: string[];
|
|
31
43
|
declare function minorUnits(currency: string): 1 | 100;
|
|
32
44
|
declare function price(value: number, currency: string): number;
|
|
45
|
+
interface Item {
|
|
46
|
+
item_id: string;
|
|
47
|
+
item_name: string;
|
|
48
|
+
affiliation?: 'Google Store' | (string & {});
|
|
49
|
+
coupon?: string;
|
|
50
|
+
discount?: number;
|
|
51
|
+
index?: number;
|
|
52
|
+
item_brand?: string;
|
|
53
|
+
item_category?: string;
|
|
54
|
+
item_category2?: string;
|
|
55
|
+
item_category3?: string;
|
|
56
|
+
item_category4?: string;
|
|
57
|
+
item_category5?: string;
|
|
58
|
+
item_list_id?: string;
|
|
59
|
+
item_list_name?: string;
|
|
60
|
+
item_variant?: string;
|
|
61
|
+
location_id?: string;
|
|
62
|
+
price?: number;
|
|
63
|
+
quantity?: number;
|
|
64
|
+
}
|
|
33
65
|
interface PurchaseProperties {
|
|
34
66
|
currency: string;
|
|
35
67
|
value: number;
|
|
@@ -37,27 +69,15 @@ interface PurchaseProperties {
|
|
|
37
69
|
coupon?: string;
|
|
38
70
|
shipping?: number;
|
|
39
71
|
tax?: number;
|
|
40
|
-
items?:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
item_brand?: string;
|
|
48
|
-
item_category?: string;
|
|
49
|
-
item_category2?: string;
|
|
50
|
-
item_category3?: string;
|
|
51
|
-
item_category4?: string;
|
|
52
|
-
item_category5?: string;
|
|
53
|
-
item_list_id?: string;
|
|
54
|
-
item_list_name?: string;
|
|
55
|
-
item_variant?: string;
|
|
56
|
-
location_id?: string;
|
|
57
|
-
price?: number;
|
|
58
|
-
quantity?: number;
|
|
59
|
-
}>;
|
|
72
|
+
items?: Item[];
|
|
73
|
+
}
|
|
74
|
+
interface BeginCheckoutProperties {
|
|
75
|
+
currency: string;
|
|
76
|
+
value: number;
|
|
77
|
+
coupon?: string;
|
|
78
|
+
items: Item[];
|
|
60
79
|
}
|
|
61
80
|
declare function getPurchaseProperties(session: CheckoutSession): PurchaseProperties;
|
|
81
|
+
declare function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties;
|
|
62
82
|
|
|
63
|
-
export { type CheckoutSession, type PurchaseProperties, ZERO_DECIMAL_CURRENCIES, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price };
|
|
83
|
+
export { type BeginCheckoutProperties, type CheckoutSession, type Item, type ProductPrice, type PurchaseProperties, ZERO_DECIMAL_CURRENCIES, getBeginCheckoutProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price };
|
package/dist/stripe/mapper.d.ts
CHANGED
|
@@ -23,13 +23,45 @@ declare function mapCheckoutSession(session: Stripe.Checkout.Session): {
|
|
|
23
23
|
price: {
|
|
24
24
|
id: string;
|
|
25
25
|
} | null;
|
|
26
|
-
}[];
|
|
26
|
+
}[] | undefined;
|
|
27
27
|
};
|
|
28
28
|
type CheckoutSession = ReturnType<typeof mapCheckoutSession>;
|
|
29
|
+
type ProductPrice = {
|
|
30
|
+
id: string;
|
|
31
|
+
type: Stripe.Price.Type;
|
|
32
|
+
unit_amount: number;
|
|
33
|
+
currency: Stripe.Price['currency'];
|
|
34
|
+
product: {
|
|
35
|
+
id: Stripe.Product['id'];
|
|
36
|
+
name: Stripe.Product['name'];
|
|
37
|
+
description: Stripe.Product['description'];
|
|
38
|
+
livemode: Stripe.Product['livemode'];
|
|
39
|
+
};
|
|
40
|
+
};
|
|
29
41
|
declare function mapStatus(status: Stripe.Subscription.Status): SubscriptionStatus;
|
|
30
42
|
declare const ZERO_DECIMAL_CURRENCIES: string[];
|
|
31
43
|
declare function minorUnits(currency: string): 1 | 100;
|
|
32
44
|
declare function price(value: number, currency: string): number;
|
|
45
|
+
interface Item {
|
|
46
|
+
item_id: string;
|
|
47
|
+
item_name: string;
|
|
48
|
+
affiliation?: 'Google Store' | (string & {});
|
|
49
|
+
coupon?: string;
|
|
50
|
+
discount?: number;
|
|
51
|
+
index?: number;
|
|
52
|
+
item_brand?: string;
|
|
53
|
+
item_category?: string;
|
|
54
|
+
item_category2?: string;
|
|
55
|
+
item_category3?: string;
|
|
56
|
+
item_category4?: string;
|
|
57
|
+
item_category5?: string;
|
|
58
|
+
item_list_id?: string;
|
|
59
|
+
item_list_name?: string;
|
|
60
|
+
item_variant?: string;
|
|
61
|
+
location_id?: string;
|
|
62
|
+
price?: number;
|
|
63
|
+
quantity?: number;
|
|
64
|
+
}
|
|
33
65
|
interface PurchaseProperties {
|
|
34
66
|
currency: string;
|
|
35
67
|
value: number;
|
|
@@ -37,27 +69,15 @@ interface PurchaseProperties {
|
|
|
37
69
|
coupon?: string;
|
|
38
70
|
shipping?: number;
|
|
39
71
|
tax?: number;
|
|
40
|
-
items?:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
item_brand?: string;
|
|
48
|
-
item_category?: string;
|
|
49
|
-
item_category2?: string;
|
|
50
|
-
item_category3?: string;
|
|
51
|
-
item_category4?: string;
|
|
52
|
-
item_category5?: string;
|
|
53
|
-
item_list_id?: string;
|
|
54
|
-
item_list_name?: string;
|
|
55
|
-
item_variant?: string;
|
|
56
|
-
location_id?: string;
|
|
57
|
-
price?: number;
|
|
58
|
-
quantity?: number;
|
|
59
|
-
}>;
|
|
72
|
+
items?: Item[];
|
|
73
|
+
}
|
|
74
|
+
interface BeginCheckoutProperties {
|
|
75
|
+
currency: string;
|
|
76
|
+
value: number;
|
|
77
|
+
coupon?: string;
|
|
78
|
+
items: Item[];
|
|
60
79
|
}
|
|
61
80
|
declare function getPurchaseProperties(session: CheckoutSession): PurchaseProperties;
|
|
81
|
+
declare function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties;
|
|
62
82
|
|
|
63
|
-
export { type CheckoutSession, type PurchaseProperties, ZERO_DECIMAL_CURRENCIES, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price };
|
|
83
|
+
export { type BeginCheckoutProperties, type CheckoutSession, type Item, type ProductPrice, type PurchaseProperties, ZERO_DECIMAL_CURRENCIES, getBeginCheckoutProperties, getPurchaseProperties, mapCheckoutSession, mapStatus, mapTime, minorUnits, price };
|
package/dist/stripe/mapper.mjs
CHANGED
|
@@ -26,7 +26,7 @@ function mapCheckoutSession(session) {
|
|
|
26
26
|
currency: session.currency,
|
|
27
27
|
amount_total: session.amount_total,
|
|
28
28
|
line_items: session.line_items?.data.map((item) => ({
|
|
29
|
-
id: item.id,
|
|
29
|
+
id: item.price ? typeof item.price.product === "string" ? item.price.product : item.price.product.id : item.id,
|
|
30
30
|
currency: item.currency,
|
|
31
31
|
quantity: item.quantity,
|
|
32
32
|
description: item.description,
|
|
@@ -35,7 +35,7 @@ function mapCheckoutSession(session) {
|
|
|
35
35
|
amount_subtotal: item.amount_subtotal,
|
|
36
36
|
amount_discount: item.amount_discount,
|
|
37
37
|
price: item.price ? { id: item.price.id } : null
|
|
38
|
-
}))
|
|
38
|
+
}))
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
function mapStatus(status) {
|
|
@@ -101,7 +101,7 @@ function getPurchaseProperties(session) {
|
|
|
101
101
|
value: price(value, currency),
|
|
102
102
|
currency: currency.toUpperCase(),
|
|
103
103
|
coupon: session.coupon,
|
|
104
|
-
items: session.line_items
|
|
104
|
+
items: session.line_items?.map((item, index) => ({
|
|
105
105
|
index,
|
|
106
106
|
item_id: item.id,
|
|
107
107
|
item_name: item.description ?? "",
|
|
@@ -111,8 +111,22 @@ function getPurchaseProperties(session) {
|
|
|
111
111
|
}))
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
+
function getBeginCheckoutProperties(p) {
|
|
115
|
+
return {
|
|
116
|
+
currency: p.currency.toUpperCase(),
|
|
117
|
+
value: price(p.unit_amount, p.currency),
|
|
118
|
+
items: [
|
|
119
|
+
{
|
|
120
|
+
item_id: p.product.id,
|
|
121
|
+
item_name: p.product.name,
|
|
122
|
+
price: price(p.unit_amount, p.currency)
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
};
|
|
126
|
+
}
|
|
114
127
|
export {
|
|
115
128
|
ZERO_DECIMAL_CURRENCIES,
|
|
129
|
+
getBeginCheckoutProperties,
|
|
116
130
|
getPurchaseProperties,
|
|
117
131
|
mapCheckoutSession,
|
|
118
132
|
mapStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import type Stripe from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items
|
|
1
|
+
{"version":3,"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import type Stripe from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status: session.payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map((item) => ({\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? { id: item.price.id } : null,\n })),\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${status}`);\n throw new Error(`Invalid stripe status: ${status}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";AACA,SAAS,0BAA0B;AAE5B,SAAS,QACd,wBACkC;AAClC,MAAI,CAAC,uBAAwB,QAAO;AACpC,SAAO,IAAI,KAAK,yBAAyB,GAAI,EAAE,YAAY;AAC7D;AAEO,SAAS,mBAAmB,SAAkC;AACnE,MAAI,SAA6B;AACjC,MAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;AACtE,UAAM,WAAW,QAAQ,UAAU,CAAC;AACpC,QAAI,SAAS,UAAU,OAAO,SAAS,WAAW,UAAU;AAC1D,eAAS,SAAS,OAAO;AAAA,IAC3B,WAAW,OAAO,SAAS,WAAW,UAAU;AAC9C,eAAS,SAAS;AAAA,IACpB,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI,QAAQ;AAAA,IACZ,KAAK,QAAQ;AAAA,IACb;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB,YAAY,QA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