服务器端的REST paypal不起作用:executePayment方法不起作用

时间:2017-07-03 19:58:37

标签: c# asp.net asp.net-mvc paypal paypal-rest-sdk

我使用Paypal执行付款方式时出现问题。我试图在我的Asp.net MVC应用程序上集成服务器端Rest。我有这个方法的问题: 在服务器端,我有这个方法,它应该接收paymentId和payerID。

[HttpPost]
    public JsonResult executePayment(string paymentId,string PayerID)
    {
        // Authenticate with PayPal
        var config = ConfigManager.Instance.GetProperties();
        var accessToken = new OAuthTokenCredential(config).GetAccessToken();
        var apiContext = new APIContext(accessToken);

        var payment = new PaypalTransactions();
        PaypalTransactions.ExecutePayment();

        return Json("okadaokd", JsonRequestBehavior.AllowGet);
    }

在客户端,我有这个脚本:

<script>
    paypal.Button.render({

        env: 'sandbox', // sandbox | production

        // Show the buyer a 'Pay Now' button in the checkout flow
        commit: true,

        // payment() is called when the button is clicked
        payment: function() {

            // Set up a url on your server to create the payment
            var CREATE_URL = 'localhost:59679/Home/createPayment';

            // Make a call to your server to set up the payment
            return paypal.request.post(CREATE_URL)
                .then(function(res) {
                    return res.paymentID;
                });
        },

        // onAuthorize() is called when the buyer approves the payment
        onAuthorize: function(data, actions) {

            // Set up a url on your server to execute the payment
            var EXECUTE_URL = 'localhost:59679/Home/executePayment';

            // Set up the data you need to pass to your server
            var data = {
                paymentID: data.paymentID,
                payerID: data.payerID
            };

            // Make a call to your server to execute the payment
            return paypal.request.post(EXECUTE_URL, data)
                .then(function (res) {
                    window.alert('Payment Complete!');
                });
        }

    }, '#paypal-button-container');
</script>

客户端的付款方式运作良好,但onAuthorize不起作用。我有这个代码错误: -MLHttpRequest无法加载localhost:59679 / Home / createPayment。交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https。 -Uncaught Error:请求发布localhost:59679 / Home / createPayment失败:[object ProgressEvent]

解决方案是什么?谢谢你的帮助!

0 个答案:

没有答案