@vendure/payments-plugin 2.0.0-next.23 → 2.0.0-next.25

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/README.md CHANGED
@@ -1,3 +1,19 @@
1
1
  # Payments plugin
2
2
 
3
3
  For documentation, see https://www.vendure.io/docs/typescript-api/payments-plugin
4
+
5
+ ## Development
6
+
7
+ ### Mollie local development
8
+
9
+ For testing out changes to the Mollie plugin locally, with a real Mollie account, follow the steps below. These steps
10
+ will create an order, set Mollie as payment method, and create a payment intent link to the Mollie platform.
11
+
12
+ 1. Get a test api key from your Mollie
13
+ dashboard: https://help.mollie.com/hc/en-us/articles/115000328205-Where-can-I-find-the-API-key-
14
+ 2. Create the file `packages/payments-plugin/.env` with content `MOLLIE_APIKEY=your-test-apikey`
15
+ 3. `cd packages/payments-plugin`
16
+ 5. `yarn dev-server:mollie`
17
+ 6. Watch the logs for `Mollie payment link` and click the link to finalize the test payment.
18
+
19
+ You can change the order flow, payment methods and more in the file `e2e/mollie-dev-server`, and restart the devserver.
@@ -26,7 +26,11 @@ let MollieController = class MollieController {
26
26
  return core_1.Logger.warn(` Ignoring incoming webhook, because it has no body.id.`, constants_1.loggerCtx);
27
27
  }
28
28
  try {
29
- await this.mollieService.settlePayment({ channelToken, paymentMethodId, paymentId: body.id });
29
+ await this.mollieService.handleMollieStatusUpdate({
30
+ channelToken,
31
+ paymentMethodId,
32
+ orderId: body.id,
33
+ });
30
34
  }
31
35
  catch (error) {
32
36
  core_1.Logger.error(`Failed to process incoming webhook: ${error === null || error === void 0 ? void 0 : error.message}`, constants_1.loggerCtx, error);
@@ -1 +1 @@
1
- {"version":3,"file":"mollie.controller.js","sourceRoot":"","sources":["../../src/mollie/mollie.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+D;AAC/D,wCAAuC;AAEvC,2CAAwC;AACxC,qDAAiD;AAGjD,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IACz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C,IAAI,CAAC,EAAE,EAAE;YACV,OAAO,aAAM,CAAC,IAAI,CAAC,wDAAwD,EAAE,qBAAS,CAAC,CAAC;SAC3F;QACD,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,wBAAwB,CAAC;gBAC9C,YAAY;gBACZ,eAAe;gBACf,OAAO,EAAE,IAAI,CAAC,EAAE;aACnB,CAAC,CAAC;SACN;QAAC,OAAO,KAAU,EAAE;YACjB,aAAM,CAAC,KAAK,CAAC,uCAAuC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,EAAE,qBAAS,EAAE,KAAK,CAAC,CAAC;YACxF,MAAM,KAAK,CAAC;SACf;IACL,CAAC;CACJ,CAAA;AAnBG;IADC,IAAA,aAAI,EAAC,uCAAuC,CAAC;IAEzC,WAAA,IAAA,cAAK,EAAC,cAAc,CAAC,CAAA;IACrB,WAAA,IAAA,cAAK,EAAC,iBAAiB,CAAC,CAAA;IACxB,WAAA,IAAA,aAAI,GAAE,CAAA;;;;+CAeV;AAtBQ,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAEgB,8BAAa;GADvC,gBAAgB,CAuB5B;AAvBY,4CAAgB"}
@@ -19,4 +19,16 @@ export declare const molliePaymentHandler: PaymentMethodHandler<{
19
19
  value: string;
20
20
  }[];
21
21
  };
22
+ autoCapture: {
23
+ type: "boolean";
24
+ label: {
25
+ languageCode: LanguageCode.en;
26
+ value: string;
27
+ }[];
28
+ defaultValue: false;
29
+ description: {
30
+ languageCode: LanguageCode.en;
31
+ value: string;
32
+ }[];
33
+ };
22
34
  }>;
@@ -24,6 +24,7 @@ const api_client_1 = __importStar(require("@mollie/api-client"));
24
24
  const generated_types_1 = require("@vendure/common/lib/generated-types");
25
25
  const core_1 = require("@vendure/core");
26
26
  const constants_1 = require("./constants");
27
+ const mollie_helpers_1 = require("./mollie.helpers");
27
28
  const mollie_service_1 = require("./mollie.service");
28
29
  let mollieService;
29
30
  exports.molliePaymentHandler = new core_1.PaymentMethodHandler({
@@ -46,39 +47,67 @@ exports.molliePaymentHandler = new core_1.PaymentMethodHandler({
46
47
  { languageCode: generated_types_1.LanguageCode.en, value: 'Redirect the client to this URL after payment' },
47
48
  ],
48
49
  },
50
+ autoCapture: {
51
+ type: 'boolean',
52
+ label: [{ languageCode: generated_types_1.LanguageCode.en, value: 'Auto capture payments' }],
53
+ defaultValue: false,
54
+ description: [
55
+ {
56
+ languageCode: generated_types_1.LanguageCode.en,
57
+ value: 'This option only affects pay-later methods. Automatically capture payments immediately after authorization. Without autoCapture orders will remain in the PaymentAuthorized state, and you need to manually settle payments to get paid.',
58
+ },
59
+ ],
60
+ },
49
61
  },
50
62
  init(injector) {
51
63
  mollieService = injector.get(mollie_service_1.MollieService);
52
64
  },
53
65
  createPayment: async (ctx, order, amount, args, metadata) => {
54
- // Creating a payment immediately settles the payment in Mollie flow, so only Admins and internal calls should be allowed to do this
66
+ // Only Admins and internal calls should be allowed to settle and authorize payments
55
67
  if (ctx.apiType !== 'admin') {
56
68
  throw Error(`CreatePayment is not allowed for apiType '${ctx.apiType}'`);
57
69
  }
70
+ if (metadata.status !== 'Authorized' && metadata.status !== 'Settled') {
71
+ throw Error(`Cannot create payment for status ${metadata.status} for order ${order.code}. Only Authorized or Settled are allowed.`);
72
+ }
73
+ core_1.Logger.info(`Payment for order ${order.code} created with state '${metadata.status}'`, constants_1.loggerCtx);
58
74
  return {
59
75
  amount,
60
- state: 'Settled',
61
- transactionId: metadata.paymentId,
76
+ state: metadata.status,
77
+ transactionId: metadata.orderId,
62
78
  metadata, // Store all given metadata on a payment
63
79
  };
64
80
  },
65
81
  settlePayment: async (ctx, order, payment, args) => {
66
- // this should never be called
82
+ // Called for Authorized payments
83
+ const { apiKey } = args;
84
+ const mollieClient = (0, api_client_1.default)({ apiKey });
85
+ const mollieOrder = await mollieClient.orders.get(payment.transactionId);
86
+ // Order could have been completed via Mollie dashboard, then we can just settle
87
+ if (!mollieOrder.isCompleted()) {
88
+ await mollieClient.orders_shipments.create({ orderId: payment.transactionId }); // Creating a shipment captures the payment
89
+ }
90
+ core_1.Logger.info(`Settled payment for ${order.code}`, constants_1.loggerCtx);
67
91
  return { success: true };
68
92
  },
69
93
  createRefund: async (ctx, input, amount, order, payment, args) => {
70
94
  const { apiKey } = args;
71
95
  const mollieClient = (0, api_client_1.default)({ apiKey });
96
+ const mollieOrder = await mollieClient.orders.get(payment.transactionId, {
97
+ embed: [api_client_1.OrderEmbed.payments],
98
+ });
99
+ const molliePayments = await mollieOrder.getPayments();
100
+ const molliePayment = molliePayments.find(p => p.status === api_client_1.PaymentStatus.paid); // Only one paid payment should be there
101
+ if (!molliePayment) {
102
+ throw Error(`No payment with status 'paid' was found in Mollie for order ${order.code} (Mollie order ${mollieOrder.id})`);
103
+ }
72
104
  const refund = await mollieClient.payments_refunds.create({
73
- paymentId: payment.transactionId,
105
+ paymentId: molliePayment.id,
74
106
  description: input.reason,
75
- amount: {
76
- value: (amount / 100).toFixed(2),
77
- currency: order.currencyCode,
78
- },
107
+ amount: (0, mollie_helpers_1.toAmount)(amount, order.currencyCode),
79
108
  });
80
109
  if (refund.status === api_client_1.RefundStatus.failed) {
81
- core_1.Logger.error(`Failed to create refund of ${amount.toFixed()} for order ${order.code} for transaction ${payment.transactionId}`, constants_1.loggerCtx);
110
+ core_1.Logger.error(`Failed to create refund of ${amount.toFixed()} for order ${order.code} for transaction ${molliePayment.id}`, constants_1.loggerCtx);
82
111
  return {
83
112
  state: 'Failed',
84
113
  transactionId: payment.transactionId,
@@ -1 +1 @@
1
- {"version":3,"file":"mollie.handler.js","sourceRoot":"","sources":["../../src/mollie/mollie.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAsE;AACtE,yEAAmE;AACnE,wCAQuB;AAGvB,2CAA6D;AAC7D,qDAAiD;AAEjD,IAAI,aAA4B,CAAC;AACpB,QAAA,oBAAoB,GAAG,IAAI,2BAAoB,CAAC;IACzD,I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EAAE,SAAS;YAChB,aAAa,EAAE,OAAO,CAAC,aAAa;SACvC,CAAC;IACN,CAAC;CACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { CreateParameters } from '@mollie/api-client/dist/types/src/binders/orders/parameters';
2
+ import { Amount } from '@mollie/api-client/dist/types/src/data/global';
3
+ import { OrderAddress as MollieOrderAddress } from '@mollie/api-client/dist/types/src/data/orders/data';
4
+ import { Customer, Order } from '@vendure/core';
5
+ import { OrderAddress } from './graphql/generated-shop-types';
6
+ /**
7
+ * Check if given address has mandatory fields for Mollie Order and map to a MollieOrderAddress.
8
+ * Returns undefined if address doesn't have all mandatory fields
9
+ */
10
+ export declare function toMollieAddress(address: OrderAddress, customer: Customer): MollieOrderAddress | undefined;
11
+ /**
12
+ * Map all order and shipping lines to a single array of Mollie order lines
13
+ */
14
+ export declare function toMollieOrderLines(order: Order): CreateParameters['lines'];
15
+ /**
16
+ * Stringify and fixed decimals
17
+ */
18
+ export declare function toAmount(value: number, orderCurrency: string): Amount;
19
+ /**
20
+ * Lookup one of Mollies allowed locales based on an orders countrycode or channel default.
21
+ * If both lookups fail, resolve to en_US to prevent payment failure
22
+ */
23
+ export declare function getLocale(countryCode: string, channelLanguage: string): string;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocale = exports.toAmount = exports.toMollieOrderLines = exports.toMollieAddress = void 0;
4
+ /**
5
+ * Check if given address has mandatory fields for Mollie Order and map to a MollieOrderAddress.
6
+ * Returns undefined if address doesn't have all mandatory fields
7
+ */
8
+ function toMollieAddress(address, customer) {
9
+ if (address.city && address.countryCode && address.streetLine1 && address.postalCode) {
10
+ return {
11
+ streetAndNumber: `${address.streetLine1} ${address.streetLine2 || ''}`,
12
+ postalCode: address.postalCode,
13
+ city: address.city,
14
+ country: address.countryCode.toUpperCase(),
15
+ givenName: customer.firstName,
16
+ familyName: customer.lastName,
17
+ email: customer.emailAddress,
18
+ };
19
+ }
20
+ }
21
+ exports.toMollieAddress = toMollieAddress;
22
+ /**
23
+ * Map all order and shipping lines to a single array of Mollie order lines
24
+ */
25
+ function toMollieOrderLines(order) {
26
+ // Add order lines
27
+ const lines = order.lines.map(line => ({
28
+ name: line.productVariant.name,
29
+ quantity: line.quantity,
30
+ unitPrice: toAmount(line.proratedUnitPriceWithTax, order.currencyCode),
31
+ totalAmount: toAmount(line.proratedLinePriceWithTax, order.currencyCode),
32
+ vatRate: String(line.taxRate),
33
+ vatAmount: toAmount(line.lineTax, order.currencyCode),
34
+ }));
35
+ // Add shippingLines
36
+ lines.push(...order.shippingLines.map(line => {
37
+ var _a;
38
+ return ({
39
+ name: ((_a = line.shippingMethod) === null || _a === void 0 ? void 0 : _a.name) || 'Shipping',
40
+ quantity: 1,
41
+ unitPrice: toAmount(line.priceWithTax, order.currencyCode),
42
+ totalAmount: toAmount(line.discountedPriceWithTax, order.currencyCode),
43
+ vatRate: String(line.taxRate),
44
+ vatAmount: toAmount(line.discountedPriceWithTax - line.discountedPrice, order.currencyCode),
45
+ });
46
+ }));
47
+ // Add surcharges
48
+ lines.push(...order.surcharges.map(surcharge => ({
49
+ name: surcharge.description,
50
+ quantity: 1,
51
+ unitPrice: toAmount(surcharge.price, order.currencyCode),
52
+ totalAmount: toAmount(surcharge.priceWithTax, order.currencyCode),
53
+ vatRate: String(surcharge.taxRate),
54
+ vatAmount: toAmount(surcharge.priceWithTax - surcharge.price, order.currencyCode),
55
+ })));
56
+ return lines;
57
+ }
58
+ exports.toMollieOrderLines = toMollieOrderLines;
59
+ /**
60
+ * Stringify and fixed decimals
61
+ */
62
+ function toAmount(value, orderCurrency) {
63
+ return {
64
+ value: (value / 100).toFixed(2),
65
+ currency: orderCurrency,
66
+ };
67
+ }
68
+ exports.toAmount = toAmount;
69
+ /**
70
+ * Lookup one of Mollies allowed locales based on an orders countrycode or channel default.
71
+ * If both lookups fail, resolve to en_US to prevent payment failure
72
+ */
73
+ function getLocale(countryCode, channelLanguage) {
74
+ const allowedLocales = [
75
+ 'en_US',
76
+ 'en_GB',
77
+ 'nl_NL',
78
+ 'nl_BE',
79
+ 'fr_FR',
80
+ 'fr_BE',
81
+ 'de_DE',
82
+ 'de_AT',
83
+ 'de_CH',
84
+ 'es_ES',
85
+ 'ca_ES',
86
+ 'pt_PT',
87
+ 'it_IT',
88
+ 'nb_NO',
89
+ 'sv_SE',
90
+ 'fi_FI',
91
+ 'da_DK',
92
+ 'is_IS',
93
+ 'hu_HU',
94
+ 'pl_PL',
95
+ 'lv_LV',
96
+ 'lt_LT',
97
+ ];
98
+ // Prefer order locale if possible
99
+ const orderLocale = allowedLocales.find(locale => locale.toLowerCase().indexOf(countryCode.toLowerCase()) > -1);
100
+ if (orderLocale) {
101
+ return orderLocale;
102
+ }
103
+ // If no order locale, try channel default
104
+ const channelLocale = allowedLocales.find(locale => locale.toLowerCase().indexOf(channelLanguage.toLowerCase()) > -1);
105
+ if (channelLocale) {
106
+ return channelLocale;
107
+ }
108
+ // If no order locale and no channel locale, return a default, otherwise order creation will fail
109
+ return allowedLocales[0];
110
+ }
111
+ exports.getLocale = getLocale;
112
+ //# sourceMappingURL=mollie.helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mollie.helpers.js","sourceRoot":"","sources":["../../src/mollie/mollie.helpers.ts"],"names":[],"mappings":";;;AAOA;;;GAGG;AACH,SAAgB,eAAe,CAAC,OAAqB,EAAE,QAAkB;IACrE,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE;QAClF,OAAO;YACH,eAAe,EAAE,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,IAAI,EAAE,EAAE;YACtE,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE;YAC1C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IAAI,CACnC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,CACzE,CAAC;IACF,IAAI,WAAW,EAAE;QACb,OAAO,WAAW,CAAC;KACtB;IACD,0CAA0C;IAC1C,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CACrC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,CAC7E,CAAC;IACF,IAAI,aAAa,EAAE;QACf,OAAO,aAAa,CAAC;KACxB;IACD,iGAAiG;IACjG,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AAzCD,8BAyCC"}
@@ -100,14 +100,13 @@ export interface MolliePluginOptions {
100
100
  * After completing payment on the Mollie platform,
101
101
  * the user is redirected to the configured redirect url + orderCode: `https://storefront/order/CH234X5`
102
102
  *
103
- * ## Local development
103
+ * ## Pay later methods
104
+ * Mollie supports pay-later methods like 'Klarna Pay Later'. For pay-later methods, the status of an order is
105
+ * 'PaymentAuthorized' after the Mollie hosted checkout. You need to manually settle the payment via the admin ui to capture the payment!
106
+ * Make sure you capture a payment within 28 days, because this is the Klarna expiry time
104
107
  *
105
- * Use something like [localtunnel](https://github.com/localtunnel/localtunnel) to test on localhost.
106
- *
107
- * ```bash
108
- * npx localtunnel --port 3000 --subdomain my-shop-local-dev
109
- * > your url is: https://my-shop-local-dev.loca.lt <- use this as the vendureHost for local dev.
110
- * ```
108
+ * If you don't want this behaviour (Authorized first), you can set 'autoCapture=true' on the payment method. This option will immediately
109
+ * capture the payment after a customer authorizes the payment.
111
110
  *
112
111
  * @docsCategory payments-plugin
113
112
  * @docsPage MolliePlugin
@@ -103,14 +103,13 @@ const mollie_service_1 = require("./mollie.service");
103
103
  * After completing payment on the Mollie platform,
104
104
  * the user is redirected to the configured redirect url + orderCode: `https://storefront/order/CH234X5`
105
105
  *
106
- * ## Local development
106
+ * ## Pay later methods
107
+ * Mollie supports pay-later methods like 'Klarna Pay Later'. For pay-later methods, the status of an order is
108
+ * 'PaymentAuthorized' after the Mollie hosted checkout. You need to manually settle the payment via the admin ui to capture the payment!
109
+ * Make sure you capture a payment within 28 days, because this is the Klarna expiry time
107
110
  *
108
- * Use something like [localtunnel](https://github.com/localtunnel/localtunnel) to test on localhost.
109
- *
110
- * ```bash
111
- * npx localtunnel --port 3000 --subdomain my-shop-local-dev
112
- * > your url is: https://my-shop-local-dev.loca.lt <- use this as the vendureHost for local dev.
113
- * ```
111
+ * If you don't want this behaviour (Authorized first), you can set 'autoCapture=true' on the payment method. This option will immediately
112
+ * capture the payment after a customer authorizes the payment.
114
113
  *
115
114
  * @docsCategory payments-plugin
116
115
  * @docsPage MolliePlugin
@@ -1 +1 @@
1
- {"version":3,"file":"mollie.plugin.js","sourceRoot":"","sources":["../../src/mollie/mollie.plugin.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,wCAAwF;AAGxF,2CAAkD;AAClD,6DAAkD;AAClD,2DAAuD;AACvD,qDAAwD;AACxD,uDAAmD;AACnD,qDAAiD;AAiBjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AAcH,IAAa,YAAY,oBAAzB,MAAa,YAAY;IAGrB;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,OAA4B;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,cAAY,CAAC;IACxB,CAAC;CACJ,CAAA;AAZY,YAAY;IAbxB,IAAA,oBAAa,EAAC;QACX,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,8BAAa,EAAE,EAAE,OAAO,E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oB,CAAC,CAAC;YACvE,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,iBAAiB,EAAE;YACf,MAAM,EAAE,+BAAU;YAClB,SAAS,EAAE,CAAC,gCAAc,CAAC;SAC9B;KACJ,CAAC;GACW,YAAY,CAYxB;AAZY,oCAAY"}
@@ -1,10 +1,11 @@
1
- import { ActiveOrderService, ChannelService, EntityHydrator, OrderService, PaymentMethodService, RequestContext } from '@vendure/core';
1
+ import { Order as MollieOrder } from '@mollie/api-client';
2
+ import { ActiveOrderService, ChannelService, EntityHydrator, Order, OrderService, PaymentMethodService, RequestContext } from '@vendure/core';
2
3
  import { MolliePaymentIntentInput, MolliePaymentIntentResult, MolliePaymentMethod } from './graphql/generated-shop-types';
3
4
  import { MolliePluginOptions } from './mollie.plugin';
4
- interface SettlePaymentInput {
5
+ interface OrderStatusInput {
5
6
  channelToken: string;
6
7
  paymentMethodId: string;
7
- paymentId: string;
8
+ orderId: string;
8
9
  }
9
10
  export declare class MollieService {
10
11
  private paymentMethodService;
@@ -19,9 +20,17 @@ export declare class MollieService {
19
20
  */
20
21
  createPaymentIntent(ctx: RequestContext, { paymentMethodCode, molliePaymentMethodCode }: MolliePaymentIntentInput): Promise<MolliePaymentIntentResult>;
21
22
  /**
22
- * Makes a request to Mollie to verify the given payment by id
23
+ * Update Vendure payments and order status based on the incoming Mollie order
23
24
  */
24
- settlePayment({ channelToken, paymentMethodId, paymentId }: SettlePaymentInput): Promise<void>;
25
+ handleMollieStatusUpdate({ channelToken, paymentMethodId, orderId, }: OrderStatusInput): Promise<void>;
26
+ /**
27
+ * Add payment to order. Can be settled or authorized depending on the payment method.
28
+ */
29
+ addPayment(ctx: RequestContext, order: Order, mollieOrder: MollieOrder, paymentMethodCode: string, status: 'Authorized' | 'Settled'): Promise<Order>;
30
+ /**
31
+ * Settle an existing payment based on the given mollieOrder
32
+ */
33
+ settleExistingPayment(ctx: RequestContext, order: Order, mollieOrderId: string): Promise<void>;
25
34
  getEnabledPaymentMethods(ctx: RequestContext, paymentMethodCode: string): Promise<MolliePaymentMethod[]>;
26
35
  private getPaymentMethod;
27
36
  private createContext;
@@ -33,18 +33,18 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.MollieService = void 0;
35
35
  const api_client_1 = __importStar(require("@mollie/api-client"));
36
- const api_client_2 = require("@mollie/api-client");
37
36
  const common_1 = require("@nestjs/common");
38
37
  const core_1 = require("@vendure/core");
39
38
  const constants_1 = require("./constants");
40
39
  const generated_shop_types_1 = require("./graphql/generated-shop-types");
40
+ const mollie_helpers_1 = require("./mollie.helpers");
41
41
  class PaymentIntentError {
42
42
  constructor(message) {
43
43
  this.message = message;
44
44
  this.errorCode = generated_shop_types_1.ErrorCode.ORDER_PAYMENT_STATE_ERROR;
45
45
  }
46
46
  }
47
- class InvalidInput {
47
+ class InvalidInputError {
48
48
  constructor(message) {
49
49
  this.message = message;
50
50
  this.errorCode = generated_shop_types_1.ErrorCode.INELIGIBLE_PAYMENT_METHOD_ERROR;
@@ -64,18 +64,20 @@ let MollieService = class MollieService {
64
64
  */
65
65
  async createPaymentIntent(ctx, { paymentMethodCode, molliePaymentMethodCode }) {
66
66
  var _a, _b, _c, _d;
67
- const allowedMethods = Object.values(api_client_2.PaymentMethod);
67
+ const allowedMethods = Object.values(api_client_1.PaymentMethod);
68
68
  if (molliePaymentMethodCode && !allowedMethods.includes(molliePaymentMethodCode)) {
69
- return new InvalidInput(`molliePaymentMethodCode has to be one of "${allowedMethods.join(',')}"`);
69
+ return new InvalidInputError(`molliePaymentMethodCode has to be one of "${allowedMethods.join(',')}"`);
70
70
  }
71
71
  const [order, paymentMethod] = await Promise.all([
72
- this.activeOrderService.getOrderFromContext(ctx),
72
+ this.activeOrderService.getActiveOrder(ctx, undefined),
73
73
  this.getPaymentMethod(ctx, paymentMethodCode),
74
74
  ]);
75
75
  if (!order) {
76
76
  return new PaymentIntentError('No active order found for session');
77
77
  }
78
- await this.entityHydrator.hydrate(ctx, order, { relations: ['lines', 'customer', 'shippingLines'] });
78
+ await this.entityHydrator.hydrate(ctx, order, {
79
+ relations: ['customer', 'surcharges', 'lines.productVariant', 'shippingLines.shippingMethod'],
80
+ });
79
81
  if (!((_a = order.lines) === null || _a === void 0 ? void 0 : _a.length)) {
80
82
  return new PaymentIntentError('Cannot create payment intent for empty order');
81
83
  }
@@ -99,60 +101,85 @@ let MollieService = class MollieService {
99
101
  const vendureHost = this.options.vendureHost.endsWith('/')
100
102
  ? this.options.vendureHost.slice(0, -1)
101
103
  : this.options.vendureHost; // remove appending slash
102
- const paymentInput = {
103
- amount: {
104
- value: `${(order.totalWithTax / 100).toFixed(2)}`,
105
- currency: order.currencyCode,
106
- },
107
- metadata: {
108
- orderCode: order.code,
109
- },
110
- description: `Order ${order.code}`,
104
+ const billingAddress = (0, mollie_helpers_1.toMollieAddress)(order.billingAddress, order.customer) ||
105
+ (0, mollie_helpers_1.toMollieAddress)(order.shippingAddress, order.customer);
106
+ if (!billingAddress) {
107
+ return new InvalidInputError(`Order doesn't have a complete shipping address or billing address. At least city, streetline1 and country are needed to create a payment intent.`);
108
+ }
109
+ const orderInput = {
110
+ orderNumber: order.code,
111
+ amount: (0, mollie_helpers_1.toAmount)(order.totalWithTax, order.currencyCode),
111
112
  redirectUrl: `${redirectUrl}/${order.code}`,
112
113
  webhookUrl: `${vendureHost}/payments/mollie/${ctx.channel.token}/${paymentMethod.id}`,
114
+ billingAddress,
115
+ locale: (0, mollie_helpers_1.getLocale)(billingAddress.country, ctx.languageCode),
116
+ lines: (0, mollie_helpers_1.toMollieOrderLines)(order),
113
117
  };
114
118
  if (molliePaymentMethodCode) {
115
- paymentInput.method = molliePaymentMethodCode;
119
+ orderInput.method = molliePaymentMethodCode;
116
120
  }
117
- const payment = await mollieClient.payments.create(paymentInput);
118
- const url = payment.getCheckoutUrl();
121
+ const mollieOrder = await mollieClient.orders.create(orderInput);
122
+ core_1.Logger.info(`Created Mollie order ${mollieOrder.id} for order ${order.code}`);
123
+ const url = mollieOrder.getCheckoutUrl();
119
124
  if (!url) {
120
- throw Error(`Unable to getCheckoutUrl() from Mollie payment`);
125
+ throw Error(`Unable to getCheckoutUrl() from Mollie order`);
121
126
  }
122
127
  return {
123
128
  url,
124
129
  };
125
130
  }
126
131
  /**
127
- * Makes a request to Mollie to verify the given payment by id
132
+ * Update Vendure payments and order status based on the incoming Mollie order
128
133
  */
129
- async settlePayment({ channelToken, paymentMethodId, paymentId }) {
130
- var _a;
134
+ async handleMollieStatusUpdate({ channelToken, paymentMethodId, orderId, }) {
135
+ var _a, _b;
131
136
  const ctx = await this.createContext(channelToken);
132
- core_1.Logger.info(`Received payment for ${channelToken}`, constants_1.loggerCtx);
137
+ core_1.Logger.info(`Received status update for channel ${channelToken} for Mollie order ${orderId}`, constants_1.loggerCtx);
133
138
  const paymentMethod = await this.paymentMethodService.findOne(ctx, paymentMethodId);
134
139
  if (!paymentMethod) {
135
140
  // Fail silently, as we don't want to expose if a paymentMethodId exists or not
136
141
  return core_1.Logger.warn(`No paymentMethod found with id ${paymentMethodId}`, constants_1.loggerCtx);
137
142
  }
138
143
  const apiKey = (_a = paymentMethod.handler.args.find(a => a.name === 'apiKey')) === null || _a === void 0 ? void 0 : _a.value;
144
+ const autoCapture = ((_b = paymentMethod.handler.args.find(a => a.name === 'autoCapture')) === null || _b === void 0 ? void 0 : _b.value) === 'true';
139
145
  if (!apiKey) {
140
146
  throw Error(`No apiKey found for payment ${paymentMethod.id} for channel ${channelToken}`);
141
147
  }
142
148
  const client = (0, api_client_1.default)({ apiKey });
143
- const molliePayment = await client.payments.get(paymentId);
144
- const orderCode = molliePayment.metadata.orderCode;
145
- if (molliePayment.status !== api_client_1.PaymentStatus.paid) {
146
- return core_1.Logger.warn(`Received payment for ${channelToken} for order ${orderCode} with status ${molliePayment.status}`, constants_1.loggerCtx);
149
+ const mollieOrder = await client.orders.get(orderId);
150
+ core_1.Logger.info(`Processing status '${mollieOrder.status}' for order ${mollieOrder.orderNumber} for channel ${channelToken} for Mollie order ${orderId}`, constants_1.loggerCtx);
151
+ let order = await this.orderService.findOneByCode(ctx, mollieOrder.orderNumber, ['payments']);
152
+ if (!order) {
153
+ throw Error(`Unable to find order ${mollieOrder.orderNumber}, unable to process Mollie order ${mollieOrder.id}`);
154
+ }
155
+ if (mollieOrder.status === api_client_1.OrderStatus.paid) {
156
+ // Paid is only used by 1-step payments without Authorized state. This will settle immediately
157
+ await this.addPayment(ctx, order, mollieOrder, paymentMethod.code, 'Settled');
158
+ return;
159
+ }
160
+ if (order.state === 'AddingItems' && mollieOrder.status === api_client_1.OrderStatus.authorized) {
161
+ order = await this.addPayment(ctx, order, mollieOrder, paymentMethod.code, 'Authorized');
162
+ if (autoCapture && mollieOrder.status === api_client_1.OrderStatus.authorized) {
163
+ // Immediately capture payment if autoCapture is set
164
+ core_1.Logger.info(`Auto capturing payment for order ${order.code}`, constants_1.loggerCtx);
165
+ await this.settleExistingPayment(ctx, order, mollieOrder.id);
166
+ }
167
+ return;
147
168
  }
148
- if (!orderCode) {
149
- throw Error(`Molliepayment does not have metadata.orderCode, unable to settle payment ${molliePayment.id}!`);
169
+ if (order.state === 'PaymentAuthorized' && mollieOrder.status === api_client_1.OrderStatus.completed) {
170
+ return this.settleExistingPayment(ctx, order, mollieOrder.id);
150
171
  }
151
- core_1.Logger.info(`Received payment ${molliePayment.id} for order ${orderCode} with status ${molliePayment.status}`, constants_1.loggerCtx);
152
- const order = await this.orderService.findOneByCode(ctx, orderCode);
153
- if (!order) {
154
- throw Error(`Unable to find order ${orderCode}, unable to settle payment ${molliePayment.id}!`);
172
+ if (order.state === 'PaymentAuthorized' || order.state === 'PaymentSettled') {
173
+ core_1.Logger.info(`Order ${order.code} is '${order.state}', no need for handling Mollie status '${mollieOrder.status}'`, constants_1.loggerCtx);
174
+ return;
155
175
  }
176
+ // Any other combination of Mollie status and Vendure status indicates something is wrong.
177
+ throw Error(`Unhandled incoming Mollie status '${mollieOrder.status}' for order ${order.code} with status '${order.state}'`);
178
+ }
179
+ /**
180
+ * Add payment to order. Can be settled or authorized depending on the payment method.
181
+ */
182
+ async addPayment(ctx, order, mollieOrder, paymentMethodCode, status) {
156
183
  if (order.state !== 'ArrangingPayment') {
157
184
  const transitionToStateResult = await this.orderService.transitionToState(ctx, order.id, 'ArrangingPayment');
158
185
  if (transitionToStateResult instanceof core_1.OrderStateTransitionError) {
@@ -160,22 +187,35 @@ let MollieService = class MollieService {
160
187
  }
161
188
  }
162
189
  const addPaymentToOrderResult = await this.orderService.addPaymentToOrder(ctx, order.id, {
163
- method: paymentMethod.code,
190
+ method: paymentMethodCode,
164
191
  metadata: {
165
- paymentId: molliePayment.id,
166
- mode: molliePayment.mode,
167
- method: molliePayment.method,
168
- profileId: molliePayment.profileId,
169
- settlementAmount: molliePayment.settlementAmount,
170
- customerId: molliePayment.customerId,
171
- authorizedAt: molliePayment.authorizedAt,
172
- paidAt: molliePayment.paidAt,
192
+ status,
193
+ orderId: mollieOrder.id,
194
+ mode: mollieOrder.mode,
195
+ method: mollieOrder.method,
196
+ profileId: mollieOrder.profileId,
197
+ settlementAmount: mollieOrder.amount,
198
+ authorizedAt: mollieOrder.authorizedAt,
199
+ paidAt: mollieOrder.paidAt,
173
200
  },
174
201
  });
175
202
  if (!(addPaymentToOrderResult instanceof core_1.Order)) {
176
- throw Error(`Error adding payment to order ${orderCode}: ${addPaymentToOrderResult.message}`);
203
+ throw Error(`Error adding payment to order ${order.code}: ${addPaymentToOrderResult.message}`);
204
+ }
205
+ return addPaymentToOrderResult;
206
+ }
207
+ /**
208
+ * Settle an existing payment based on the given mollieOrder
209
+ */
210
+ async settleExistingPayment(ctx, order, mollieOrderId) {
211
+ const payment = order.payments.find(p => p.transactionId === mollieOrderId);
212
+ if (!payment) {
213
+ throw Error(`Cannot find payment ${mollieOrderId} for ${order.code}. Unable to settle this payment`);
214
+ }
215
+ const result = await this.orderService.settlePayment(ctx, payment.id);
216
+ if (result.message) {
217
+ throw Error(`Error settling payment ${payment.id} for order ${order.code}: ${result.errorCode} - ${result.message}`);
177
218
  }
178
- core_1.Logger.info(`Payment for order ${molliePayment.metadata.orderCode} settled`, constants_1.loggerCtx);
179
219
  }
180
220
  async getEnabledPaymentMethods(ctx, paymentMethodCode) {
181
221
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"mollie.service.js","sourceRoot":"","sources":["../../src/mollie/mollie.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAuE;AACvE,mDAAyE;AAEzE,2CAAoD;AACpD,wCAYuB;AAEvB,2CAA6D;AAC7D,yEAMwC;AASxC,MAAM,kBAAkB;IAGpB,YAAmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlC,cAAS,GAAG,gCAAS,CAAC,yBAAyB,CAAC;IAEX,CAAC;CACzC;AAED,MAAM,YAAY;IAGd,YAAmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlC,cAAS,GAAG,gCAAS,CAAC,+BAA+B,CAAC;IAEjB,CAAC;CACzC;AAGD,IAAa,aAAa,GAA1B,MAAa,aAAa;IACtB,YACY,oBAA0C,EACb,OAA4B,EACzD,kBAAsC,EACtC,YAA0B,EAC1B,cAA8B,EAC9B,cAA8B;QAL9B,yBAAoB,GAApB,oBAAoB,CAAsB;QACb,YAAO,GAAP,OAAO,CAAqB;QACzD,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;IACvC,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,mBAAmB,CACrB,GAAmB,EACnB,EAAE,iBAAiB,EAAE,uBAAuB,EAA4B;;QAExE,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,0BAAkB,CAAa,CAAC;QACrE,IAAI,uBAAuB,IAAI,CAAC,cAAc,CAAC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AAC,CAAC;IACP,CAAC;CACJ,CAAA;AA7PY,aAAa;IADzB,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,eAAM,EAAC,+BAAmB,CAAC,CAAA;qCADE,2BAAoB,UAEtB,yBAAkB;QACxB,mBAAY;QACV,qBAAc;QACd,qBAAc;GAPjC,aAAa,CA6PzB;AA7PY,sCAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendure/payments-plugin",
3
- "version": "2.0.0-next.23",
3
+ "version": "2.0.0-next.25",
4
4
  "license": "MIT",
5
5
  "main": "package/index.js",
6
6
  "types": "package/index.d.ts",
@@ -13,7 +13,8 @@
13
13
  "build": "rimraf package && tsc -p ./tsconfig.build.json",
14
14
  "e2e": "jest --config ../../e2e-common/jest-config.js --runInBand --package=payments-plugin",
15
15
  "lint": "tslint --fix --project ./",
16
- "ci": "yarn build"
16
+ "ci": "yarn build",
17
+ "dev-server:mollie": "yarn build && DB=sqlite node -r ts-node/register e2e/mollie-dev-server.ts"
17
18
  },
18
19
  "homepage": "https://www.vendure.io/",
19
20
  "funding": "https://github.com/sponsors/michaelbromley",
@@ -28,14 +29,14 @@
28
29
  "devDependencies": {
29
30
  "@mollie/api-client": "^3.6.0",
30
31
  "@types/braintree": "^2.22.15",
31
- "@vendure/common": "^2.0.0-next.23",
32
- "@vendure/core": "^2.0.0-next.23",
33
- "@vendure/testing": "^2.0.0-next.23",
32
+ "@vendure/common": "^2.0.0-next.25",
33
+ "@vendure/core": "^2.0.0-next.25",
34
+ "@vendure/testing": "^2.0.0-next.25",
34
35
  "braintree": "^3.0.0",
35
36
  "nock": "^13.1.4",
36
37
  "rimraf": "^3.0.2",
37
38
  "stripe": "^8.197.0",
38
39
  "typescript": "4.5.5"
39
40
  },
40
- "gitHead": "ca728cb4d755c575a7b084a97d0d871016cd6e38"
41
+ "gitHead": "1f9b6192a269ef4242da0143ea460a512af964d4"
41
42
  }