mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-03 07:42:03 +00:00
Update src/hooks/courses/useCoursePayment.js
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
44929d54b9
commit
f8bd1ddb43
@ -34,11 +34,23 @@ const useCoursePayment = (course) => {
|
||||
|
||||
// Handler for successful payment
|
||||
const handlePaymentSuccess = useCallback(async (response) => {
|
||||
if (response && response?.preimage) {
|
||||
// Update session to reflect purchase
|
||||
const updated = await update();
|
||||
showToast('success', 'Payment Success', 'You have successfully purchased this course');
|
||||
return true;
|
||||
if (response?.preimage) {
|
||||
try {
|
||||
await update(); // refresh session
|
||||
showToast(
|
||||
'success',
|
||||
'Payment Success',
|
||||
'You have successfully purchased this course'
|
||||
);
|
||||
return true;
|
||||
} catch (err) {
|
||||
showToast(
|
||||
'warn',
|
||||
'Session Refresh Failed',
|
||||
'Purchase succeeded but we could not refresh your session automatically. Please reload the page.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
showToast('error', 'Error', 'Failed to purchase course. Please try again.');
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user