@unchainedshop/plugins 2.11.4 → 2.11.6
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/lib/payment/stripe/index.js +16 -7
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.d.ts +4 -1
- package/lib/payment/stripe/stripe.js +6 -12
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/package.json +1 -1
- package/src/payment/stripe/index.ts +17 -9
- package/src/payment/stripe/stripe.ts +12 -16
|
@@ -14,7 +14,17 @@ const Stripe = {
|
|
|
14
14
|
actions: (params) => {
|
|
15
15
|
const { modules } = params.context;
|
|
16
16
|
const descriptorPrefix = params.config.find(({ key }) => key === 'descriptorPrefix')?.value;
|
|
17
|
-
|
|
17
|
+
const getUserData = async (forcedUserId) => {
|
|
18
|
+
const userId = forcedUserId || params.paymentContext?.userId;
|
|
19
|
+
const user = await modules.users.findUserById(userId);
|
|
20
|
+
const email = modules.users.primaryEmail(user)?.address;
|
|
21
|
+
const name = user.profile.displayName || user.username || email;
|
|
22
|
+
return {
|
|
23
|
+
email,
|
|
24
|
+
name,
|
|
25
|
+
userId,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
18
28
|
const adapterActions = {
|
|
19
29
|
...PaymentAdapter.actions(params),
|
|
20
30
|
configurationError() {
|
|
@@ -56,13 +66,11 @@ const Stripe = {
|
|
|
56
66
|
const { orderPayment, order, paymentProviderId } = params.paymentContext;
|
|
57
67
|
if (orderPayment) {
|
|
58
68
|
const pricing = await modules.orders.pricingSheet(order);
|
|
59
|
-
const
|
|
69
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
70
|
+
const paymentIntent = await createOrderPaymentIntent({ userId, name, email, order, orderPayment, pricing, descriptorPrefix }, transactionContext);
|
|
60
71
|
return paymentIntent.client_secret;
|
|
61
72
|
}
|
|
62
|
-
const userId = order?.userId
|
|
63
|
-
const user = await modules.users.findUserById(userId);
|
|
64
|
-
const email = modules.users.primaryEmail(user)?.address;
|
|
65
|
-
const name = user.profile.displayName || user.username || email;
|
|
73
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
66
74
|
const paymentIntent = await createRegistrationIntent({ userId, name, email, paymentProviderId, descriptorPrefix }, transactionContext);
|
|
67
75
|
return paymentIntent.client_secret;
|
|
68
76
|
},
|
|
@@ -74,10 +82,11 @@ const Stripe = {
|
|
|
74
82
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
75
83
|
orderPaymentId: order.paymentId,
|
|
76
84
|
});
|
|
85
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
77
86
|
const pricing = await modules.orders.pricingSheet(order);
|
|
78
87
|
const paymentIntentObject = paymentIntentId
|
|
79
88
|
? await stripe.paymentIntents.retrieve(paymentIntentId)
|
|
80
|
-
: await createOrderPaymentIntent({ orderPayment, order, pricing, descriptorPrefix }, {
|
|
89
|
+
: await createOrderPaymentIntent({ userId, name, email, orderPayment, order, pricing, descriptorPrefix }, {
|
|
81
90
|
customer: paymentCredentials.meta?.customer,
|
|
82
91
|
confirm: true,
|
|
83
92
|
payment_method: paymentCredentials.token,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/payment/stripe/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,MAAM,EAAE,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEzF,cAAc,iBAAiB,CAAC;AAEhC,MAAM,MAAM,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;AAE7D,MAAM,MAAM,GAAoB;IAC9B,GAAG,cAAc;IAEjB,GAAG,EAAE,+BAA+B;IACpC,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,OAAO;IAEhB,aAAa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AQ,KAAK,QAAQ,CAAC,WAAW,EAAE;oBACvD,mBAAmB,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EACjD,CAAC;oBACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;gBAC7E,CAAC;gBACD,IAAI,mBAAmB,CAAC,QAAQ,EAAE,cAAc,KAAK,YAAY,EAAE,GAAG,EAAE,CAAC;oBACvE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;gBAC/E,CAAC;gBAED,IAAI,mBAAmB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;oBAC/C,OAAO,mBAAmB,CAAC;gBAC7B,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,yDAAyD,EAAE;oBACxE,cAAc,EAAE,mBAAmB,CAAC,EAAE;iBACvC,CAAC,CAAC;gBAEH,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;QAEF,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAC;AAEF,eAAe,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -16,7 +16,10 @@ export declare const createRegistrationIntent: ({ userId, name, email, paymentPr
|
|
|
16
16
|
paymentProviderId: string;
|
|
17
17
|
descriptorPrefix?: string;
|
|
18
18
|
}, options?: Record<string, any>) => Promise<Stripe.Response<Stripe.SetupIntent>>;
|
|
19
|
-
export declare const createOrderPaymentIntent: ({ order, orderPayment, pricing, descriptorPrefix, }: {
|
|
19
|
+
export declare const createOrderPaymentIntent: ({ userId, name, email, order, orderPayment, pricing, descriptorPrefix, }: {
|
|
20
|
+
userId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
email: string;
|
|
20
23
|
order: Order;
|
|
21
24
|
orderPayment: OrderPayment;
|
|
22
25
|
pricing: IOrderPricingSheet;
|
|
@@ -37,8 +37,8 @@ export const upsertCustomer = async ({ userId, name, email }) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
export const createRegistrationIntent = async ({ userId, name, email, paymentProviderId, descriptorPrefix, }, options = {}) => {
|
|
40
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${userId}${email ? ` (#${email})` : ''}`;
|
|
41
40
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
41
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${userId}${email ? ` (#${email})` : ''}`;
|
|
42
42
|
const setupIntent = await stripe.setupIntents.create({
|
|
43
43
|
description,
|
|
44
44
|
customer,
|
|
@@ -52,28 +52,22 @@ export const createRegistrationIntent = async ({ userId, name, email, paymentPro
|
|
|
52
52
|
});
|
|
53
53
|
return setupIntent;
|
|
54
54
|
};
|
|
55
|
-
export const createOrderPaymentIntent = async ({ order, orderPayment, pricing, descriptorPrefix, }, options = {}) => {
|
|
55
|
+
export const createOrderPaymentIntent = async ({ userId, name, email, order, orderPayment, pricing, descriptorPrefix, }, options = {}) => {
|
|
56
56
|
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${order._id}${order.orderNumber ? ` (#${order.orderNumber})` : ''}`;
|
|
57
|
-
const
|
|
58
|
-
order.billingAddress?.company;
|
|
59
|
-
const customer = options?.customer ||
|
|
60
|
-
(await upsertCustomer({
|
|
61
|
-
userId: order.userId,
|
|
62
|
-
name,
|
|
63
|
-
email: order.contact?.emailAddress,
|
|
64
|
-
}));
|
|
57
|
+
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
65
58
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
66
59
|
const paymentIntent = await stripe.paymentIntents.create({
|
|
67
60
|
amount: Math.round(amount),
|
|
68
61
|
currency: currency.toLowerCase(),
|
|
69
62
|
description,
|
|
70
|
-
statement_descriptor_suffix: order._id,
|
|
63
|
+
statement_descriptor_suffix: `${order._id.substring(0, 4)}..${order._id.substring(order._id.length - 4)}`,
|
|
71
64
|
setup_future_usage: 'off_session', // Verify your integration in this guide by including this parameter
|
|
72
65
|
customer,
|
|
66
|
+
receipt_email: order.contact?.emailAddress,
|
|
73
67
|
metadata: {
|
|
74
|
-
userId: order.userId,
|
|
75
68
|
orderPaymentId: orderPayment._id,
|
|
76
69
|
orderId: order._id,
|
|
70
|
+
userId,
|
|
77
71
|
environment,
|
|
78
72
|
},
|
|
79
73
|
...options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../src/payment/stripe/stripe.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,EAAE,aAAa,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEtF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,EAAE;IACvC,UAAU,EAAE,YAAY;CACzB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,0BAA0B,IAAI,IAAI,CAAC;AAEvD,eAAe,MAAM,CAAC;AAEtB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAmB,EAAE;IAC/E,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,uBAAuB,MAAM,GAAG,EAAE,CAAC,CAAC;QAC5F,MAAM,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEjC,IACE,gBAAgB,CAAC,IAAI,KAAK,IAAI;YAC9B,gBAAgB,CAAC,KAAK,KAAK,KAAK;YAChC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,KAAK,WAAW,EACrD,CAAC;YACD,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE;gBACzE,QAAQ,EAAE;oBACR,MAAM;oBACN,WA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AAa,EAAE,oEAAoE;QACvG,QAAQ;QACR,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,YAAY;QAC1C,QAAQ,EAAE;YACR,cAAc,EAAE,YAAY,CAAC,GAAG;YAChC,OAAO,EAAE,KAAK,CAAC,GAAG;YAClB,MAAM;YACN,WAAW;SACZ;QACD,GAAG,OAAO;KACX,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -22,7 +22,18 @@ const Stripe: IPaymentAdapter = {
|
|
|
22
22
|
const { modules } = params.context;
|
|
23
23
|
|
|
24
24
|
const descriptorPrefix = params.config.find(({ key }) => key === 'descriptorPrefix')?.value;
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
const getUserData = async (forcedUserId) => {
|
|
27
|
+
const userId = forcedUserId || params.paymentContext?.userId;
|
|
28
|
+
const user = await modules.users.findUserById(userId);
|
|
29
|
+
const email = modules.users.primaryEmail(user)?.address;
|
|
30
|
+
const name = user.profile.displayName || user.username || email;
|
|
31
|
+
return {
|
|
32
|
+
email,
|
|
33
|
+
name,
|
|
34
|
+
userId,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
26
37
|
const adapterActions = {
|
|
27
38
|
...PaymentAdapter.actions(params),
|
|
28
39
|
|
|
@@ -72,18 +83,15 @@ const Stripe: IPaymentAdapter = {
|
|
|
72
83
|
|
|
73
84
|
if (orderPayment) {
|
|
74
85
|
const pricing = await modules.orders.pricingSheet(order);
|
|
86
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
75
87
|
const paymentIntent = await createOrderPaymentIntent(
|
|
76
|
-
{ order, orderPayment, pricing, descriptorPrefix },
|
|
88
|
+
{ userId, name, email, order, orderPayment, pricing, descriptorPrefix },
|
|
77
89
|
transactionContext,
|
|
78
90
|
);
|
|
79
91
|
return paymentIntent.client_secret;
|
|
80
92
|
}
|
|
81
93
|
|
|
82
|
-
const userId = order?.userId
|
|
83
|
-
const user = await modules.users.findUserById(userId);
|
|
84
|
-
const email = modules.users.primaryEmail(user)?.address;
|
|
85
|
-
const name = user.profile.displayName || user.username || email;
|
|
86
|
-
|
|
94
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
87
95
|
const paymentIntent = await createRegistrationIntent(
|
|
88
96
|
{ userId, name, email, paymentProviderId, descriptorPrefix },
|
|
89
97
|
transactionContext,
|
|
@@ -100,13 +108,13 @@ const Stripe: IPaymentAdapter = {
|
|
|
100
108
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
101
109
|
orderPaymentId: order.paymentId,
|
|
102
110
|
});
|
|
103
|
-
|
|
111
|
+
const { userId, name, email } = await getUserData(order?.userId);
|
|
104
112
|
const pricing = await modules.orders.pricingSheet(order);
|
|
105
113
|
|
|
106
114
|
const paymentIntentObject = paymentIntentId
|
|
107
115
|
? await stripe.paymentIntents.retrieve(paymentIntentId)
|
|
108
116
|
: await createOrderPaymentIntent(
|
|
109
|
-
{ orderPayment, order, pricing, descriptorPrefix },
|
|
117
|
+
{ userId, name, email, orderPayment, order, pricing, descriptorPrefix },
|
|
110
118
|
{
|
|
111
119
|
customer: paymentCredentials.meta?.customer,
|
|
112
120
|
confirm: true,
|
|
@@ -64,8 +64,8 @@ export const createRegistrationIntent = async (
|
|
|
64
64
|
},
|
|
65
65
|
options: Record<string, any> = {},
|
|
66
66
|
) => {
|
|
67
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${userId}${email ? ` (#${email})` : ''}`;
|
|
68
67
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
68
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${userId}${email ? ` (#${email})` : ''}`;
|
|
69
69
|
|
|
70
70
|
const setupIntent = await stripe.setupIntents.create({
|
|
71
71
|
description,
|
|
@@ -83,11 +83,17 @@ export const createRegistrationIntent = async (
|
|
|
83
83
|
|
|
84
84
|
export const createOrderPaymentIntent = async (
|
|
85
85
|
{
|
|
86
|
+
userId,
|
|
87
|
+
name,
|
|
88
|
+
email,
|
|
86
89
|
order,
|
|
87
90
|
orderPayment,
|
|
88
91
|
pricing,
|
|
89
92
|
descriptorPrefix,
|
|
90
93
|
}: {
|
|
94
|
+
userId: string;
|
|
95
|
+
name: string;
|
|
96
|
+
email: string;
|
|
91
97
|
order: Order;
|
|
92
98
|
orderPayment: OrderPayment;
|
|
93
99
|
pricing: IOrderPricingSheet;
|
|
@@ -96,31 +102,21 @@ export const createOrderPaymentIntent = async (
|
|
|
96
102
|
options: Record<string, any> = {},
|
|
97
103
|
) => {
|
|
98
104
|
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'} ${order._id}${order.orderNumber ? ` (#${order.orderNumber})` : ''}`;
|
|
99
|
-
|
|
100
|
-
const name =
|
|
101
|
-
[order.billingAddress?.firstName, order.billingAddress?.lastName].filter(Boolean).join(' ') ||
|
|
102
|
-
order.billingAddress?.company;
|
|
103
|
-
|
|
104
|
-
const customer =
|
|
105
|
-
options?.customer ||
|
|
106
|
-
(await upsertCustomer({
|
|
107
|
-
userId: order.userId,
|
|
108
|
-
name,
|
|
109
|
-
email: order.contact?.emailAddress,
|
|
110
|
-
}));
|
|
111
|
-
|
|
105
|
+
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
112
106
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
107
|
+
|
|
113
108
|
const paymentIntent = await stripe.paymentIntents.create({
|
|
114
109
|
amount: Math.round(amount),
|
|
115
110
|
currency: currency.toLowerCase(),
|
|
116
111
|
description,
|
|
117
|
-
statement_descriptor_suffix: order._id,
|
|
112
|
+
statement_descriptor_suffix: `${order._id.substring(0, 4)}..${order._id.substring(order._id.length - 4)}`,
|
|
118
113
|
setup_future_usage: 'off_session', // Verify your integration in this guide by including this parameter
|
|
119
114
|
customer,
|
|
115
|
+
receipt_email: order.contact?.emailAddress,
|
|
120
116
|
metadata: {
|
|
121
|
-
userId: order.userId,
|
|
122
117
|
orderPaymentId: orderPayment._id,
|
|
123
118
|
orderId: order._id,
|
|
119
|
+
userId,
|
|
124
120
|
environment,
|
|
125
121
|
},
|
|
126
122
|
...options,
|