This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
const coinpayments = require('../../vendor/coinpayments'); | ||
|
||
let coinpaymentsProcessor; | ||
|
||
const coinpaymentsAdapter = { | ||
|
||
serializeData: function (data) { | ||
return data; | ||
}, | ||
|
||
parseData: function () { | ||
return coinpaymentsProcessor.rawData; | ||
}, | ||
|
||
addPaymentMethod: function (token) { | ||
return new Promise((resolve, reject) => { | ||
coinpayments.getCallbackAddress(token, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
coinpaymentsProcessor.data.push({ | ||
token: token, | ||
address: data.address | ||
}); | ||
return coinpaymentsProcessor.save() | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}); | ||
}, | ||
|
||
removePaymentMethod: function (address) { | ||
return new Promise((resolve, reject) => { | ||
const updated = coinpaymentsProcessor.data.filter(item => { | ||
return item.address !== address; | ||
}); | ||
coinpaymentsProcessor.data = updated; | ||
return coinpaymentsProcessor.save() | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}, | ||
|
||
defaultPaymentMethod: function () { | ||
return coinpaymentsProcessor.rawData; | ||
}, | ||
|
||
validate: function () { | ||
return Promise.resolve(true); | ||
}, | ||
|
||
billingDate: function () { | ||
return 1; | ||
}, | ||
|
||
paymentMethods: function () { | ||
return coinpaymentsProcessor.rawData; | ||
} | ||
|
||
}; | ||
|
||
module.exports = function(paymentProcessor) { | ||
coinpaymentsProcessor = paymentProcessor; | ||
return coinpaymentsAdapter; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const Coinpayments = require('coinpayments'); | ||
|
||
const options = { | ||
key: process.env.CP_PUBLIC_KEY, | ||
secret: process.env.CP_PRIVATE_KEY | ||
}; | ||
|
||
let client; | ||
|
||
try { | ||
client = new Coinpayments(options); | ||
} catch (err) { | ||
if (err.message === 'Missing public key and/or secret') { | ||
console.log(err.message); | ||
return; | ||
} else { | ||
throw(err); | ||
} | ||
} | ||
|
||
|
||
module.exports = client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const proxyquire = require('proxyquire'); | ||
const sinon = require('sinon'); | ||
const libPath = '../../lib/models/payment-processor-adapters/coinpayments'; | ||
|
||
|
||
describe('Storage/models/PaymentProcessor/coinpayments', function () { | ||
|
||
describe('#addPaymentMethod', function () { | ||
it('it should push data', function (done) { | ||
const data = { | ||
address: '0x703faaa2f42291e0aaa9ffdbd74ae81172895bc7' | ||
}; | ||
const Adapter = proxyquire(libPath, { | ||
'../../vendor/coinpayments': { | ||
getCallbackAddress: sinon.stub().callsArgWith(1, null, data) | ||
} | ||
}); | ||
const paymentProcessor = { | ||
data: [], | ||
save: sinon.stub().returns(new Promise((resolve) => { | ||
resolve(); | ||
})) | ||
}; | ||
const adapter = Adapter(paymentProcessor); | ||
|
||
const token = 'token'; | ||
adapter.addPaymentMethod(token).then(() => { | ||
expect(paymentProcessor.data.length).to.equal(1); | ||
expect(paymentProcessor.data[0]).to.eql({ | ||
token: 'token', | ||
address: data.address | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('it should handle error from save', function (done) { | ||
const data = { | ||
address: '0x703faaa2f42291e0aaa9ffdbd74ae81172895bc7' | ||
}; | ||
const Adapter = proxyquire(libPath, { | ||
'../../vendor/coinpayments': { | ||
getCallbackAddress: sinon.stub().callsArgWith(1, null, data) | ||
} | ||
}); | ||
const paymentProcessor = { | ||
data: [], | ||
save: sinon.stub().returns(new Promise((resolve, reject) => { | ||
reject(new Error('test')); | ||
})) | ||
}; | ||
const adapter = Adapter(paymentProcessor); | ||
|
||
const token = 'token'; | ||
adapter.addPaymentMethod(token).catch((err) => { | ||
expect(err.message).to.equal('test'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#removePaymentMethod', function () { | ||
it('it should remove address', function (done) { | ||
const data = { | ||
address: '0x703faaa2f42291e0aaa9ffdbd74ae81172895bc7' | ||
}; | ||
const Adapter = proxyquire(libPath, { | ||
'../../vendor/coinpayments': { | ||
getCallbackAddress: sinon.stub().callsArgWith(1, null, data) | ||
} | ||
}); | ||
const paymentProcessor = { | ||
data: [{ | ||
address: '0xaaf71b381afd506107f17ed11d0fc793b2283fe7', | ||
token: 'token2' | ||
}, { | ||
address: '0x2266e1d04bc51c72c682549c7f6c216883458362', | ||
token: 'token3' | ||
}], | ||
save: sinon.stub().returns(new Promise((resolve) => { | ||
resolve(); | ||
})) | ||
}; | ||
const adapter = Adapter(paymentProcessor); | ||
const token = 'token'; | ||
|
||
adapter.addPaymentMethod(token).then(() => { | ||
expect(paymentProcessor.data.length).to.equal(3); | ||
adapter.removePaymentMethod(data.address).then(() => { | ||
expect(paymentProcessor.data.length).to.equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('it should handle error from save', function (done) { | ||
const data = { | ||
address: '0x703faaa2f42291e0aaa9ffdbd74ae81172895bc7' | ||
}; | ||
const Adapter = proxyquire(libPath, { | ||
'../../vendor/coinpayments': { | ||
getCallbackAddress: sinon.stub().callsArgWith(1, null, data) | ||
} | ||
}); | ||
const paymentProcessor = { | ||
data: [], | ||
save: sinon.stub().returns(new Promise((resolve) => { | ||
resolve(); | ||
})) | ||
}; | ||
paymentProcessor.save.onSecondCall() | ||
.returns(new Promise((resolve, reject) => { | ||
reject(new Error('test')); | ||
})); | ||
const adapter = Adapter(paymentProcessor); | ||
const token = 'token'; | ||
|
||
adapter.addPaymentMethod(token).then(() => { | ||
expect(paymentProcessor.data.length).to.equal(1); | ||
expect(paymentProcessor.data[0]).to.eql({ | ||
token: 'token', | ||
address: data.address | ||
}); | ||
adapter.removePaymentMethod(data.address).catch((err) => { | ||
expect(err.message).to.equal('test'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |