Однако, когда я нажимаю кнопку «Использовать дебетовую/кредитную карту» под кнопкой PayPal, это работает.

const PayPalButton: React.FC = ({
amount,
onSuccess,
currency = 'USD'
}) => {
// Create order function
const createOrder = (data: any, actions: any) => {
return actions.order.create({
purchase_units: [{
amount: {
value: amount, // Use the prop instead of hardcoded value
currency_code: currency, // Use the currency prop
},
}],
}).then((orderID:string)=> {
console.log(orderID) ;
return orderID ;
})
};
const onApprove = (data: any, actions: any) => {
return actions.order.capture().then((details: any) => {
console.log("Transaction details:", details); // Log details of the successful capture
onSuccess(details); // Call your success callback with the details
alert('Transaction completed by ' + details.payer.name.given_name);
}).catch((error: any) => {
console.error("Error capturing payment:", error); // Log any error during capture
alert("An error occurred while completing the transaction.");
});
};
// Handle errors
const onError = (err: any) => {
console.error("PayPal error:", err);
alert("An error occurred during the payment process.");
};
if (!process.env.NEXT_PUBLIC_CLIENT_ID) {
console.error("PayPal Client ID is not configured");
return null;
}
return (
);
};
export default PayPalButton;
Подробнее здесь: https://stackoverflow.com/questions/793 ... l-closes-a