Skip to content

Commit

Permalink
Merge branch 'minor' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Mar 24, 2023
2 parents 98c764c + 564eff6 commit f81c5e8
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 304 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## <small>1.9.5 (2023-03-24)</small>

#### Fixes
* **payments-plugin** Fix issue with handling of partial payments in Mollie. If you are using the MolliePlugin you should update as a priority. ([#2092](https://github.com/vendure-ecommerce/vendure/pull/2092))

## <small>1.9.4 (2023-03-22)</small>


Expand Down
2 changes: 2 additions & 0 deletions packages/payments-plugin/e2e/graphql/admin-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const GET_ORDER_PAYMENTS = gql`
query order($id: ID!) {
order(id: $id) {
id
state
totalWithTax
payments {
id
transactionId
Expand Down
635 changes: 338 additions & 297 deletions packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/payments-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"braintree": "3.x",
"stripe": "8.x"
},
"dependencies": {
"currency.js": "2.0.4"
},
"peerDependenciesMeta": {
"@mollie/api-client": {
"optional": true
Expand Down
9 changes: 3 additions & 6 deletions packages/payments-plugin/src/mollie/mollie.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const molliePaymentHandler = new PaymentMethodHandler({
createPayment: async (
ctx,
order,
amount,
_amount, // Don't use this amount, but the amount from the metadata
args,
metadata,
): Promise<CreatePaymentResult | CreatePaymentErrorResult> => {
Expand All @@ -70,12 +70,9 @@ export const molliePaymentHandler = new PaymentMethodHandler({
}. Only Authorized or Settled are allowed.`,
);
}
Logger.info(
`Payment for order ${order.code} created with state '${metadata.status as string}'`,
loggerCtx,
);
Logger.info(`Payment for order ${order.code} with amount ${metadata.amount} created with state '${metadata.status}'`, loggerCtx);
return {
amount,
amount: metadata.amount,
state: metadata.status,
transactionId: metadata.orderId, // The plugin now only supports 1 payment per order, so a mollie order equals a payment
metadata, // Store all given metadata on a payment
Expand Down
8 changes: 8 additions & 0 deletions packages/payments-plugin/src/mollie/mollie.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CreateParameters } from '@mollie/api-client/dist/types/src/binders/orde
import { Amount } from '@mollie/api-client/dist/types/src/data/global';
import { OrderAddress as MollieOrderAddress } from '@mollie/api-client/dist/types/src/data/orders/data';
import { Customer, Order } from '@vendure/core';
import currency from 'currency.js';

import { OrderAddress } from './graphql/generated-shop-types';

Expand Down Expand Up @@ -81,6 +82,13 @@ export function toAmount(value: number, orderCurrency: string): Amount {
};
}

/**
* Return to number of cents
*/
export function amountToCents(amount: Amount): number {
return currency(amount.value).intValue;
}

/**
* Recalculate tax amount per order line instead of per unit for Mollie.
* Vendure calculates tax per unit, but Mollie expects the tax to be calculated per order line (the total of the quantities).
Expand Down
3 changes: 2 additions & 1 deletion packages/payments-plugin/src/mollie/mollie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
MolliePaymentIntentResult,
MolliePaymentMethod,
} from './graphql/generated-shop-types';
import { getLocale, toAmount, toMollieAddress, toMollieOrderLines } from './mollie.helpers';
import { amountToCents, getLocale, toAmount, toMollieAddress, toMollieOrderLines } from './mollie.helpers';
import { MolliePluginOptions } from './mollie.plugin';

interface OrderStatusInput {
Expand Down Expand Up @@ -245,6 +245,7 @@ export class MollieService {
const addPaymentToOrderResult = await this.orderService.addPaymentToOrder(ctx, order.id, {
method: paymentMethodCode,
metadata: {
amount: amountToCents(mollieOrder.amount),
status,
orderId: mollieOrder.id,
mode: mollieOrder.mode,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7244,6 +7244,11 @@ cuint@^0.2.2:
resolved "https://registry.yarnpkg.com/cuint/-/cuint-0.2.2.tgz#408086d409550c2631155619e9fa7bcadc3b991b"
integrity sha512-d4ZVpCW31eWwCMe1YT3ur7mUDnTXbgwyzaL320DrcRT45rfjYxkt5QWLrmOJ+/UEAI2+fQgKe/fCjR8l4TpRgw==

currency.js@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/currency.js/-/currency.js-2.0.4.tgz#a8a4d69be3b2e509bf67a560c78220bc04809cf1"
integrity sha512-6/OplJYgJ0RUlli74d93HJ/OsKVBi8lB1+Z6eJYS1YZzBuIp4qKKHpJ7ad+GvTlWmLR/hLJOWTykN5Nm8NJ7+w==

custom-event@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/custom-event/-/custom-event-1.0.1.tgz#5d02a46850adf1b4a317946a3928fccb5bfd0425"
Expand Down

0 comments on commit f81c5e8

Please sign in to comment.