How to use the @mollie/api-client.createMollieClient function in @mollie/api-client

To help you get started, we’ve selected a few @mollie/api-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mollie / mollie-api-node / examples / with-express / 01-new-payment.js View on Github external
/**
 * 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());
    })
github mollie / mollie-api-node / examples / with-express / 11-recurring-payment.js View on Github external
/**
 * 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',
github mollie / mollie-api-node / examples / payments / create.js View on Github external
/**
 * @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',
      },
    });
github mollie / mollie-api-node / examples / with-express / 07-new-customer.js View on Github external
/**
 * 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.
  });
github mollie / mollie-api-node / examples / mandates / create.js View on Github external
/**
 * @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);
github mollie / mollie-api-node / examples / customers / update.js View on Github external
/**
 * @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);
  }
})();
github mollie / mollie-api-node / examples / customers / list.js View on Github external
/**
 * @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);
  }
})();
github mollie / mollie-api-node / examples / customers / create-recurring-payment.js View on Github external
/**
 * @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);
github mollie / mollie-api-node / examples / subscriptions / create.js View on Github external
/**
 * @docs https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription
 */
const { createMollieClient } = require('@mollie/api-client');

const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });

(async () => {
  try {
    const subscription = await mollieClient.customers_subscriptions.create({
      customerId: 'cst_pzhEvnttJ2',
      amount: { value: '24.00', currency: 'EUR' },
      times: 4,
      interval: '3 months',
      description: 'Quarterly payment',
      webhookUrl: 'https://webshop.example.org/payments/webhook/',
    });

    console.log(subscription);
  } catch (e) {
    console.log(e);
  }
github mollie / mollie-api-node / examples / orders / list.js View on Github external
/**
 * @docs https://docs.mollie.com/reference/v2/orders-api/list-orders
 */
const { createMollieClient } = require('@mollie/api-client');

const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });

(async () => {
  try {
    const mostRecentOrders = await mollieClient.orders.all();
    const previousOrders = await mostRecentOrders.nextPage();

    console.log(mostRecentOrders);
    console.log(previousOrders);
  } catch (error) {
    console.warn(error);
  }
})();