Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* @docs https://docs.mollie.com/reference/v2/refunds-api/create-refund
* @docs https://docs.mollie.com/reference/v2/orders-api/create-order-refund
*/
import createMollieClient, { Refund } from '@mollie/api-client';
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
// Create payment refund
const paymentRefund: Refund = await mollieClient.payments_refunds.create({
paymentId: 'tr_WDqYK6vllg',
amount: {
value: '5.95',
currency: 'EUR',
},
});
console.log(paymentRefund);
// Create order refund
const orderRefund: Refund = await mollieClient.orders_refunds.create({
/**
* @docs https://docs.mollie.com/reference/v2/refunds-api/list-refunds
* @docs https://docs.mollie.com/reference/v2/orders-api/list-order-refunds
*/
import createMollieClient, { List, Refund } from '@mollie/api-client';
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
// Payment refunds
const paymentRefunds: List = await mollieClient.payments_refunds.all({ paymentId: 'tr_WDqYK6vllg' });
console.log(paymentRefunds);
// Order refunds
const orderRefunds: List = await mollieClient.orders_refunds.all({ orderId: 'ord_stTC2WHAuS' });
console.log(orderRefunds);
} catch (error) {
console.warn(error);
}
})();
/**
* Example 01 - How to prepare a new payment with the Mollie API.
*/
const express = require('express');
const { createMollieClient } = require('@mollie/api-client');
const app = express();
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
app.get('/', (req, res) => {
const orderId = new Date().getTime();
mollieClient.payments
.create({
amount: { value: '10.00', currency: 'USD' },
description: 'New payment',
redirectUrl: `https://example.org/redirect?orderId=${orderId}`,
webhookUrl: `http://example.org/webhook?orderId=${orderId}`,
metadata: { orderId },
})
.then(payment => {
// Redirect the consumer to complete the payment using `payment.getPaymentUrl()`.
res.redirect(payment.getPaymentUrl());
})
/**
* Example 11 - How to create an on-demand recurring payment.
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
mollieClient.customers
.all()
.then(customers => {
const customerId = customers[0].id; // Select one of your customers.
const orderId = new Date().getTime();
mollieClient.customers_payments
.create({
amount: { value: '10.00', currency: 'EUR' },
description: `Recurring payment for customer ${customerId}`,
redirectUrl: `https://example.org/redirect?orderId=${orderId}`,
webhookUrl: `http://example.org/webhook?orderId=${orderId}`,
metadata: { orderId },
customerId,
sequenceType: 'recurring',
/**
* @docs https://docs.mollie.com/reference/v2/payments-api/create-payment
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
const payment = await mollieClient.payments.create({
amount: {
currency: 'EUR',
value: '10.00', // You must send the correct number of decimals, thus we enforce the use of strings
},
description: 'My first payment',
redirectUrl: 'https://webshop.example.org/order/12345/',
webhookUrl: 'https://webshop.example.org/payments/webhook/',
metadata: {
order_id: '12345',
},
});
/**
* Example 07 - How to create a new customer.
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
mollieClient.customers
.create({
name: 'Luke Skywalker',
email: 'luke@example.org',
metadata: {
isJedi: true,
},
})
.then(customer => {
// New customer created with ID `customer.id` and name `customer.name`.
})
.catch(error => {
// Do some proper error handling.
});
/**
* @docs https://docs.mollie.com/reference/v2/mandates-api/create-mandate
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
const mandate = await mollieClient.customers_mandates.create({
customerId: 'cst_pzhEvnttJ2',
method: 'directdebit',
consumerName: 'John Doe',
consumerAccount: 'NL55INGB0000000000',
consumerBic: 'INGBNL2A',
signatureDate: '2018-05-07',
mandateReference: 'YOUR-COMPANY-MD13804',
});
console.log(mandate);
} catch (e) {
console.log(e);
/**
* @docs https://docs.mollie.com/reference/v2/customers-api/update-customer
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
const customer = await mollieClient.customers.update('cst_pzhEvnttJ2', {
name: 'Updated customer name',
email: 'updated-email@example.org',
});
console.log(customer);
} catch (e) {
console.log(e);
}
})();
/**
* @docs https://docs.mollie.com/reference/v2/customers-api/list-customers
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
const customers = await mollieClient.customers.all();
console.log(customers);
} catch (e) {
console.log(e);
}
})();
/**
* @docs https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
*/
const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });
(async () => {
try {
const customerId = 'cst_pzhEvnttJ2';
const payment = await mollieClient.customers_payments.create({
amount: { value: '10.00', currency: 'EUR' },
description: 'Recurring payment',
redirectUrl: 'https://example.org/redirect',
webhookUrl: 'http://example.org/webhook',
metadata: { orderId: 'Order #23' },
customerId,
sequenceType: 'recurring',
});
console.log(payment);