npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mollie-es6

v3.1.0

Published

Mollie module in ES6

Downloads

86

Readme

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:

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');

Initialize

    const mollieApp = new Mollie('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 = 'https://example.org/order/12345';
        try {
            const payment = yield mollieApp.payments.create(
                amount,
                description,
                redirectUrl
            );
            res.redirect(payment.getPaymentUrl());
        } catch (e) {
            // Handle error
        }
    });

Retrieving a payment.

    co.wrap(function*() {
        const paymentId = 'paymentId';
        try {
            const payment = yield mollieApp.payments.get(paymentId);
            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 = 'https://example.org/order/12345';
    try {
        const payment = yield mollieApp.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 = 'https://example.org/order/12345';
    try {
        const payment = yield mollieApp.payments.create(
            amount,
            description,
            redirectUrl,
            {
                recurringType: 'first' || 'recurring',
                customerId: 'John Cena'
            }
        );
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }

Get

    const paymentId = 'paymentId';
    const options = {
        method: 'creditcard'
    };
    try {
        const payment = yield mollieApp.payments.get(paymentId, 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 mollieApp.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 mollieApp.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 methodId = 'creditcard';

    try {
        const method = yield mollieApp.methods.get(methodId);
        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 mollieApp.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 issuerId = 'ideal_ABNANL2A';

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

Refunds

Create

    try {
        const refundId = 'someId';
        const amount = 5.00; // This is optional, if omitted,
                             // the full amount will be refunded
        const refund = yield mollieApp.refunds.create(refundId, amount);
    } catch (e) {
        // Handle error
    }

Get

    const paymentId = 'paymentId';
    const refundId = 'refundId'
    try {
        const refund = yield mollieApp.refunds.get(paymentId, refundId);
        if(refund.payment.isFullyRefunded()) {
            console.log('Payment is fully refunded');
        }
    } catch (e) {
        // Handle error
    }

List

    const paymentId = 'paymentId';
    const options = {
        count: 10,
        offset: 2
    }
    try {
        const payments_list = yield mollieApp.refunds.list(paymentId, options);
    } catch (e) {
        // Handle error
    }

Cancel

    const paymentId = 'paymentId';
    const refundId = 'refundId'
    try {
        const refund = yield mollieApp.refunds.cancel(paymentId, refundId);
    } catch (e) {
        // Handle error
    }

Customers

Create

Normal
    try {
        const customer = yield mollieApp.customers.create(
            'Customer name',
            '[email protected]',
            {locale: 'en', metadata: {something: 'here'}}
        );
        // New customer created, do something fun with it
    } catch (e) {
        // Handle error
    }

Get

    const customerId = 'someId';
    try {
        const customer = yield mollieApp.customers.get(customerId);
        // Do something with this customer data
    } catch (e) {
        // Handle error
    }

List

    const options = {
        count: 100,
        offset: 200
    }
    try {
        const customer_list = yield mollieApp.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
    }