Skip to content

Commit

Permalink
refactor(payment): Extract classes from submitPayment function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchin committed Apr 21, 2017
1 parent c50bf0f commit 04a5eeb
Show file tree
Hide file tree
Showing 47 changed files with 784 additions and 694 deletions.
12 changes: 3 additions & 9 deletions src/client/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PAYMENT_TYPES, submitPayment } from '../payment';
import OffsitePaymentInitializer from '../payment/offsite-payment-initializer';
import PaymentSubmitter from '../payment/payment-submitter';

export default class Client {
/**
Expand All @@ -10,6 +10,7 @@ export default class Client {
constructor(config) {
this.host = config.host;
this.offsitePaymentInitializer = OffsitePaymentInitializer.create(config);
this.paymentSubmitter = PaymentSubmitter.create(config);
}

/**
Expand All @@ -29,13 +30,6 @@ export default class Client {
* @returns {void}
*/
submitPayment(data, callback) {
const { paymentMethod = {} } = data;
const options = { host: this.host };

if (paymentMethod.type !== PAYMENT_TYPES.API) {
throw new Error(`${paymentMethod.type} is not supported.`);
}

submitPayment(data, options, callback);
this.paymentSubmitter.submitPayment(data, callback);
}
}
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createClient } from './client';
import Client from './client/client';

export {
createClient,
};
/**
* @param {Object} config
* @returns {Client}
*/
export function createClient(config) {
return Client.create(config);
}
7 changes: 0 additions & 7 deletions src/payment-method/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/payment-method/map-to-id.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/payment-method/payment-methods.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/payment/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/payment/mappers/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/payment/mappers/map-to-address.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/payment/mappers/map-to-billing-address.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/payment/mappers/map-to-credit-card.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/payment/mappers/map-to-customer.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/payment/mappers/map-to-headers.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/payment/mappers/map-to-items.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/payment/mappers/map-to-order-totals.js

This file was deleted.

24 changes: 0 additions & 24 deletions src/payment/mappers/map-to-order.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/payment/mappers/map-to-payload.js

This file was deleted.

36 changes: 0 additions & 36 deletions src/payment/mappers/map-to-payment.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/payment/mappers/map-to-shipping-address.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/payment/mappers/map-to-store.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/payment/payment-mappers/customer-mapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { omitNil, toString } from '../../common/utils';

export default class CustomerMapper {
/**
* @returns {CustomerMapper}
*/
static create() {
return new CustomerMapper();
}

/**
* @param {PaymentRequestData} data
* @returns {Object}
*/
mapToCustomer(data) {
const { customer = {}, quoteMeta = {} } = data;

return omitNil({
geo_ip_country_code: quoteMeta.request ? quoteMeta.request.geoCountryCode : null,
id: customer.customerId ? toString(customer.customerId) : null,
session_token: quoteMeta.request ? quoteMeta.request.sessionHash : null,
});
}
}
Loading

0 comments on commit 04a5eeb

Please sign in to comment.