diff --git a/pages/FamilyDetail.tsx b/pages/FamilyDetail.tsx index c367ac7..954ab8d 100644 --- a/pages/FamilyDetail.tsx +++ b/pages/FamilyDetail.tsx @@ -167,8 +167,9 @@ export const FamilyDetail: React.FC = () => { } else { setShowAddModal(false); } - } catch (e) { + } catch (e: any) { console.error("Failed to add payment", e); + alert(`Errore durante il salvataggio del pagamento: ${e.message || "Errore sconosciuto"}`); } finally { setIsSubmitting(false); } @@ -509,17 +510,25 @@ export const FamilyDetail: React.FC = () => { description: `Quota ${MONTH_NAMES[newPaymentMonth - 1]} ${selectedYear} - Famiglia ${family.name}`, amount: { currency_code: "EUR", - value: newPaymentAmount.toString(), + value: newPaymentAmount.toFixed(2), }, }, ], }); }} - onApprove={(data, actions) => { - if(!actions.order) return Promise.resolve(); - return actions.order.capture().then((details) => { - handlePaymentSuccess(details); - }); + onApprove={async (data, actions) => { + if(!actions.order) return; + try { + const details = await actions.order.capture(); + await handlePaymentSuccess(details); + } catch (err) { + console.error("PayPal Capture Error", err); + alert("Errore durante il completamento del pagamento PayPal."); + } + }} + onError={(err) => { + console.error("PayPal Button Error", err); + alert("Errore caricamento PayPal: " + err.toString()); }} />