-
-
Save Boorj/24321cea94506d28c94231597bbbf47b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function makePayment(loanId, amount, paymentMethodId) { | |
return dispatch => { | |
dispatch(makePaymentSent()) | |
fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ | |
'amount': amount, | |
'paymentMethodId': paymentMethodId, | |
}) | |
}) | |
.then(response => { | |
dispatch(closeModal()) | |
if (response.status !== 200) { | |
throw new Error(response.statusText) | |
} else { | |
return response.json() | |
} | |
}) | |
.then(result => { | |
dispatch(makePaymentSuccess(result.data)) | |
}) | |
.catch(error => { | |
dispatch(makePaymentFailed(error.message)) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment