Created
August 30, 2018 12:46
-
-
Save bondgeek/9062a6d72a47b21adea3c56e0400290e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const braintreeClientCreate = require('braintree-web/client').create; | |
| const braintreeDataCollectorCreate = require('braintree-web/data-collector').create; | |
| import {isEmpty, isNil} from 'ramda'; | |
| import application from "../common"; | |
| // REDUX action types______________________________________________ | |
| export const SET_PAYMENT_CLIENT = 'SET_PAYMENT_CLIENT'; | |
| export function fetchPaymentClient (ThirstieApi = null) { | |
| ThirstieApi = ThirstieApi || application.ThirstieApi; | |
| /* | |
| NOTE: this is the `GET /m/v2/payments/gateway_client_token` call | |
| */ | |
| const request = ThirstieApi.paymenttoken.get(); | |
| return (dispatch) => { | |
| request.then(({data}) => { | |
| const paymentToken = data.token; | |
| // Initialize the braintree client | |
| braintreeClientCreate({ | |
| authorization: paymentToken | |
| }, (error, clientInstance ) => { | |
| if (error) { | |
| application.Analytics.reportException(error, 'braintree Error' ); | |
| } else { | |
| let deviceData; | |
| // Initialize the collection of user device data | |
| braintreeDataCollectorCreate({ | |
| client: clientInstance, | |
| kount: true | |
| }, (errorDataCollector, dataCollectorInstance) => { | |
| if (errorDataCollector) { | |
| application.Analytics.reportException(errorDataCollector, 'braintree Data Collector Error' ); | |
| } | |
| deviceData = dataCollectorInstance.deviceData; | |
| dispatch({ | |
| type: SET_PAYMENT_CLIENT, | |
| payload: { deviceData, instance: clientInstance } | |
| }); | |
| }); | |
| } | |
| }); | |
| }).catch((error) => { | |
| application.Analytics.reportException(error, 'fetchPaymentClient request error' ); | |
| dispatch({ | |
| type: SET_PAYMENT_CLIENT, | |
| payload: null | |
| }); | |
| }); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment