Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payments-plugin): Idempotent 'paid' Mollie webhooks #2462

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
18 changes: 10 additions & 8 deletions packages/payments-plugin/src/mollie/mollie.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ export function toMollieOrderLines(order: Order, alreadyPaid: number): CreatePar
vatAmount: toAmount(surcharge.priceWithTax - surcharge.price, order.currencyCode),
})));
// Deduct amount already paid
lines.push({
name: 'Already paid',
quantity: 1,
unitPrice: toAmount(-alreadyPaid, order.currencyCode),
totalAmount: toAmount(-alreadyPaid, order.currencyCode),
vatRate: String(0),
vatAmount: toAmount(0, order.currencyCode),
});
if (alreadyPaid) {
lines.push({
name: 'Already paid',
quantity: 1,
unitPrice: toAmount(-alreadyPaid, order.currencyCode),
totalAmount: toAmount(-alreadyPaid, order.currencyCode),
vatRate: String(0),
vatAmount: toAmount(0, order.currencyCode),
});
}
return lines;
}

Expand Down
14 changes: 7 additions & 7 deletions packages/payments-plugin/src/mollie/mollie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ export class MollieService {
`Unable to find order ${mollieOrder.orderNumber}, unable to process Mollie order ${mollieOrder.id}`,
);
}
if (order.state === 'PaymentSettled') {
Logger.info(
`Order ${order.code} is already 'PaymentSettled', no need for handling Mollie status '${mollieOrder.status}'`,
loggerCtx,
);
return;
}
if (mollieOrder.status === OrderStatus.expired) {
// Expired is fine, a customer can retry the payment later
return;
Expand All @@ -248,13 +255,6 @@ export class MollieService {
if (order.state === 'PaymentAuthorized' && mollieOrder.status === OrderStatus.completed) {
return this.settleExistingPayment(ctx, order, mollieOrder.id);
}
if (order.state === 'PaymentAuthorized' || order.state === 'PaymentSettled') {
Logger.info(
`Order ${order.code} is '${order.state}', no need for handling Mollie status '${mollieOrder.status}'`,
loggerCtx,
);
return;
}
// Any other combination of Mollie status and Vendure status indicates something is wrong.
throw Error(
`Unhandled incoming Mollie status '${mollieOrder.status}' for order ${order.code} with status '${order.state}'`,
Expand Down
Loading