Skip to content

Instantly share code, notes, and snippets.

@martijnvdbrug
Created July 23, 2024 08:43
Show Gist options
  • Save martijnvdbrug/361a3048ce0f26ec4c428cf717889651 to your computer and use it in GitHub Desktop.
Save martijnvdbrug/361a3048ce0f26ec4c428cf717889651 to your computer and use it in GitHub Desktop.
// Create an .env file with MOLLIE_APIKEY=YOUR_API_KEY, where YOUR_API_KEY is the api key of your test account
// Run this script with "node reproduce.js"
// Click the payment link in the console, pay for the order using iDeal
// See the error in your browser, and see in the Mollie dashboard that
const { createMollieClient } = require('@mollie/api-client');
const axios = require('axios');
(async () => {
require('dotenv').config();
const apiKey = process.env.MOLLIE_APIKEY;
const webhookCatcherUrl = "https://pinelab-mollie.requestcatcher.com/test";
const client = createMollieClient({ apiKey});
const billingAddress = {
streetAndNumber: "Cornelist Trooststraat 48",
postalCode: "8934 CC",
city: "Leeuwarden",
country: "NL",
givenName: "Martijn",
familyName: "Van de Brug",
email: "[email protected]",
};
const orderLine = {
name: "Sample product",
quantity: 1,
unitPrice: {
value: "123.45",
currency: "EUR",
},
totalAmount: {
value: "123.45",
currency: "EUR",
},
vatRate: "21.00",
vatAmount: {
value: "21.43",
currency: "EUR",
},
}
let order = await client.orders.create({
orderNumber: "ERROR-REPRO",
amount: {
value: "123.45",
currency: "EUR",
},
redirectUrl: "https://my.mollie.com/dashboard/org_10091657/orders/",
webhookUrl: webhookCatcherUrl,
billingAddress,
locale: "nl_NL",
lines: [orderLine],
metadata: {
languageCode: "en_EN",
}
});
console.log(`Created order ${order.id}: ${order.getCheckoutUrl()}`);
// We recreate order lines, to make sure the Mollie order matches our Vendure order when attempting another payment
// This feature is not part of the Mollie NodeJS client yet, so we have to call the API ourselves
const {data, status} = await axios({
url: `https://api.mollie.com/v2/orders/${order.id}/lines`,
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
data: {
operations: [
{
operation: 'cancel',
data: { id: order.lines[0].id }
},
{
operation: 'add',
data: orderLine
}
]
}
});
console.log(`Updated order lines: ${status}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment