我写了一个简单的PHP脚本来制作PayPal弹出支付按钮:
<!-- 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 BraintreeGateway([
'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>
所有步骤(包括结算(都在工作,但问题是我有一些JS错误,代码401来自PayPal服务器,因为客户端Id如下:
https://pasteboard.co/PABp8HzbdfhB.png
加载资源失败:服务器响应状态为401((
我在PayPal&Braintree文档,但找不到如何传递我的客户端id。所有手册都是关于旧版本的SDK!
那么解决方案是什么呢?
在Braintree网关设置中链接PayPal沙箱帐户,处理。