首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使结账按钮初始化paypal支付表单?ASP.NET核心MVC

如何使结账按钮初始化paypal支付表单?ASP.NET核心MVC
EN

Stack Overflow用户
提问于 2020-08-09 01:05:56
回答 1查看 350关注 0票数 0

我一直在寻找这个问题的解决方案,只发现出于安全原因,你不能用jquery来定位paypal按钮。

所以我有这个表单,我需要用卡打开我的paypal窗口支付,如果成功,它应该会触发一个api调用,我将在稍后添加

代码语言:javascript
复制
<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解决方案

代码语言:javascript
复制
 <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需要的东西,最后你有返回商家,在那里你被重定向到你的网站(在那个重定向中,我想你可以调用一个方法来完成下一部分的结账)

EN

回答 1

Stack Overflow用户

发布于 2020-08-09 06:55:18

嗯,所以

代码语言:javascript
复制
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/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63318104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档