From 547ee0f4a9896e500d2568202328db149ed47335 Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Tue, 2 Oct 2018 17:49:35 +0700 Subject: [PATCH 1/6] replace deprecated Buffer constructor --- lib/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index 0ddcf24..a28ac55 100644 --- a/lib/api.js +++ b/lib/api.js @@ -48,7 +48,7 @@ function _buildContentHeaders(options) { } function _authenticate(options) { - var base64Encoded = new Buffer(options['key'] + ':').toString('base64'); + var base64Encoded = Buffer.from(options['key'] + ':').toString('base64'); return {'basic': 'Basic ' + base64Encoded}; } From 45f74d20f89bb894778bbf0a45a68d173da96fc7 Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Tue, 2 Oct 2018 17:54:25 +0700 Subject: [PATCH 2/6] Fix eslint warnings --- examples/as_promises.js | 14 +++++++------- examples/create_token.js | 10 +++++----- index.js | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/as_promises.js b/examples/as_promises.js index de1000d..5fe8e50 100644 --- a/examples/as_promises.js +++ b/examples/as_promises.js @@ -7,21 +7,21 @@ var omise = require('../index')({ var cardDetails = { card: { - 'name': 'JOHN DOE', - 'city': 'Bangkok', - 'postal_code': 10320, - 'number': '4242424242424242', + 'name': 'JOHN DOE', + 'city': 'Bangkok', + 'postal_code': 10320, + 'number': '4242424242424242', 'expiration_month': 2, - 'expiration_year': 2017, + 'expiration_year': 2017, }, }; omise.tokens.create(cardDetails).then(function(token) { console.log(token); return omise.customers.create({ - 'email': 'john.doe@example.com', + 'email': 'john.doe@example.com', 'description': 'John Doe (id: 30)', - 'card': token.id, + 'card': token.id, }); }).then(function(customer) { console.log(customer); diff --git a/examples/create_token.js b/examples/create_token.js index c189924..cca8c1d 100644 --- a/examples/create_token.js +++ b/examples/create_token.js @@ -7,12 +7,12 @@ var omise = require('../index')({ var cardDetails = { card: { - 'name': 'JOHN DOE', - 'city': 'Bangkok', - 'postal_code': 10160, - 'number': '4532156433142865', + 'name': 'JOHN DOE', + 'city': 'Bangkok', + 'postal_code': 10160, + 'number': '4532156433142865', 'expiration_month': 8, - 'expiration_year': 2022, + 'expiration_year': 2022, }, }; diff --git a/index.js b/index.js index adb7de2..d3d839d 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ 'use strict'; -//Omise.co +// Omise.co var resource = require('./lib/apiResources'); module.exports = function(config) { return resource.omiseResources(config); From 108ae9ca07f8f95a97239f49bcc66dea25c34576 Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Tue, 2 Oct 2018 18:14:28 +0700 Subject: [PATCH 3/6] Backward compatibility with older node --- lib/api.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index a28ac55..cb24e52 100644 --- a/lib/api.js +++ b/lib/api.js @@ -48,7 +48,9 @@ function _buildContentHeaders(options) { } function _authenticate(options) { - var base64Encoded = Buffer.from(options['key'] + ':').toString('base64'); + var key = options['key'] + ':'; + var buffer = Buffer.from ? Buffer.from(key) : new Buffer(key); + var base64Encoded = buffer.toString('base64'); return {'basic': 'Basic ' + base64Encoded}; } From e61d3ce46c3b2475a067f3dd60350790f0875469 Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Tue, 2 Oct 2018 18:50:46 +0700 Subject: [PATCH 4/6] Handle TypeError --- lib/api.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index cb24e52..d508aad 100644 --- a/lib/api.js +++ b/lib/api.js @@ -49,7 +49,17 @@ function _buildContentHeaders(options) { function _authenticate(options) { var key = options['key'] + ':'; - var buffer = Buffer.from ? Buffer.from(key) : new Buffer(key); + var buffer; + + try { + buffer = Buffer.from(key); + } catch (e) { + if (e.message === 'this is not a typed array') { + buffer = new Buffer(key); + } else { + throw e; + } + } var base64Encoded = buffer.toString('base64'); return {'basic': 'Basic ' + base64Encoded}; } From 917780a403b699bdf11ad92ba520b28fea618b47 Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Tue, 2 Oct 2018 18:55:00 +0700 Subject: [PATCH 5/6] Fix a typo --- lib/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index d508aad..acb9a5c 100644 --- a/lib/api.js +++ b/lib/api.js @@ -54,7 +54,7 @@ function _authenticate(options) { try { buffer = Buffer.from(key); } catch (e) { - if (e.message === 'this is not a typed array') { + if (e.message === 'this is not a typed array.') { buffer = new Buffer(key); } else { throw e; From f296d45cd878aa7546d94ba292cfb8dc623c764c Mon Sep 17 00:00:00 2001 From: Bhoomtawath Plinsut Date: Thu, 25 Oct 2018 17:19:14 +0700 Subject: [PATCH 6/6] check backward compatibility --- lib/api.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/api.js b/lib/api.js index acb9a5c..28edc67 100644 --- a/lib/api.js +++ b/lib/api.js @@ -51,15 +51,12 @@ function _authenticate(options) { var key = options['key'] + ':'; var buffer; - try { + if (Buffer.allocUnsafe) { buffer = Buffer.from(key); - } catch (e) { - if (e.message === 'this is not a typed array.') { - buffer = new Buffer(key); - } else { - throw e; - } + } else { + buffer = new Buffer(key); } + var base64Encoded = buffer.toString('base64'); return {'basic': 'Basic ' + base64Encoded}; }