change page after payment
akille67
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Mar-04-2020
02:47 AM
Hi, I have inserted a button to pay with paypal for the services purchased on my site.
I can enter some transaction data in a db but when he returns to the page that calls the payment the user could accidentally pay again.
How can I change the page if the payment has been successful or how can I delete the payment button if it has already been done.
Thank you
is my code:
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: $amount
},
description: $type,
}
]
});
},
// --------- onApprove ---
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// alert('Transaction completed by ' + details.payer.name.given_name+' ApplicationId <?php echo $id; ?> :payerID '+data.payerID);
// Call your server to save the transaction
return fetch('payments.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
time: details.create_time,
status: details.status,
nom: details.payer.name.given_name,
prenom: details.payer.name.surname,
pays: details.payer.address.country_code,
valeur:details.purchase_units[0].amount.value
})
}).then(data => data.ok && data.json()).then(response => {
alert(response.status);
});
});
}
}).render('#paypal-button-container');
</script>
payment.php
<?php
header('Content-Type: application/json');
$date = date('Y-m-d H:i:s');
//Receive the RAW post data.
$contentType = isset($_SERVER["CONTENT_TYPE"]) ?trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json") {
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
$decoded = json_decode($content, true);
//If json_decode failed, the JSON is invalid.
if(! is_array($decoded)) {
//echo "error";
} else {
$name = $decoded['nom'];
$prenom = $decoded['prenom'];
$name=$name." ".$prenom;
$time = $decoded['time'];
$id = $decoded['orderID'];
$stat = $decoded['status'];
$pays = $decoded['pays'];
$val = $decoded['valeur'];
include('conn.inc');
include('common.inc');
$q=new Query("INSERT INTO paypal (`nom`, `paytime`, `orderID`, `status`, `pays`, `valeur`, `paydata`) VALUES ('$name', '$time', '$id', '$stat', '$pays', '$val', '$date')");
echo '{"status":"Acquisto effettuato.\nRiceverai una email con tutti i dati della prenotazione"}';
}
} else {
echo '{"status":"Attenzione Errore nella fase di acquisto!!!"}';
}
?>
Labels:
- Labels:
-
Payments REST APIs
-
Payouts Rest APIs
0 REPLIES 0
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- IPN has stopped working - payments received but IPN list for last 24 hours is empty in PayPal Payments Standard
- Zettle reporting within PayPal Transaction Detail Report Specification in PayPal Reporting
- "Show Order Details" Vs "Capture Payment For Order" in REST APIs
- App selection for Subscription Button in Sandbox Environment
- Simple easy Checkout integration for me website. in PayPal Payments Standard