AUTHENTICATION_FAILURE when trying to access adata tranasactions API

Bazanez
Contributor
Contributor

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);

Login to Me Too
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.