2020-04-24 15:11:08 +00:00
|
|
|
|
|
|
|
import { transactionUrl } from "./IlinkConstants";
|
2020-05-03 09:16:24 +00:00
|
|
|
import { fetchDepositError, fetchDepositSuccess, fetchDepositPending, fetchDepositReset } from "../redux/actions/DepositAction";
|
2020-04-24 15:11:08 +00:00
|
|
|
import { store } from "../redux/store";
|
|
|
|
import axios from "axios";
|
2020-05-06 13:07:53 +00:00
|
|
|
import I18n from 'react-native-i18n'
|
2020-04-24 15:11:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
"type" : "debit",
|
|
|
|
"numCarte" : 12345454445,
|
|
|
|
"montant":10000,
|
|
|
|
"cvv": 325,
|
|
|
|
"expiration_date": "03/2024",
|
|
|
|
"id_wallet":1
|
|
|
|
}
|
|
|
|
*/
|
2020-05-03 09:16:24 +00:00
|
|
|
export const depositAction = (data) => {
|
2020-04-24 15:11:08 +00:00
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchDepositPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: transactionUrl,
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2020-05-06 13:07:53 +00:00
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
2020-04-24 15:11:08 +00:00
|
|
|
},
|
|
|
|
data
|
|
|
|
})
|
|
|
|
.then(response => {
|
2020-05-03 10:21:29 +00:00
|
|
|
console.log('DEPOSIT ACTION', response);
|
2020-04-24 15:11:08 +00:00
|
|
|
dispatch(fetchDepositSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-05-03 10:21:29 +00:00
|
|
|
console.log('DEPOSIT ACTION', error);
|
2020-04-24 15:11:08 +00:00
|
|
|
dispatch(fetchDepositError(error.message));
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchDepositError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchDepositError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchDepositError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 09:16:24 +00:00
|
|
|
export const depositActionReset = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchDepositReset());
|
|
|
|
}
|
|
|
|
}
|