fecmall 集成 braintreepayments 信用卡收款方式(php Yii2框架) 客户端部分
https://developers.braintreepayments.com/start/hello-client/javascript/v3
客户端部分,最简单的方式就是使用Drop-in UI

html代码
Add Drop-in to your page
<head>
<meta charset="utf-8">
<script src="https://js.braintreegateway.com/web/dropin/1.21.0/js/dropin.min.js"></script>
</head>
<body>
<div id="dropin-container"></div>
<button id="submit-button">Request payment method</button>
<script>
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_TOKEN_FROM_SERVER',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (err, payload) {
// Submit payload.nonce to your server
});
});
});
</script>
</body>
CLIENT_TOKEN_FROM_SERVER
是由服务端生成,详细参看:
https://developers.braintreepayments.com/start/hello-server/php#generate-a-client-token
您可以通过ajax进行获取这个值
测试
When testing in the sandbox, be sure to use our test card numbers (e.g. 4111111111111111) and nonces (e.g. fake-valid-nonce). Real payment method data will not work in the sandbox. See our Testing page for more details.
Testing page:https://developers.braintreepayments.com/reference/general/testing/php
发送支付方式随机数到服务端
Braintree客户端SDK,(已经集成该功能)将付款信息(例如信用卡或PayPal授权)发送到Braintree,以换取支付方式随机数
(代表该付款方式的一次性使用价值)。
客户端获取支付方式随机数
,发送给服务端,
服务端通过 Braintree SDK,和付款方式随机数
来对卡进行收费或更新客户的付款方式。