Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/controller/checkout.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function checkoutController(usersService: UsersService, paymentsService:
postalCode: string;
captchaToken: string;
companyVatId?: string;
metadata?: Record<string, string>;
};
}>(
'/customer',
Expand All @@ -45,6 +46,10 @@ export function checkoutController(usersService: UsersService, paymentsService:
postalCode: { type: 'string' },
captchaToken: { type: 'string' },
companyVatId: { type: 'string' },
metadata: {
type: 'object',
additionalProperties: { type: 'string' },
},
},
},
},
Expand All @@ -57,8 +62,17 @@ export function checkoutController(usersService: UsersService, paymentsService:
},
async (req, res): Promise<{ customerId: string; token: string }> => {
let customerId: Stripe.Customer['id'];
const { customerName, lineAddress1, lineAddress2, city, country, postalCode, companyVatId, captchaToken } =
req.body;
const {
customerName,
lineAddress1,
lineAddress2,
city,
country,
postalCode,
companyVatId,
captchaToken,
metadata,
} = req.body;
const { uuid: userUuid, email } = req.user.payload;

const verifiedCaptcha = await verifyRecaptcha(captchaToken);
Expand All @@ -80,6 +94,7 @@ export function checkoutController(usersService: UsersService, paymentsService:
postalCode,
country,
},
metadata,
});
customerId = userExists.customerId;
} else {
Expand All @@ -93,6 +108,7 @@ export function checkoutController(usersService: UsersService, paymentsService:
postalCode,
country,
},
metadata,
});

await usersService.insertUser({
Expand Down
1 change: 1 addition & 0 deletions src/infrastructure/adapters/stripe.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class StripePaymentsAdapter implements PaymentsAdapter {
postal_code: params.address.postalCode ?? undefined,
},
}),
...(params.metadata && { metadata: params.metadata }),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/infrastructure/domain/entities/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CreateCustomerParams {
name: string;
email: string;
address: Partial<Address>;
metadata?: Record<string, string>;
}

export interface UpdateCustomerParams extends Partial<CreateCustomerParams> {
Expand Down
3 changes: 3 additions & 0 deletions tests/src/infrastructure/adapters/stripe.adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('Stripe Adapter', () => {
.spyOn(stripePaymentsAdapter.getInstance().customers, 'create')
.mockResolvedValue(mockedCustomer as Stripe.Response<Stripe.Customer>);

const metadata = { referralCode: 'ABC123' };

const createdCustomer = await stripePaymentsAdapter.createCustomer({
email: mockedCustomer.email as string,
name: mockedCustomer.name as string,
Expand All @@ -25,6 +27,7 @@ describe('Stripe Adapter', () => {
country: mockedCustomer.address?.country ?? '',
postalCode: mockedCustomer.address?.postal_code ?? '',
},
metadata,
});

expect(createdCustomer).toStrictEqual(Customer.toDomain(mockedCustomer));
Expand Down
Loading