I wrote a simple PHP script to make PayPal popup payment button :
<!-- Load the required checkout.js script -->
<script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script>
<!-- Load the required Braintree components. -->
<script src="https://js.braintreegateway.com/web/3.87.0/js/client.min.js?"></script>
<script src="https://js.braintreegateway.com/web/3.87.0/js/paypal-checkout.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
<?php
require_once 'vendor/lib/Braintree.php';
$access_token = 'access_token$sandbox$...3';
$gateway = new Braintree\Gateway([
'accessToken' => $access_token,
]);
$clientToken = $gateway->clientToken()->generate();
?>
paypal.Button.render({
braintree: braintree,
client: {
//production: '<?= $clientToken ?>',
sandbox: '<?= $clientToken ?>'
},
env: 'sandbox',
style: {
shape: 'rect',
color: 'blue',
layout: 'horizontal',
label: 'pay',
},
payment: function (data, actions) {
return actions.braintree.create({
flow: 'checkout', // Required
amount: 10.00, // Required
currency: 'USD', // Required
intent: 'sale',
enableShippingAddress: false
});
},
onAuthorize: function (payload) {
$.ajax({
url : 'verify.php',
type : 'POST',
data: {
"payment_method_nonce": payload.nonce
},
success : function (result) {
alert(result);
},
error : function () {
alert(result);
}
});
},
}, '#paypal-button');
</script>
<div id="paypal-button"></div>
All steps (including settle) are working but the problem is that I have some JS errors with code 401 from PayPal server because of Client Id as below :
https://pasteboard.co/PABp8HzbdfhB.png
Failed to load resource: the server responded with a status of 401 ()
I searched in PayPal & Braintree docs but couldn't find how to pass my client id. All manuals are about older versions of SDK!
So what's the solution?
Link a PayPal sandbox account in the Braintree gateway settings, Processing.