Closed bobbiec closed 5 years ago
I pulled this and tested locally - looks good! LMK when you're ready to merge (if you'd like to implement any of the comments, remove console.logs, etc)
Addressed the style fixes, thanks.
I disagree with your comments. I feel like the first two don't really add anything, while the third and fourth show a misunderstanding of how the code flows.
I would read this code (and UI code in general) not from top-to-bottom, but from interaction to result. So in the Cart, the Check Out button has an onClick handler payForCart (inline below).
return async () => {
// create a new transaction
const response = await createTransaction(totalPrice) as any;
const newTransaction = createTransactionResponse.validate(response);
if (newTransaction.error) {
alert(newTransaction.error);
return;
}
// open a new window for customer to complete the payment
const transactionId = newTransaction.value.id;
const getTransactionUrl = `http://credit.17-356.isri.cmu.edu/?transaction_id=${transactionId}`
var win = window.open(getTransactionUrl, '_blank');
if (win === null) {
return;
}
// start polling to monitor status
this.startTransactionPolling(transactionId);
// switch focus to the new tab
win.focus();
}
}
I think the comments in this function give a fairly high-level overview of what happens:
From there, startTransactionPolling
calls checkTransactionStatus
, which checks the status, validates it, and stops the polling once the transaction resolves to a finished state.
Super helpful, thank you! I really like that distinction for how to read UI code and non UI code ; In the few formal programming classes I've taken, that has not come up. However the process of understanding where the interaction in the code first starts seems non-trivial...
I actually wasn't sure of how to get a transaction approved (aka, what I need to fill out on the web form), but I confirmed that it works for denying.