Skip to content

Commit

Permalink
Added get and list methods for PayPal Account Status Transition
Browse files Browse the repository at this point in the history
  • Loading branch information
skambar110 committed Nov 3, 2020
1 parent 0b3eade commit 4605fa6
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/Hyperwallet.js
Expand Up @@ -1042,7 +1042,7 @@ export default class Hyperwallet {
* @param {Object} data - The PayPal account data to update
* @param {api-callback} callback - The callback for this call
*
* @throws Will throw an error if userToken or bankAccountToken is not provided
* @throws Will throw an error if userToken or payPalAccountToken is not provided
*/
updatePayPalAccount(userToken, payPalAccountToken, data, callback) {
if (!userToken) {
Expand Down Expand Up @@ -1074,6 +1074,49 @@ export default class Hyperwallet {
this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, data, {}, callback);
}

/**
* Get PayPal account status transition
*
* @param {string} userToken - The user token
* @param {string} payPalAccountToken - PayPal account token
* @param {string} statusTransitionToken - The PayPal account status transition token
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or payPalAccountToken or statusTransitionToken is not provided
*/
getPayPalAccountStatusTransition(userToken, payPalAccountToken, statusTransitionToken, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!payPalAccountToken) {
throw new Error("payPalAccountToken is required");
}
if (!statusTransitionToken) {
throw new Error("statusTransitionToken is required");
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions/${encodeURIComponent(statusTransitionToken)}`,
{},
callback);
}

/**
* List PayPal account status transition
*
* @param {string} userToken - The user token
* @param {string} payPalAccountToken - PayPal account token
* @param {Object} options - The query parameters to send
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or payPalAccountToken is not provided
*/
listPayPalAccountStatusTransitions(userToken, payPalAccountToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!payPalAccountToken) {
throw new Error("payPalAccountToken is required");
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback));
}

//--------------------------------------
// Bank Accounts
//--------------------------------------
Expand Down
112 changes: 112 additions & 0 deletions test/Hyperwallet.spec.js
Expand Up @@ -2041,6 +2041,118 @@ describe("Hyperwallet", () => {
});
});

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

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

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

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

/** @test {Hyperwallet#getPayPalAccountStatusTransition} */
it("should throw error if statusTransitionToken is missing", () => {
const callback = () => null;
expect(() => client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", undefined, callback)).to.throw("statusTransitionToken is required");
});

/** @test {Hyperwallet#getPayPalAccountStatusTransition} */
it("should do get call if userToken, payPalAccountToken and statusTransitionToken is provided", () => {
const callback = () => null;
client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", "status-transition-token", callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions/status-transition-token", {}, callback);
});
});

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

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

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

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

/** @test {Hyperwallet#listPayPalAccountStatusTransitions} */
it("should do get call with options", () => {
const callback = () => null;
client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", { test: "value" }, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", { test: "value" });
});

/** @test {Hyperwallet#listPayPalAccountStatusTransitions} */
it("should do get call without options", () => {
const callback = () => null;
client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {});
});

/** @test {Hyperwallet#listPayPalAccountStatusTransitions} */
it("should handle 204 return", (cb) => {
const callback = (err, data) => {
data.should.be.deep.equal({
hasNextPage: false,
hasPreviousPage: false,
limit: 0,
data: [],
});
cb();
};
client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {});

apiClientSpy.getCall(0).args[2](undefined, {}, {
status: 204,
});
});
});

//--------------------------------------
// Prepaid Cards
//--------------------------------------
Expand Down

0 comments on commit 4605fa6

Please sign in to comment.