The Community Forum will no longer be available starting June 30, 2025. Please note that the forum is now closed for new posts and responses, but previous posts will remain accessible for review until June, 30 2025. For comprehensive support options, please visit PayPal.com/HelpCenter
Merchant Technical Support: For technical support and related questions, please visit our Technical Support Help Center or Developer Central
If you want to report illegal content under the EU Digital Services Act, please do so here
This is my code:
index.php
script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=USD"
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
env: 'sandbox', // sandbox | production
style: {
label: 'checkout', // checkout | credit | pay | buynow | generic
size: 'responsive', // small | medium | large | responsive
shape: 'pill', // pill | rect
color: 'gold' // gold | blue | silver | black
},
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '',
production: ''
},
// Wait for the PayPal button to be clicked
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: ''
},
description: 'Compra de productos a a :',
reference_id: "#dsadasdasdasdasdas"
}]
});
},
// Wait for the payment to be authorized by the customer
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
console.log(data);
// Show a success message to the buyer
//alert('Transaction completed by ' + details.payer.name.given_name + '!');
window.location="verificador.php?paymentToken="+data.payerID+"&orderID="+data.authorization_id;
alert('sdasdasdasd');
});
}
}).render('#paypal-button-container');
</script>
sale.php
$login = curl_init();
$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
curl_setopt($login,CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_RETURNTRANSFER, true);
curl_setopt($login, CURLOPT_USERPWD, $clienteID.":".$secret);
curl_setopt($login, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$request = curl_exec($login);
echo "<br>";
echo "<br>";
echo "<br>";
$objResponse = json_decode($request);
$accessToken = $objResponse -> access_token;
print_r($accessToken);
echo "<br>";
echo "<br>";
echo "<br>";
$venta = curl_init( "https://api.sandbox.paypal.com/v2/payments/authorizations/".$_GET['orderID']);
curl_setopt($venta, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$accessToken));
$responseVenta = curl_exec($venta);
$objResponseVenta = json_decode($responseVenta);
print_r($objResponseVenta);