give
/
src
/
DonorDashboards
/
resources
/
js
/
app
/
components
/
subscription-manager
/
utils
/
index.js
give
/
src
/
DonorDashboards
/
resources
/
js
/
app
/
components
/
subscription-manager
/
utils
Last commit date
index.js
3 years ago
index.js
27 lines
| 1 | import {store} from '../../../tabs/recurring-donations/store'; |
| 2 | import {donorDashboardApi} from '../../../utils'; |
| 3 | import {fetchSubscriptionsDataFromAPI} from '../../../tabs/recurring-donations/utils'; |
| 4 | import {setError} from '../../../tabs/recurring-donations/store/actions'; |
| 5 | |
| 6 | export const updateSubscriptionWithAPI = ({id, amount, paymentMethod}) => { |
| 7 | const {dispatch} = store; |
| 8 | return donorDashboardApi |
| 9 | .post( |
| 10 | 'recurring-donations/subscription/update', |
| 11 | { |
| 12 | id: id, |
| 13 | amount: amount, |
| 14 | payment_method: paymentMethod, |
| 15 | }, |
| 16 | {}, |
| 17 | ) |
| 18 | .then(async (response) => { |
| 19 | if (response.data.status === 400) { |
| 20 | dispatch(setError(response.data.body_response.message)); |
| 21 | return; |
| 22 | } |
| 23 | await fetchSubscriptionsDataFromAPI(); |
| 24 | return response; |
| 25 | }); |
| 26 | }; |
| 27 |