我一直在寻找这个问题的解决方案,只发现出于安全原因,你不能用jquery来定位paypal按钮。
所以我有这个表单,我需要用卡打开我的paypal窗口支付,如果成功,它应该会触发一个api调用,我将在稍后添加
<form onsubmit="openPaypal" style="margin-bottom:30px">
<div class="row heading">
<h5>Checkout information</h5>
</div>
<hr />
<div class="field">
<label>Email:</label>
<div class="price-field">
<span><i class="far fa-envelope"></i></span>
<input required name="email" type="email" value="" />
</div>
</div>
<div class="space"></div>
<div class="field">
<label>Name:</label>
<div class="price-field">
<span><i class="fas fa-user-alt"></i></span>
<input required name="name" type="text" value="" />
</div>
</div>
<div class="space"></div>
<div class="field">
<div id="paypal-button-container"></div>
<button type="submit" class="btn btn-primary">Checkout</button>
</div>
</form>我需要它以某种方式提交时,打开paypal支付表单。
我从他们的文档中复制了paypal buttons解决方案
<script src="https://www.paypal.com/sdk/js?client-id=ClientId">
// Replace YOUR_SB_CLIENT_ID with your sandbox client ID
</script>
<!-- Add the checkout buttons, set up the order and approve the order -->
<script>
function openPaypal(event) {
$('.paypal-button-number-1').click();
}
paypal.Buttons({
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container'); // Display payment options on your web page
</script>具体地说,我寻找类似sellfy.com的paypal结账的东西。你在购物车中输入你的凭证,它会进行验证,然后将你发送到某个贝宝网页。在那里你输入paypal需要的东西,最后你有返回商家,在那里你被重定向到你的网站(在那个重定向中,我想你可以调用一个方法来完成下一部分的结账)
发布于 2020-08-09 06:55:18
嗯,所以
function openPaypal(event) {
paypal.Buttons({
[..snip..]
}).render('#paypal-button-container');
}既然你想让它“启动一个API调用”,你就应该在服务器端创建和捕获支付。为此,您需要以下UI按钮代码:https://developer.paypal.com/demo/checkout/#/pattern/server
在您的服务器上有两个相应的路由,一个用于“设置事务”,另一个用于“捕获事务”,记录在这里:https://developer.paypal.com/docs/checkout/reference/server-integration/
https://stackoverflow.com/questions/63318104
复制相似问题