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/mollie failing webhook #3014

Conversation

martijnvdbrug
Copy link
Collaborator

@martijnvdbrug martijnvdbrug commented Aug 15, 2024

Description

Fixes #2941

  • We create new Mollie orders on every payment intent. No changing Mollie orders anymore. This was suggested by the Mollie engineers and is also how Shopify handles Mollie payments.
  • We now log an error when a customer still manages to pay twice for an order.

Breaking changes

Removed order.customFields.mollieOrderId, because we dont need a reference to Mollie anymore, but a migration is not per se needed, because its only a field removal.

Screenshots

image

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Aug 15, 2024 10:51am

},
});
expect(createPaymentMethod.code).toBe(mockData.methodCode);
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved to top, because payment method creation should happen before creating orders

Comment on lines +271 to +278
if (!paymentWithSameTransactionId) {
// The order is paid for again, with another transaction ID. This means the customer paid twice
Logger.error(
`Order '${order.code}' is already paid. Mollie order '${mollieOrder.id}' should be refunded.`,
loggerCtx,
);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can tap into this error log and automatically report this to Sentry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we have done in one of our projects is to create a SentryLogger that is a wrapper around a VendureLogger, which sends all error logs to Sentry. You could use a similar approach and filter out only this message. We could add a prefix/constant in the log message to make sure that is always in the error message.

// Error function in our SentryLogger class

  error(message: string, context?: string | undefined, trace?: string | undefined,
  ): void {
    Sentry.captureMessage(message, "error");
    this.logger.error(message, context, trace);
  }

Any alternative suggestions welcome, but I dont think there is any error emitting way of working in Vendure currently?

The alternative is to throw an error that you can handle somewhere, but this will also make Mollie retry this webhook until we return a status 200

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wrapper logger would work well, since I also need it for some other logs. Thanks for the suggestion!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message is checked in the test. I will add a comment that the message shouldn't be changed because monitoring can depend on it.

@michaelbromley michaelbromley merged commit 694845f into vendure-ecommerce:master Aug 19, 2024
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 2024
@michaelbromley
Copy link
Member

Thanks for the fix! I'll be publishing a patch this week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mollie doesn't call webhook
3 participants