Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created August 29, 2016 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccorcos/334f4d5571326fd88984076d06b4bc5c to your computer and use it in GitHub Desktop.
Save ccorcos/334f4d5571326fd88984076d06b4bc5c to your computer and use it in GitHub Desktop.
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) {
dispatch(makePaymentFailed(response.statusText))
} else {
return response.json()
.then(result => {
dispatch(makePaymentSuccess(result.data))
})
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment