我是braintree支付网关的新手。我使用自定义集成进行payment.i使用信用卡成功完成我的付款。但我有两个问题,我也想在表单中添加我选择的数量。
1)我想在我的表单中添加更多字段,如客户名称,地址,电话号码,电子邮件,我不知道如何在托管字段中添加更多字段。
2)老实说,我不知道如何在braintree中配置paypal.even braintree说"默认情况下,Sandbox中启用了PayPal。" 当我点击paypal按钮它显示错误 "抱歉,我们无法连接到PayPal。请在几分钟后再试一次。"我在印度创建了我的沙盒帐户。可能PayPal不允许来自印度的PayPal付款。
<?php
require ('vendor/autoload.php');
$clientToken = Braintree_ClientToken::generate();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Checkout</title>
</head>
<body>
<form action="#" id="my-sample-form">
<div id="paypal-container"></div>
<label for="card-number">Card Number</label>
<div id="card-number"></div>
<label for="cvv">CVV</label>
<div id="cvv"></div>
<label for="expiration-date">Expiration Date</label>
<div id="expiration-date"></div>
<input type="submit" value="Pay" />
</form>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup("<?php echo $clientToken; ?>", "custom", {
id: "my-sample-form",
hostedFields: {
number: {
selector: "#card-number"
},
cvv: {
selector: "#cvv"
},
expirationDate: {
selector: "#expiration-date"
}
},
paypal: {
container: "paypal-container",
},
onPaymentMethodReceived: function (obj) {
window.location.href = 'http://localhost/braintreecustom/payment.php?payment_method_nonce='+obj.nonce;
},
onError: function (){
alert('wrong details');
}
});
</script>
</body>
</html>
这是payment.php的代码
<?php
require ('vendor/autoload.php');
$nonce = $_GET["payment_method_nonce"];
$result = Braintree_Transaction::sale([
'amount' => '700.00', // Your amount goes here
'paymentMethodNonce' => $nonce
]);
?>
答案 0 :(得分:0)
完全披露:我在Braintree工作。如果您还有其他问题,请随时contact support。
1)要添加其他字段,您只需要在表单中添加输入字段,并按照托管字段输入的方式设置样式。提交表单时,您可以将这些值捕获为普通表单输入。
<form action="#" id="my-sample-form">
<div id="paypal-container"></div>
<label for="card-number">Card Number</label>
<div id="card-number"></div>
<label for="cvv">CVV</label>
<div id="cvv"></div>
<label for="expiration-date">Expiration Date</label>
<div id="expiration-date"></div>
<label for="another-field">Another Field</label>
<input type="text" id="another-field" name="another-field" />
<input type="submit" value="Pay" />
</form>
这是服务器代码
<?php
require('vendor/autoload.php');
$nonce = $_GET["payment_method_nonce"];
$anotherField = $_GET["another-fild"];
// do something with fields
2)根据给定的信息,我不确定您的PayPal配置有什么问题。我建议reaching out to Braintree support,以便他们可以帮助您排查问题。