I have a website where the user fills in a form, and when they submit, my site inserts the info into a mySql database, then the user makes the payment using a PayPal button. After the sale is complete, Paypal returns the user to example.com/thank-you?id=XXX and the details are extracted from the mySql database and sent to the email.
The problem is that the database does not have any information about whether they actually completed the payment. The customer can go directly to the Thankyou page by entering the URL (along with the order number). I want the thankyou page to load only when that order is marked as completed in the database.
Is there anything I can insert in the Paypal button code to update the order in my database with a "paid" flag?
This is my PayPal smart button code:
<script
src="https://www.paypal.com/sdk/js?client-id=sb"> // Required. Replace SB_CLIENT_ID with your sandbox client ID.
</script>
<div id="paypal-button-container" id="contine_btn"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
invoice_id: '<?php echo $order_id; ?>',
description: '<?php echo $details['service']; ?>',
amount: {
value: '<?php echo $details['cost']; ?>'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
actions.redirect('<?php echo 'https://www.example.com/thank-you/?id='.$order_id; ?>');
});
}
}).render('#paypal-button-container');
</script>