0.5.0 • Published 8 years ago

mollie-reseller-es6 v0.5.0

Weekly downloads
7
License
GPL-3.0
Repository
github
Last release
8 years ago

Mollie

Mollie Reseller API client in ES6

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

Note: Till version 1.0 of this module, not all functions are implemented and / or tested check below to see a full list of implemented functions and how to use them.

Requirements

To use the this module, the following is required:

  • Node.js v6.0.0 or higher
  • You can Sign up here for free.
  • You need to accept the Mollie Reseller Agreement for this module to work

Installation

You can install this module with NPM:

npm install --save mollie-reseller-es6

Getting started

Require the library.

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

Set the basics needed

    const keys = {
        "partner_id": 1234567,
        "profile_key": "profile_key",
        "secret": "site_secret"
    }
    const reseller = new API(keys);

All (main) functions return promises, which you can either yield in a try / catch or resolve it foo.then().catch()

Tips

If you're managing multiple reseller accounts on 1 server, it's ofcourse also possible to instantiate the class multiple times.

    const account_1 = new API(keys_1);
    const account_2 = new API(keys_2);

Implemented instance functions

Account

Claim

    const username = 'customers username';
    const password = 'customers password';
    try {
        const result = yield reseller.accountClaim(username, password);
        if(result.success) {
            // Account successfully claimed
        } else {
            // Something went wrong
        }
    } catch (e) {
        // Handle error
    }

Account Valid

    const username = 'customers username';
    const password = 'customers password';
    try {
        const result = yield reseller.accountValid(username, password);
        if(result.success) {
            // Account exists
        } else {
            // Something went wrong
        }
    } catch (e) {
        // Handle error
    }

Profile

Profiles

    const username = 'customers username';
    const password = 'customers password';
    const partner_id_customer = 1234568
    try {
        const result = yield reseller.profiles({username, password});
        // or
        const result = yield reseller.profiles({partner_id_customer});
        if(result.success) {
            // Account exists and is a sub of yours
        } else {
            // Account invalid
        }
    } catch (e) {
        // Handle error
    }

Static functions

Here are some static functions that might prove useful, maybe even for other projects!

stringToEncodedURI

URIencodes a String as the way Mollie requires us to. The standard encodeURIComponent(String) functions is not enough.

    const string_to_be_encoded = '/api/reseller/v1/account-valid?partner_id=1234567&etc=more';
    const encoded_string = API.stringToEncodedURI(string_to_be_encoded);

getLegalForms

Returns an array with the legal forms Mollie accepts. Might I miss some, please do a pull request :)

    const legal_forms = API.getLegalForms();

Printing this would result in:

    [
        {
            "key": "eenmanszaak",
            "value": "Eenmanszaak (The Netherlands)"
        },
        {
            "key": "eenmanszaak-be",
            "value": "Eenmanszaak (Belgium)"
        },
        {
            "key": "eenmans-bvba-be",
            "value": "Eenmans besloten vennootschap met beperkte aansprakelijkheid"
        },
        {
            "key": "maatschap",
            "value": "Maatschap"
        },
        {
            "key": "vof",
            "value": "VOF (The Netherlands)"
        },
    // Etc etc etc
    ]