Created
August 29, 2016 23:28
-
-
Save ccorcos/dea62720a3654595939b168522ad9147 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
// api.js | |
export function makePayment(loanId, amount, paymentMethodId) { | |
return fetch(`/api/loans/${loanId}/payments`, { | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
}), | |
credentials: 'same-origin', | |
method: 'POST', | |
body: JSON.stringify({ | |
'amount': amount, | |
'paymentMethodId': paymentMethodId, | |
}) | |
}) | |
} | |
// actions.js | |
import * as api from './api' | |
export function makePayment(loanId, amount, paymentMethodId) { | |
return dispatch => { | |
dispatch(makePaymentSent()) | |
api.makePayment(loanId, amount, 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