Reputation: 11
I have added my button script from Paypal to my php file and it outputs the buttons nicely.
I need $myvariable to be at the end of the return url where paypal sends someone back to my site upon successful payment.
This return url will be a constant but the $myvariable will be different with every customer.
ex: https://example.com/index3.php?processid=$myvariable $myvariable will be a 7 digit unique reference number.
I believe I must use Paypals "rm parameter" and have "return url" turned on at paypal developer.
The following was recommended in a 2011 post. But I don't know where to put it. <INPUT TYPE="hidden" NAME="return" value="<?php echo 'example.com/complete.php?option='.$theoption ?>">
Please, what code do I add to the following Paypal button code to get a return as described.
HERE IS MY BUTTON CODE FROM PAYPAL ("example.com" in script is paypal)
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.example.com/sdk/js?client-id=sb&enable-funding=venmo¤cy=USD" data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"1 \".csv\" file download","amount":{"currency_code":"USD","value":19.95}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Full available details
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
// Show a success message within this page, e.g.
const element = document.getElementById('paypal-button-container');
element.innerHTML = '';
element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
},
onError: function(err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
Upvotes: 1
Views: 42
Reputation: 30359
2024 edit: actions.order.create , actions.order.capture, and actions.redirect are all deprecated; do not use any of them for any purpose.
<script src="https://www.example.com/sdk/js?client-id=sb&enable-funding=venmo¤cy=USD" data-sdk-integration-source="button-factory"></script>
First of all, fix this SDK src url. It should be paypal.com
JS SDK integrations do not redirect away from your page, and so they do not need to "return" anywhere. On success, they can simply display a success message. This is where that happens:
// Show a success message within this page, e.g.
const element = document.getElementById('paypal-button-container');
element.innerHTML = '';
element.innerHTML = '<h3>Thank you for your payment!</h3>';
If, for some reason, you don't want to stay on the current page and wish to redirect to a different page, uncomment the line that follows:
// Or go to another URL: actions.redirect('thank_you.html');
And give it the path or URL you want.
There will be no transaction information in the resulting URL, unless you parse it out from orderData
and add it to the URL you specify. Never perform any automated operations with data passed this way.
Upvotes: 1