Skip to content

Commit

Permalink
Added currency field to braintree subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrei committed Jan 10, 2018
1 parent 44f5410 commit 91e19af
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export BRAINTREE_ENV=Sandbox
export VCR_MODE=playback
export CHAMPAIGN_URL='https://action-staging.sumofus.org'
export UNSUBSCRIBE_PAGE_NAME=unsubscribe
export BRAINTREE_MERCHANT_CURRENCIES="{\"EUR\": \"EUR\", \"USD\": \"USD\"}"
8 changes: 7 additions & 1 deletion lib/clients/braintree/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const SUBSCRIPTION_FIELDS = [
'failureCount',
'firstBillingDate',
'id',
'merchantAccountId',
'nextBillingDate',
'nextBillingPeriodAmount',
'numberOfBillingCycles',
Expand All @@ -38,6 +37,11 @@ const TRANSACTION_FIELDS = [
'refundedTransactionId',
];

// Object of format: { 'merchantId': 'Currency'}, ie { souUSD: 'USD' }
const merchantCurrencies = JSON.parse(
process.env.BRAINTREE_MERCHANT_CURRENCIES || '{}'
);

export const client = braintree.connect({
environment: braintree.Environment[process.env.BRAINTREE_ENV],
merchantId: process.env.BRAINTREE_MERCHANT_ID,
Expand Down Expand Up @@ -113,6 +117,8 @@ const buildSubscription = btSubscription => {
const subscription = pick(btSubscription, SUBSCRIPTION_FIELDS);
subscription.amount = parseFloat(btSubscription.price);
subscription.status = btSubscription.status.toLowerCase();
subscription.currency =
merchantCurrencies[btSubscription.merchantAccountId] || 'Unknown';

subscription.statusHistory = map(btSubscription.statusHistory, status => {
return pick(status, 'status', 'balance', 'price');
Expand Down
2 changes: 1 addition & 1 deletion lib/clients/braintree/braintree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('searchCustomer', () => {
failureCount: 0,
firstBillingDate: '2017-11-23',
id: 'j4ym6w',
merchantAccountId: 'USD',
currency: 'USD',
nextBillingDate: '2017-12-23',
nextBillingPeriodAmount: '1.00',
numberOfBillingCycles: null,
Expand Down
1 change: 1 addition & 0 deletions settings/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ environment:
MEMBER_SERVICES_SECRET: ${env:MEMBER_SERVICES_SECRET}
DB_LOG_TABLE: ${env:DB_LOG_TABLE}
UNSUBSCRIBE_PAGE_NAME: ${env:UNSUBSCRIBE_PAGE_NAME}
BRAINTREE_MERCHANT_CURRENCIES: ${env:BRAINTREE_MERCHANT_CURRENCIES}
1 change: 1 addition & 0 deletions settings/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ environment:
MEMBER_SERVICES_SECRET: ${env:MEMBER_SERVICES_SECRET}
DB_LOG_TABLE: ${env:DB_LOG_TABLE}
UNSUBSCRIBE_PAGE_NAME: ${env:UNSUBSCRIBE_PAGE_NAME}
BRAINTREE_MERCHANT_CURRENCIES: ${env:BRAINTREE_MERCHANT_CURRENCIES}

0 comments on commit 91e19af

Please sign in to comment.