I first ask the user for a username and email address, after they submit that form, the user will be able to click one of the PayPal buttons. The user then makes a purchase and is redirected back to a confirmation page. My question is how can I verify the payment. I understand that it’s not possible to get the purchasers email address, is there some other way I can verify the purchase? Here is the code which presents the PayPal buttons.
<!DOCTYPE html>
<html>
<head>
<script src="https://www.paypal.com/sdk/js?client-id={MY-CLIENT-ID}¤cy=USD"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// Set up order details
return actions.order.create({
intent: 'CAPTURE',
application_context: {
shipping_preference: 'NO_SHIPPING' // Adjust as needed
},
purchase_units: [{
amount: {
value: 1.00, // Replace with your product price
currency: 'USD'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Handle successful payment (e.g., redirect to confirmation page)
window.location.href = 'https://www.example.com/paidregistrations/confirm?paymentId=' + details.id;
});
},
onError: function(err) {
console.error('Error:', err);
}
}).render('#paypal-button-container');
</script>
</body>
</html>