mollie

Access the Mollie API (http://mollie.nl)

nodejs-mollie

Node.js module to access the Mollie API.

Installation is straightforward with NPM, this will take care of any dependencies. The release on NPM is always the latest stable version.

npm install mollie

To use account specific functions you need to specify your credentials in the api var. In your account settings you can set a password for the HTTP-API that can be different from your regular password. Communication with the API is always over HTTPS. The api setting takes these elements:

  • partnerid - customer ID, required for payments (lookup)

  • username - your account username

  • password - your account or HTTP-API password

Below is a very basic example, including setup and call.

var mollie = require('mollie')
 
// account credentials 
mollie.api.partnerid = 1234
mollie.api.username = 'yourname'
mollie.api.password = 'yourapipass'
 
// get remaining credits 
mollie.credits( console.log )

Output:

{ type: 'credits',
  resultcode: 10,
  resultmessage: 'Credits available.',
  credits: 58.85,
  euro: 0 }

Or in case of an error

{ type: 'credits',
  resultcode: 30,
  resultmessage: 'Incorrect username or password.',
  credits: 0,
  euro: 0 }

To load the module directly from sourcecode, require the module like this:

var mollie = require('/path/to/mollie.js');

Get remaining account credits

mollie.credits( console.log )
{ type: 'credits',
  resultcode: 10,
  resultmessage: 'Credits available.',
  credits: 58.85,
  euro: 0 }

HLR-lookup (Network Query)

Request the MNC network code for a number. A complete list with the codes can be found at Wikipedia. The response will be pushed to your HLR report URL as provided on your SMS settings page.

  • reference - your internal reference ID for this lookup, will be included in the report callback.

  • recipients - the number to lookup in international format, digits only. Although the name is plural, provide only one number for each call.

mollie.hlr(
    {
        recipients: 31612345678,
        reference:  'lookup123'
    },
    console.log
)

Output:

{ type: 'sms',
  recipients: 1,
  success: 'true',
  resultcode: 10,
  resultmessage: 'Network query sent.' }

Send a normal or premium SMS to one or many recipients at once.

See the API documentation for details.

mollie.sms(
    {
        originator: 'MyApp',
        recipients: '31612345678,31687654321',
        message:    'Hello world',
        gateway:    1,
        reference:  'abc123'
    },
    console.log
)

Output:

{ type: 'sms',
  recipients: 2,
  success: 'true',
  resultcode: 10,
  resultmessage: 'Message successfully sent.' }

Mollie provides a simple streamlined method for handling iDEAL payments. For this to work you need to an active payment profile. See the API documentation for all the details and variables.

On your payment page you first need to let the customer choose his bank.

mollie.ideal.banklist ( [testmode], callback )

  • testmode - optional - true: returns a test-bank, all transactions are fake. false: returns real banks, all transactions are real with real money. The default is what you set on your account iDEAL API testmode settings.

  • callback - required - your callback function

mollie.ideal.banklist( true, console.log );
{ '9999': { bank_id: 9999, bank_name: 'TBM Bank' } }

The key is the same as bank_id, this allows you to do quick reverse lookups.

mollie.ideal.banklist( console.log );
{ '17': { bank_id: 17, bank_name: 'Rabobank' },
  '25': { bank_id: 25, bank_name: 'ABN AMRO' },
  '91': { bank_id: 91, bank_name: 'Friesland Bank' },
  '113': { bank_id: 113, bank_name: 'van Lanschot' },
  '329': { bank_id: 329, bank_name: 'Triodos Bank' },
  '465': { bank_id: 465, bank_name: 'ING' },
  '489': { bank_id: 489, bank_name: 'SNS Bank' },
  '497': { bank_id: 497, bank_name: 'ASN Bank' },
  '505': { bank_id: 505, bank_name: 'RegioBank' } }

Create an iDEAL payment.

mollie.ideal.payment(
    {
        amount:         2000,
        bank_id:        9999,
        description:    'Invoice 20120012345',
        reporturl:      'http://myapp.tld/mollie/ideal',
        returnurl:      'http://myapp.tld/ideal/complete'
    },
    console.log
)       
{ order: 
   { transaction_id: 'abcxyz',
     amount: 2000,
     currency: 'EUR',
     url: 'http://www.mollie.nl/partners/ideal-test-bank?order_nr=M0040123&transaction_id=abcdef&trxid=M0040123',
     message: 'Your iDEAL-payment has successfully been setup. Your customer should visit the given URL to make the payment' } }

When the customer completes the payment the API will make a call on your reporturl with the transaction_id as GET argument. Then you can check the payment status ONCE with mollie.ideal.check. In the meantime the customer will be redirected to your returnurl and bring the transaction_id too, for cross-referencing.

  • testmode - optional - set to true when using the TMB Bank (ID 9999).

  • transaction_id - required - the transaction ID to check

mollie.ideal.check(
    {
        testmode:       true,
        transaction_id: 'abcxyz'
    },
    console.log
)       
{ order: 
   { transaction_id: 'abcxyz',
     amount: 2000,
     currency: 'EUR',
     payed: 'true',
     consumer: 
      { consumername: 'T. TEST',
        consumeraccount: 123456789,
        consumercity: 'Testdorp' },
     message: 'This iDEAL-order has successfuly been payed for, and this is the first time you check it.',
     status: 'Success' } }

The variable payed can be true only once, for security.

Generate an iDEAL payment link to redirect the customer to. This is useful for emails and such. This way Mollie will take care of the banklist, payment creation and confirmation.

mollie.ideal.paymentLink(
    {
        amount:         2000,
        description:    'Invoice 20120012345'
    },
    console.log
)
{ link: 
   { url: 'https://secure.mollie.nl/pay/ideal/123-12ab3456/2000_Invoice_20120012345/abcxyz',
     message: 'Your iDEAL-link has been successfully setup. Your customer should visit the given URL to make the payment.' } }

You get the payment status by email.

This code is COPYLEFT meaning you can do anything you like, except copyrighting it. It would be nice to refer back to the source in your code, for future reference:

https://github.com/fvdm/nodejs-mollie/