Skip to content

Commit fdc149f

Browse files
authored
fix: added possibility to see prefilled email for the first checkout session (#164)
fix: added possibility to see prefilled email for the first checkout session
1 parent d548b39 commit fdc149f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

microservices/authorization/migrations/permissions/list/models/payment-stripe.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,47 +2224,55 @@
22242224
"schema": {
22252225
"cartId": {
22262226
"in": {
2227-
"admin": "allow"
2227+
"user": "allow"
22282228
},
22292229
"out": {
22302230
"admin": "allow"
22312231
}
22322232
},
22332233
"userId": {
22342234
"in": {
2235+
"user": "allow"
2236+
},
2237+
"out": {
22352238
"admin": "allow"
2239+
}
2240+
},
2241+
"customerEmail": {
2242+
"in": {
2243+
"user": "allow"
22362244
},
22372245
"out": {
22382246
"admin": "allow"
22392247
}
22402248
},
22412249
"successUrl": {
22422250
"in": {
2243-
"admin": "allow"
2251+
"user": "allow"
22442252
},
22452253
"out": {
22462254
"admin": "allow"
22472255
}
22482256
},
22492257
"cancelUrl": {
22502258
"in": {
2251-
"admin": "allow"
2259+
"user": "allow"
22522260
},
22532261
"out": {
22542262
"admin": "allow"
22552263
}
22562264
},
22572265
"returnUrl": {
22582266
"in": {
2259-
"admin": "allow"
2267+
"user": "allow"
22602268
},
22612269
"out": {
22622270
"admin": "allow"
22632271
}
22642272
},
22652273
"isEmbeddedMode": {
22662274
"in": {
2267-
"admin": "allow"
2275+
"user": "allow"
22682276
},
22692277
"out": {
22702278
"admin": "allow"

microservices/payment-stripe/src/methods/stripe/create-cart-checkout.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class CreateCartCheckoutInput {
2424
@ValidateIf((input) => input.isEmbeddedMode)
2525
returnUrl: string | null;
2626

27+
@Length(1, 40)
28+
@IsString()
29+
@IsUndefinable()
30+
customerEmail?: string;
31+
2732
@IsBoolean()
2833
@IsUndefinable()
2934
isEmbeddedMode?: boolean;
@@ -48,7 +53,15 @@ const createCartCheckout = Endpoint.custom(
4853
output: CreateCartCheckoutOutput,
4954
description: 'Setup intent and return client secret key',
5055
}),
51-
async ({ cartId, successUrl, cancelUrl, userId, returnUrl, isEmbeddedMode = false }) => {
56+
async ({
57+
cartId,
58+
successUrl,
59+
cancelUrl,
60+
userId,
61+
customerEmail,
62+
returnUrl,
63+
isEmbeddedMode = false,
64+
}) => {
5265
const service = await Stripe.init();
5366

5467
return service.createCartCheckout(
@@ -58,13 +71,15 @@ const createCartCheckout = Endpoint.custom(
5871
cartId,
5972
userId,
6073
returnUrl,
74+
customerEmail,
6175
}
6276
: {
6377
isEmbeddedMode,
6478
cartId,
6579
userId,
6680
successUrl,
6781
cancelUrl,
82+
customerEmail,
6883
},
6984
);
7085
},

microservices/payment-stripe/src/services/payment-gateway/stripe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ interface IStripePromoCodeParams {
169169
}
170170

171171
interface ICreateMultipleProductCheckout {
172-
isEmbeddedMode?: boolean;
173172
cartId: string;
174173
userId: string;
174+
customerEmail?: string;
175+
isEmbeddedMode?: boolean;
175176
}
176177

177178
interface ICreateMultipleProductCheckoutEmbedded extends ICreateMultipleProductCheckout {
@@ -471,7 +472,7 @@ class Stripe extends Abstract {
471472
public async createCartCheckout(
472473
params: TCreateMultipleProductCheckoutParams,
473474
): Promise<ICheckoutCart | null> {
474-
const { cartId, userId, isEmbeddedMode } = params;
475+
const { cartId, userId, isEmbeddedMode, customerEmail } = params;
475476
const { customerId } = await super.getCustomer(userId);
476477

477478
const cart = await this.cartRepository.findOne(
@@ -496,6 +497,7 @@ class Stripe extends Abstract {
496497
let checkoutParams: Omit<StripeSdk.Checkout.SessionCreateParams, 'success_url'> & {
497498
success_url?: string;
498499
} = {
500+
customer_email: customerEmail,
499501
line_items: lineItems,
500502
mode: 'payment',
501503
customer: customerId,

0 commit comments

Comments
 (0)