Skip to content

Commit

Permalink
feat(payments): PAYMENTS-4228 include currency code in shopper instru…
Browse files Browse the repository at this point in the history
…ment calls
  • Loading branch information
Eira Tse committed May 9, 2019
1 parent d53653f commit a22917c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default class Client {
* @param {Object} data
* @param {string} data.storeId
* @param {string} data.customerId
* @param {string} data.currencyCode
* @param {Function} [callback]
* @return {void}
*/
Expand All @@ -121,6 +122,7 @@ export default class Client {
* @param {Object} data
* @param {string} data.storeId
* @param {string} data.customerId
* @param {string} data.currencyCode
* @param {AddressData} data.shippingAddress
* @param {Function} [callback]
* @return {void}
Expand All @@ -133,6 +135,7 @@ export default class Client {
* @param {Object} data
* @param {string} data.storeId
* @param {string} data.customerId
* @param {string} data.currencyCode
* @param {CreditCard} data.creditCard
* @param {AddressData} data.billingAddress
* @param {boolean} data.defaultInstrument
Expand All @@ -149,6 +152,7 @@ export default class Client {
* @param {string} data.storeId
* @param {string} data.customerId
* @param {string} data.instrumentId
* @param {string} data.currencyCode
* @param {Function} [callback]
* @return {void}
*/
Expand Down
21 changes: 17 additions & 4 deletions src/store/store-request-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export default class StoreRequestSender {
* @return {void}
*/
loadInstruments(data, callback) {
const url = this.urlHelper.getInstrumentsUrl(data.storeId, data.customerId);
const url = this.urlHelper.getInstrumentsUrl(
data.storeId,
data.customerId,
data.currencyCode
);
const options = {
headers: mapToHeaders(data),
};
Expand All @@ -58,7 +62,11 @@ export default class StoreRequestSender {
* @return {void}
*/
loadInstrumentsWithAddress(data, callback) {
const url = this.urlHelper.getTrustedShippingAddressUrl(data.storeId, data.customerId);
const url = this.urlHelper.getTrustedShippingAddressUrl(
data.storeId,
data.customerId,
data.currencyCode
);
const payload = mapToTrustedShippingAddressPayload(data);
const options = {
method: POST,
Expand All @@ -74,7 +82,11 @@ export default class StoreRequestSender {
* @return {void}
*/
postShopperInstrument(data, callback) {
const url = this.urlHelper.getInstrumentsUrl(data.storeId, data.customerId);
const url = this.urlHelper.getInstrumentsUrl(
data.storeId,
data.customerId,
data.currencyCode
);
const payload = mapToInstrumentPayload(data);
const options = {
headers: mapToHeaders(data),
Expand All @@ -92,7 +104,8 @@ export default class StoreRequestSender {
const url = this.urlHelper.getInstrumentByIdUrl(
data.storeId,
data.customerId,
data.instrumentId
data.instrumentId,
data.currencyCode
);
const options = {
method: DELETE,
Expand Down
15 changes: 9 additions & 6 deletions src/store/url-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,31 @@ export default class UrlHelper {
/**
* @param {number} storeId
* @param {number} customerId
* @param {string} currencyCode
* @returns {string}
*/
getInstrumentsUrl(storeId, customerId) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments`;
getInstrumentsUrl(storeId, customerId, currencyCode) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments?currency_code=${currencyCode}`;
}

/**
* @param {number} storeId
* @param {number} customerId
* @param {string} currencyCode
* @return {string}
*/
getTrustedShippingAddressUrl(storeId, customerId) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments/trusted_shipping_address`;
getTrustedShippingAddressUrl(storeId, customerId, currencyCode) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments/trusted_shipping_address?currency_code=${currencyCode}`;
}

/**
* @param {number} storeId
* @param {number} customerId
* @param {number} instrumentId
* @param {string} currencyCode
* @returns {string}
*/
getInstrumentByIdUrl(storeId, customerId, instrumentId) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments/${instrumentId}`;
getInstrumentByIdUrl(storeId, customerId, instrumentId, currencyCode) {
return `${this.host}/api/v2/stores/${storeId}/shoppers/${customerId}/instruments/${instrumentId}?currency_code=${currencyCode}`;
}
}
1 change: 1 addition & 0 deletions test/mocks/store-instrument-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const instrumentRequestDataMock = {
shopperId: '321',
instrumentId: '456',
providerName: 'braintree',
currencyCode: 'USD',
creditCard: {
cardholderName: 'John Doe',
number: '4111 1111 1111 1111',
Expand Down
21 changes: 17 additions & 4 deletions test/store/store-request-sender.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ describe('StoreRequestSender', () => {
it('request a shopper instrument with the appropriately mapped headers', () => {
storeRequestSender.loadInstruments(data, () => {});

expect(urlHelperMock.getInstrumentsUrl).toHaveBeenCalledWith(data.storeId, data.customerId);
expect(urlHelperMock.getInstrumentsUrl).toHaveBeenCalledWith(
data.storeId,
data.customerId,
data.currencyCode
);
expect(requestSenderMock.sendRequest).toHaveBeenCalled();
expect(mappers.mapToHeaders).toHaveBeenCalled();
});

it('posts a trusted shipping address with the appropriately mapped headers and payload', () => {
storeRequestSender.loadInstrumentsWithAddress(data, () => {});

expect(urlHelperMock.getTrustedShippingAddressUrl).toHaveBeenCalledWith(data.storeId, data.customerId);
expect(urlHelperMock.getTrustedShippingAddressUrl).toHaveBeenCalledWith(
data.storeId,
data.customerId,
data.currencyCode
);
expect(requestSenderMock.postRequest).toHaveBeenCalled();
expect(mappers.mapToHeaders).toHaveBeenCalled();
expect(mappers.mapToTrustedShippingAddressPayload).toHaveBeenCalled();
Expand All @@ -57,7 +65,11 @@ describe('StoreRequestSender', () => {
it('posts a new shopper instrument with the appropriately mapped headers and payload', () => {
storeRequestSender.postShopperInstrument(data, () => {});

expect(urlHelperMock.getInstrumentsUrl).toHaveBeenCalledWith(data.storeId, data.customerId);
expect(urlHelperMock.getInstrumentsUrl).toHaveBeenCalledWith(
data.storeId,
data.customerId,
data.currencyCode
);
expect(requestSenderMock.postRequest).toHaveBeenCalled();
expect(mappers.mapToHeaders).toHaveBeenCalled();
});
Expand All @@ -68,7 +80,8 @@ describe('StoreRequestSender', () => {
expect(urlHelperMock.getInstrumentByIdUrl).toHaveBeenCalledWith(
data.storeId,
data.customerId,
data.instrumentId
data.instrumentId,
data.currencyCode
);
expect(requestSenderMock.sendRequest).toHaveBeenCalled();
expect(mappers.mapToHeaders).toHaveBeenCalled();
Expand Down
13 changes: 7 additions & 6 deletions test/store/url-helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('UrlHelper', () => {
const storeId = '123';
const shopperId = '456';
const instrumentId = '789';
const currencyCode = 'USD';

let urlHelper;

Expand Down Expand Up @@ -33,22 +34,22 @@ describe('UrlHelper', () => {
});

it('returns a URL for submitting payments to an offsite provider', () => {
const result = urlHelper.getInstrumentsUrl(storeId, shopperId);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments`;
const result = urlHelper.getInstrumentsUrl(storeId, shopperId, currencyCode);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments?currency_code=${currencyCode}`;

expect(result).toEqual(expected);
});

it('returns a URL for posting a trusted shipping address', () => {
const result = urlHelper.getTrustedShippingAddressUrl(storeId, shopperId);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments/trusted_shipping_address`;
const result = urlHelper.getTrustedShippingAddressUrl(storeId, shopperId, currencyCode);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments/trusted_shipping_address?currency_code=${currencyCode}`;

expect(result).toEqual(expected);
});

it('returns a URL for generating a client token', () => {
const result = urlHelper.getInstrumentByIdUrl(storeId, shopperId, instrumentId);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments/${instrumentId}`;
const result = urlHelper.getInstrumentByIdUrl(storeId, shopperId, instrumentId, currencyCode);
const expected = `${host}/api/v2/stores/${storeId}/shoppers/${shopperId}/instruments/${instrumentId}?currency_code=${currencyCode}`;

expect(result).toEqual(expected);
});
Expand Down

0 comments on commit a22917c

Please sign in to comment.