Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Changelog

0.2.0 (in progress)
-------------------

- Added PayPal account endpoint
- Added transfer endpoint
- Added client token endpoint
- Added Layer 7 encryption
- Added payment status transition endpoint
- Added paper check endpoint
Expand Down
19 changes: 19 additions & 0 deletions src/Hyperwallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,25 @@ export default class Hyperwallet {
this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards/${encodeURIComponent(bankCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}

//--------------------------------------
// Client Token
//--------------------------------------

/**
* Get client token
*
* @param {string} userToken - The user token
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken is not provided
*/
getClientToken(userToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doPost(`users/${encodeURIComponent(userToken)}/client-token`, {}, {}, callback);
}

//--------------------------------------
// Paper Checks
//--------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions test/Hyperwallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,42 @@ describe("Hyperwallet", () => {
});
});

//--------------------------------------
// Client Token
//--------------------------------------

/** @test {Hyperwallet#getClientToken} */
describe("getClientToken()", () => {
let client;
let apiClientSpy;

beforeEach(() => {
apiClientSpy = sinon.spy();
client = new Hyperwallet({
username: "test-username",
password: "test-password",
});
client.client = {
doPost: apiClientSpy,
};
});

/** @test {Hyperwallet#getClientToken} */
it("should throw error if userToken is missing", () => {
const callback = () => null;
expect(() => client.getClientToken(undefined, callback)).to.throw("userToken is required");
});

/** @test {Hyperwallet#getClientToken} */
it("should do post call to client token endpoint", () => {
const callback = () => null;
client.getClientToken("test-user-token", callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/client-token", {}, {}, callback);
});
});

//--------------------------------------
// Paper Checks
//--------------------------------------
Expand Down