Socket
Socket
Sign inDemoInstall

mollie-es6

Package Overview
Dependencies
23
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

28

lib/payments.js

@@ -55,7 +55,23 @@ import request from './request';

}
//
// function *list(options) {
//
// }
function *list(options) {
if (options.count && options.count > 250) {
throw {error: 'Count larger than 250 is not allowed'};
}
const result = yield request(
'GET',
`payments`,
null,
options
);
if (result.error) {
throw result;
} else {
readifyPayments(result.data);
return result;
}
}
function readifyPayments(payments) {

@@ -74,4 +90,4 @@ if (payments.constructor === Object) {

create,
get
// list
get,
list
};
import superagent from 'superagent';
import mollie from '../app';
export default function *(method, extension, data) {
export default function *(method, extension, data, url_parameters) {
if (!mollie.api_key) {

@@ -12,3 +12,3 @@ throw {error: 'There is no API key I can use, please set your key `mollie.api_key`'};

// Get the base promise
const request = getMethodPromise(method, extension);
const request = getMethodPromise(method, extension, url_parameters);
// Set api_key

@@ -29,12 +29,30 @@ request.set('Authorization', `Bearer ${mollie.api_key}`);

function getMethodPromise(method, extension) {
const mollie_base_url = 'https://api.mollie.nl/v1';
function getMethodPromise(method, extension, url_parameters) {
const url = `https://api.mollie.nl/v1/${extension}${addURLParams(url_parameters)}`;
switch (method) {
case 'get':
return superagent.get(`${mollie_base_url}/${extension}`);
return superagent.get(url);
case 'post':
return superagent.post(`${mollie_base_url}/${extension}`);
return superagent.post(url);
case 'delete':
return superagent.delete(`${mollie_base_url}/${extension}`);
return superagent.delete(url);
}
}
function addURLParams(url_parameters) {
if (!url_parameters) {
return '';
} else if (url_parameters.constructor === Object) {
return `?${Object.keys(url_parameters)[0]}=${url_parameters[Object.keys(url_parameters)[0]]}`;
} else {
let params = '?';
for (let i = 0; i < url_parameters.length; i++) {
if (i !== 0) {
params += '&';
}
const url_param = url_parameters[0];
params += `${Object.keys(url_param)[0]}=${url_parameters[Object.keys(url_param)[0]]}`;
}
return params;
}
}
{
"name": "mollie-es6",
"version": "0.3.0",
"version": "0.4.0",
"description": "Mollie module ready for ES6 usage",

@@ -5,0 +5,0 @@ "main": "app.js",

@@ -69,3 +69,3 @@ # Mollie ES6 API client for Node.js #

| Get | Yes |
| List | No |
| List | Yes |

@@ -72,0 +72,0 @@ ### Methods ###

@@ -21,3 +21,2 @@ "use strict";

describe('Basics', function () {
it('Should be a function', function () {

@@ -142,2 +141,8 @@ payments.create.should.be.a.Function();

describe('Basics', function () {
it('Should be a function', function () {
payments.get.should.be.a.Function();
});
});
describe('Errors', function () {

@@ -247,2 +252,73 @@ it('An Object should be thrown', co.wrap(function *() {

});
describe('.list', function () {
const offset = 2;
const count = 'Mollie ES6 module Test';
describe('Basics', function () {
it('Should be a function', function () {
payments.list.should.be.a.Function();
});
});
describe('Errors', function () {
it('Should throw an error if a count of more than 250 is given', co.wrap(function*() {
try {
yield payments.list({count: 251});
check = 1;
} catch (error) {
error.should.have.property('error', 'Count larger than 250 is not allowed');
check = 2;
}
check.should.equal(2);
}));
});
describe('Success', function () {
it('Should return an Object', co.wrap(function *() {
try {
const payment = yield mollie.payments.list({count: 15});
payment.should.be.an.Object();
check = 1;
} catch (error) {
console.log(error);
check = 2;
}
check.should.equal(1);
}));
it('Should return certain fields', co.wrap(function *() {
try {
const payment = yield mollie.payments.list({count: 15});
payment.should.have.property('totalCount')
payment.should.have.property('offset')
payment.should.have.property('count')
payment.should.have.property('data')
check = 1;
} catch (error) {
console.log(error);
check = 2;
}
check.should.equal(1);
}));
it('Should return payments with payment functions', co.wrap(function *() {
try {
const payments = yield mollie.payments.list({count: 15});
const payment = payments.data[0];
payment.should.have.property('getPaymentUrl');
payment.should.have.property('isPaid');
check = 1;
} catch (error) {
console.log(error);
check = 2;
}
check.should.equal(1);
}));
});
});
});
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