card-connect-api
Advanced tools
Comparing version 1.0.0 to 1.0.1
const httpism = require("httpism"); | ||
function CommandCancelledError() { | ||
this.name = 'CommandCancelledError'; | ||
this.message = 'Command cancelled'; | ||
this.stack = (new Error()).stack; | ||
} | ||
CommandCancelledError.prototype = new Error; | ||
function errorTypeForCode(code) { | ||
if (code === 8) { | ||
return CommandCancelledError | ||
} | ||
} | ||
class CardConnectApi { | ||
@@ -47,4 +60,2 @@ constructor({ baseUrl, merchantId, authorizationHeader }) { | ||
async readCard({ hsn, amount }) { | ||
console.log("zomg"); | ||
try { | ||
@@ -56,6 +67,10 @@ const response = await this._client.post("readCard", { | ||
}); | ||
console.log(response, "WWWAAAAAAAAAAAAAAAAAAAAAAA"); | ||
return response; | ||
} catch (e) { | ||
return e; | ||
const errorType = errorTypeForCode(e.body.errorCode) | ||
if (errorType) { | ||
throw new errorType() | ||
} | ||
throw e; | ||
} | ||
@@ -62,0 +77,0 @@ } |
{ | ||
"name": "card-connect-api", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Node Wrapper for CardConnectApi", | ||
"main": "CardConnectApi.js", | ||
"scripts": { | ||
"test": "mocha test.js --timeout 10000" | ||
"test": "mocha test.js --timeout 30000" | ||
}, | ||
@@ -9,0 +9,0 @@ "dependencies": { |
48
test.js
@@ -27,3 +27,3 @@ const assert = require("assert"); | ||
it("should send a message to a terminal", async () => { | ||
it("sets the terminal message", async () => { | ||
await this.api.connectTerminal({ | ||
@@ -41,2 +41,15 @@ hsn: process.env.TESTABLE_TERMINAL, | ||
it("clears the terminal message", async () => { | ||
await this.api.connectTerminal({ | ||
hsn: process.env.TESTABLE_TERMINAL, | ||
force: true | ||
}); | ||
const response = await this.api.sendMessage({ | ||
hsn: process.env.TESTABLE_TERMINAL, | ||
text: '' | ||
}); | ||
assert(response.delivered); | ||
}); | ||
it("should ping the terminal", async () => { | ||
@@ -54,4 +67,3 @@ await this.api.connectTerminal({ | ||
it.only("should request a payment", async () => { | ||
this.timeout = 10000; | ||
it("can be cancelled by the user", async () => { | ||
await this.api.connectTerminal({ | ||
@@ -61,2 +73,23 @@ hsn: process.env.TESTABLE_TERMINAL, | ||
}); | ||
console.log('> PRESS CANCEL ON THE TERMINAL NOW <') | ||
try { | ||
await this.api.readCard({ | ||
hsn: process.env.TESTABLE_TERMINAL, | ||
amount: 1 | ||
}); | ||
} catch(e) { | ||
assert.equal(e.message, 'Command cancelled') | ||
} | ||
}); | ||
it("should request a payment", async () => { | ||
await this.api.connectTerminal({ | ||
hsn: process.env.TESTABLE_TERMINAL, | ||
force: true | ||
}); | ||
console.log('> SWIPE YOUR CARD ON THE TERMINAL NOW <') | ||
const response = await this.api.readCard({ | ||
@@ -67,4 +100,11 @@ hsn: process.env.TESTABLE_TERMINAL, | ||
assert(response.connected); | ||
// Sample response: | ||
// { | ||
// token: '<redacted 16 digit number>', | ||
// expiry: '<redacted 4 digit expiry date>', | ||
// name: '<redacted company name? maybe?>' | ||
// } | ||
assert.equal(response.token.length, 16); | ||
}); | ||
}); |
15409
174
15