ilink-world/webservice/DepositApi.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-24 15:11:08 +00:00
import { transactionUrl } from "./IlinkConstants";
import { fetchDepositError, fetchDepositSuccess, fetchDepositPending } from "../redux/actions/DepositAction";
import { store } from "../redux/store";
import axios from "axios";
/*
{
"type" : "debit",
"numCarte" : 12345454445,
"montant":10000,
"cvv": 325,
"expiration_date": "03/2024",
"id_wallet":1
}
*/
const depositAction = (data) => {
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: {
'Authorization': authKey
},
data
})
.then(response => {
dispatch(fetchDepositSuccess(response));
})
.catch(error => {
dispatch(fetchDepositError(error.message));
if (error.response)
dispatch(fetchDepositError(error.response));
else if (error.request)
dispatch(fetchDepositError(error.request))
else
dispatch(fetchDepositError(error.message))
});
}
}
export default depositAction;