import { transactionUrl } from "./IlinkConstants"; import { fetchDepositError, fetchDepositSuccess, fetchDepositPending, fetchDepositReset } 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 } */ export 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 => { console.log('DEPOSIT ACTION', response); dispatch(fetchDepositSuccess(response)); }) .catch(error => { console.log('DEPOSIT ACTION', 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 const depositActionReset = () => { return dispatch => { dispatch(fetchDepositReset()); } }