ilink-world/webservice/WalletApi.js

228 lines
6.9 KiB
JavaScript
Raw Normal View History

2020-07-02 14:35:00 +00:00
import {
2020-11-18 11:22:53 +00:00
commissionAmount,
getOperatorListUrl,
linkCardUrl,
walletActionUrl,
walletDetailUrl,
walletUserSimpleActionUrl
} from "./IlinkConstants";
import {
fetchGetListOperatorError,
fetchGetListOperatorPending,
fetchGetListOperatorReset,
fetchGetListOperatorSuccess,
fetchLinkCardError,
fetchLinkCardPending,
fetchLinkCardReset,
fetchLinkCardSuccess,
fetchWalleGetCommissionError,
fetchWalletGetCommissionPending,
fetchWalletGetCommissionSuccess,
fetchWalletListDetailError,
fetchWalletListDetailPending,
fetchWalletListDetailReset,
fetchWalletListDetailSuccess,
fetchWalletListError,
fetchWalletListPending,
fetchWalletListReset,
fetchWalletListSuccess,
walletGetCommissionReset
2020-07-02 14:35:00 +00:00
} from "../redux/actions/WalletActions";
2020-11-18 11:22:53 +00:00
import {store} from "../redux/store";
2020-04-18 23:19:11 +00:00
import axios from "axios";
2020-05-06 13:07:53 +00:00
import I18n from 'react-native-i18n'
2020-04-18 19:59:05 +00:00
2020-05-03 09:16:24 +00:00
export const getWalletActivated = (userID) => {
2020-04-18 19:59:05 +00:00
2020-11-18 11:22:53 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchWalletListPending());
axios({
url: `${walletActionUrl}/${userID}/activated`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchWalletListSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchWalletListError(error.response));
else if (error.request)
dispatch(fetchWalletListError(error.request))
else
dispatch(fetchWalletListError(error.message))
});
}
2020-04-18 19:59:05 +00:00
}
2020-05-03 09:16:24 +00:00
export const resetWalletListReducer = () => {
2020-11-18 11:22:53 +00:00
return dispatch => {
dispatch(fetchWalletListReset());
}
2020-05-03 09:16:24 +00:00
}
2020-05-06 11:04:26 +00:00
export const getWalletDetailActivated = (id, isAgentCall) => {
2020-04-18 19:59:05 +00:00
2020-11-18 11:22:53 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
console.log("isAgentCall", isAgentCall);
let url = null;
if (isAgentCall === null)
url = `${walletUserSimpleActionUrl}/${id}`;
else if (isAgentCall === false)
url = `${walletDetailUrl}/${id}`;
else
url = `${walletActionUrl}/${id}/activated`;
return dispatch => {
dispatch(fetchWalletListDetailPending());
axios({
url,
method: 'GET',
headers: {
'Authorization': authKey
}
})
.then(response => {
console.log("RESPONSE", response);
dispatch(fetchWalletListDetailSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchWalletListDetailError(error.response));
else if (error.request)
dispatch(fetchWalletListDetailError(error.request))
else
dispatch(fetchWalletListDetailError(error.message))
});
}
2020-05-03 09:16:24 +00:00
}
export const resetWalletListDetailReducer = () => {
2020-11-18 11:22:53 +00:00
return dispatch => {
dispatch(fetchWalletListDetailReset());
}
2020-05-03 09:16:24 +00:00
}
export const getWalletCommissionAmount = (data) => {
2020-11-18 11:22:53 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchWalletGetCommissionPending());
axios({
url: `${commissionAmount}`,
method: 'POST',
headers: {
'Authorization': authKey
},
data
})
.then(response => {
console.log(response);
dispatch(fetchWalletGetCommissionSuccess(response));
})
.catch(error => {
console.log(error);
dispatch(fetchWalleGetCommissionError(error.message));
if (error.response)
dispatch(fetchWalleGetCommissionError(error.response));
else if (error.request)
dispatch(fetchWalleGetCommissionError(error.request))
else
dispatch(fetchWalleGetCommissionError(error.message))
});
}
2020-05-03 09:16:24 +00:00
}
export const walletCommissionAmountReset = () => {
2020-11-18 11:22:53 +00:00
return dispatch => {
dispatch(walletGetCommissionReset());
}
2020-05-03 09:16:24 +00:00
}
2020-07-02 14:35:00 +00:00
export const linkCardAction = (data, userID) => {
2020-11-18 11:22:53 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchLinkCardPending());
axios({
url: `${linkCardUrl}/${userID}`,
data,
method: 'POST',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchLinkCardSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchLinkCardError(error.response));
else if (error.request)
dispatch(fetchLinkCardError(error.request))
else
dispatch(fetchLinkCardError(error.message))
});
}
2020-07-02 14:35:00 +00:00
}
export const linkCardReset = () => {
2020-11-18 11:22:53 +00:00
return dispatch => {
dispatch(fetchLinkCardReset());
}
}
export const getOperatorListAction = (typeOperator, idNetworkWallet) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchGetListOperatorPending());
axios({
url: `${getOperatorListUrl}/${typeOperator}/${idNetworkWallet}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchGetListOperatorSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchGetListOperatorError(error.response));
else if (error.request)
dispatch(fetchGetListOperatorError(error.request))
else
dispatch(fetchGetListOperatorError(error.message))
});
}
}
export const getOperatorListReset = () => {
return dispatch => {
dispatch(fetchGetListOperatorReset());
}
2020-07-02 14:35:00 +00:00
}