|
|
@@ -1,5 +1,5 @@
|
|
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
|
-import { mergeConfig } from '@vendure/core';
|
|
|
+import { EntityHydrator, mergeConfig } from '@vendure/core';
|
|
|
import {
|
|
|
CreateProductMutation,
|
|
|
CreateProductMutationVariables,
|
|
|
@@ -176,6 +176,40 @@ describe('Stripe payments', () => {
|
|
|
expect(createStripePaymentIntent).toEqual('test-client-secret');
|
|
|
});
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/1935
|
|
|
+ it('should attach metadata to stripe payment intent', async () => {
|
|
|
+ StripePlugin.options.metadata = async (injector, ctx, currentOrder) => {
|
|
|
+ const hydrator = await injector.get(EntityHydrator);
|
|
|
+ await hydrator.hydrate(ctx, currentOrder, { relations: ['customer'] });
|
|
|
+ return {
|
|
|
+ customerEmail: currentOrder.customer?.emailAddress ?? 'demo',
|
|
|
+ };
|
|
|
+ };
|
|
|
+ let createPaymentIntentPayload: any;
|
|
|
+ const { activeOrder } = await shopClient.query<GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
+ nock('https://api.stripe.com/')
|
|
|
+ .post('/v1/payment_intents', body => {
|
|
|
+ createPaymentIntentPayload = body;
|
|
|
+ return true;
|
|
|
+ })
|
|
|
+ .reply(200, {
|
|
|
+ client_secret: 'test-client-secret',
|
|
|
+ });
|
|
|
+ const { createStripePaymentIntent } = await shopClient.query(CREATE_STRIPE_PAYMENT_INTENT);
|
|
|
+ expect(createPaymentIntentPayload).toEqual({
|
|
|
+ amount: activeOrder?.totalWithTax.toString(),
|
|
|
+ currency: activeOrder?.currencyCode?.toLowerCase(),
|
|
|
+ customer: 'new-customer-id',
|
|
|
+ 'automatic_payment_methods[enabled]': 'true',
|
|
|
+ 'metadata[channelToken]': E2E_DEFAULT_CHANNEL_TOKEN,
|
|
|
+ 'metadata[orderId]': '1',
|
|
|
+ 'metadata[orderCode]': activeOrder?.code,
|
|
|
+ 'metadata[customerEmail]': customers[0].emailAddress,
|
|
|
+ });
|
|
|
+ expect(createStripePaymentIntent).toEqual('test-client-secret');
|
|
|
+ StripePlugin.options.metadata = undefined;
|
|
|
+ });
|
|
|
+
|
|
|
// https://github.com/vendure-ecommerce/vendure/issues/1630
|
|
|
describe('currencies with no fractional units', () => {
|
|
|
let japanProductId: string;
|