-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathcustomer.js
65 lines (53 loc) · 2.66 KB
/
customer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
let AttributeSetter = require('./attribute_setter').AttributeSetter;
let ApplePayCard = require('./apple_pay_card').ApplePayCard;
let AndroidPayCard = require('./android_pay_card').AndroidPayCard;
let AmexExpressCheckoutCard = require('./amex_express_checkout_card').AmexExpressCheckoutCard;
let CreditCard = require('./credit_card').CreditCard;
let PayPalAccount = require('./paypal_account').PayPalAccount;
let CoinbaseAccount = require('./coinbase_account').CoinbaseAccount;
let VenmoAccount = require('./venmo_account').VenmoAccount;
let UsBankAccount = require('./us_bank_account').UsBankAccount;
class Customer extends AttributeSetter {
constructor(attributes) {
super(attributes);
this.paymentMethods = [];
if (attributes.creditCards) {
this.creditCards = attributes.creditCards.map((cardAttributes) => new CreditCard(cardAttributes));
this._addPaymentMethods(this.creditCards);
}
if (attributes.applePayCards) {
this.applePayCards = attributes.applePayCards.map((cardAttributes) => new ApplePayCard(cardAttributes));
this._addPaymentMethods(this.applePayCards);
}
if (attributes.androidPayCards) {
this.androidPayCards = attributes.androidPayCards.map((cardAttributes) => new AndroidPayCard(cardAttributes));
this._addPaymentMethods(this.androidPayCards);
}
if (attributes.amexExpressCheckoutCards) {
this.amexExpressCheckoutCards = attributes.amexExpressCheckoutCards.map((cardAttributes) => new AmexExpressCheckoutCard(cardAttributes));
this._addPaymentMethods(this.amexExpressCheckoutCards);
}
if (attributes.paypalAccounts) {
this.paypalAccounts = attributes.paypalAccounts.map((paypalAccountAttributes) => new PayPalAccount(paypalAccountAttributes));
this._addPaymentMethods(this.paypalAccounts);
}
if (attributes.coinbaseAccounts) {
this.coinbaseAccounts = attributes.coinbaseAccounts.map((coinbaseAccountAttributes) => new CoinbaseAccount(coinbaseAccountAttributes));
this._addPaymentMethods(this.coinbaseAccounts);
}
if (attributes.venmoAccounts) {
this.venmoAccounts = attributes.venmoAccounts.map((venmoAccountAttributes) => new VenmoAccount(venmoAccountAttributes));
this._addPaymentMethods(this.venmoAccounts);
}
if (attributes.usBankAccounts) {
this.usBankAccounts = attributes.usBankAccounts.map((usBankAccountAttributes) => new UsBankAccount(usBankAccountAttributes));
this._addPaymentMethods(this.usBankAccounts);
}
}
_addPaymentMethods(paymentMethods) {
return paymentMethods.map((paymentMethod) =>
this.paymentMethods.push(paymentMethod));
}
}
module.exports = {Customer: Customer};