Socket
Socket
Sign inDemoInstall

mollie-es6

Package Overview
Dependencies
40
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
Maintainers
1
Created

Readme

Source

Mollie

Mollie API client in ES6

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

Build Status Dependency Status NSP Status

Requirements

To use the this module, the following is required:

  • Node.js v6.0.0 or higher
  • You can Sign up here for free.
  • If you need any help with setting it up, just contact us @GeeX_dev on twitter or mail us at development@geex.company

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 are now generatos. You can call .next() on them or when using something like co, you can just add yield in a try / catch, like in the examples below.

Create a new payment.

    co.wrap(function*() {
        const amount = 10.00;
        const description = 'My first API payment';
        const redirectUrl = 'http://example.org/order/12345';
        try {
            const payment = yield mollie.payments.create(
                amount,
                description,
                redirectUrl
            );
            res.redirect(payment.getPaymentUrl());
        } catch (e) {
            // Handle error
        }
    });

Retrieving a payment.

    co.wrap(function*() {
        const payment_id = 'payment_id';
        try {
            const payment = yield mollie.payments.get(payment_id);
            if(payment.isPaid()) {
                console.log('Payment is fulfilled');
            }
        } catch (e) {
            // Handle error
        }
    });

Implemented Functions

Payments

Create
Normal
    const amount = 10.00;
    const description = 'My first API payment';
    const redirectUrl = 'http://example.org/order/12345';
    try {
        const payment = yield mollie.payments.create(
            amount,
            description,
            redirectUrl
        );
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }
Recurring
    const amount = 10.00;
    const description = 'My first API recurring payment';
    const redirectUrl = 'http://example.org/order/12345';
    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 = 'payment_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
    }

Customers

Create
Normal
    try {
        const customer = yield mollie.customers.create(
            'Customer name',
            'info@domain.tld',
            {locale: 'en', metadata: {something: 'here'}}
        );
        // New customer created, do something fun with it
    } catch (e) {
        // Handle error
    }
Get
    const customer_id = 'some_id';
    try {
        const customer = yield mollie.customers.get(customer_id);
        // Do something with this customer data
    } catch (e) {
        // Handle error
    }
List
    const options = {
        count: 100,
        offset: 200
    }
    try {
        const customer_list = yield mollie.customers.list(options);
        /*
        customer_list = {
            totalCount: Number,
            offset:     Number,
            count:      Number,
            data:       [Customers],
            links: {
                first:      String(url),
                previous:   String(url),
                next:       String(url),
                last:       String(url)
            }
        }
        */
    } catch (e) {
        // Handle error
    }

Keywords

FAQs

Last updated on 28 Mar 2017

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