Socket
Socket
Sign inDemoInstall

mollie-es6

Package Overview
Dependencies
24
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mollie-es6

Mollie module in ES6


Version published
Weekly downloads
4
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Mollie

Mollie API client in ES6

Mollie API client written in ES6 by an official Mollie Partner / Reseller.

Requirements

To use the this module, the following is required:

  • Node.js v6.0.0 or higher
  • You can Sign up here for free.

Installation

You can install this module with NPM:

npm install --save mollie-es6

Getting started

Examples are in Express.js

Require the library.

    const mollie = require('mollie-es6');

Set the basics needed

    mollie.api_key = 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM';

All callback functions now return promises, which you can either yield in a try / catch or resolve itfoo.then().catch()

Create a new payment.

    try {
        const payment = yield mollie.payments.create({
            amount:      10.00,
            description: "My first API payment",
            redirectUrl: "https://webshop.com/api/payments/response"
        });
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }

Retrieving a payment.

    const payment_id = 'some_id';
    try {
        const payment = yield mollie.payments.get(payment_id);
        if(payment.isPaid()) {
            console.log('Payment is paid');
        }
    } catch (e) {
        // Handle error
    }

Implemented Functions

Payments

Create
Normal
    try {
        const payment = yield mollie.payments.create({
            amount:      10.00,
            description: "My first API payment",
            redirectUrl: "https://webshop.com/api/payments/response"
        });
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }
Recurring
    try {
        const payment = yield mollie.payments.create(
            amount,
            description,
            redirectUrl,
            {
                recurringType: 'first' || 'recurring',
                customerId: 'John Cena'
            }
        );
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }
Get
    const payment_id = 'some_id';
    const options = {
        method: 'creditcard'
    };
    try {
        const payment = yield mollie.payments.get(payment_id, options);
        if(payment.isPaid()) {
            console.log('Payment is paid');
        }
    } catch (e) {
        // Handle error
    }
List
    const options = {
        count: 100,
        offset: 200
    }
    try {
        const payments_list = yield mollie.payments.list(options);
        /*
        payments_list = {
            totalCount: Number,
            offset:     Number,
            count:      Number,
            data:       [Payments],
            links: {
                first:      String(url),
                previous:   String(url),
                next:       String(url),
                last:       String(url)
            }
        }
        */
    } catch (e) {
        // Handle error
    }

Methods

List
    const options = {
        count: 10,
        offset: 5
    }
    try {
        const methods_list = yield mollie.methods.list(options);
        /*
        methods_list = {
            totalCount: Number,
            offset:     Number,
            count:      Number,
            data:       [Methods],
            links: {
                first:      String(url),
                previous:   String(url),
                next:       String(url),
                last:       String(url)
            }
        }
        */
    } catch (e) {
        // Handle error
    }
Get
    const amount = 100.00;
    const method_id = 'creditcard';

    try {
        const method = yield mollie.methods.get(method_id);
        if(method.getMinAmount() < amount && method.getMaxAmount > amount) {
            // Allow user to check out
        }
    } catch (e) {
        // Handle error
    }

Issuers

This part is iDEAL only. Using issuers makes it possible to integrate the bank choice in your own system.

List
    const options = {
        count: 20,
        offset: 2
    }
    try {
        const issuers_list = yield mollie.issuers.list(options);
        /*
        issuers_list = {
            totalCount: Number,
            offset:     Number,
            count:      Number,
            data:       [Issuers],
            links: {
                first:      String(url),
                previous:   String(url),
                next:       String(url),
                last:       String(url)
            }
        }
        */
    } catch (e) {
        // Handle error
    }
Get
    const issuer_id = 'ideal_ABNANL2A';

    try {
        const issuer = yield mollie.issuers.get(issuer_id);
        // Do something with this issuer
    } catch (e) {
        // Handle error
    }

Refunds

Create
    try {
        const refund_id = 'some_id';
        const amount = 5.00; // This is optional, if omitted,
                             // the full amount will be refunded
        const refund = yield mollie.refunds.create(refund_id, amount);
    } catch (e) {
        // Handle error
    }
Get
    const payment_id = 'payment_id';
    const refund_id = 'refund_id'
    try {
        const refund = yield mollie.refunds.get(payment_id, refund_id);
        if(refund.payment.isFullyRefunded()) {
            console.log('Payment is fully refunded');
        }
    } catch (e) {
        // Handle error
    }
List
    const payment_id = 'payment_id';
    const options = {
        count: 10,
        offset: 2
    }
    try {
        const payments_list = yield mollie.refunds.list(payment_id, options);
    } catch (e) {
        // Handle error
    }
Cancel
    const payment_id = 'payment_id';
    const refund_id = 'refund_id'
    try {
        const refund = yield mollie.refunds.cancel(payment_id, refund_id);
    } catch (e) {
        // Handle error
    }

Keywords

FAQs

Last updated on 18 Jun 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc