【问题标题】:Uncaught Error: No value passed to payment未捕获的错误:没有值传递给付款
【发布时间】:2017-12-13 14:45:52
【问题描述】:

Windows 上的 ASP.Net Framework 4.5.2

我正在使用 服务器端 REST 配置与 paypal 的集成,我的代码与 https://github.com/paypal/PayPal-NET-SDK/blob/develop/Samples/Source/PaymentWithPayPal.aspx.cs 相同,没有区别。

支付模式

创建的支付模型是这样的:

{"intent":"sale","payer":{"payment_method":"paypal"},"transactions":[{"amount":{"currency":"USD","total":"100.00","details":{"subtotal":"75","shipping":"10","tax":"15"}},"description":"Transaction description.","invoice_number":"608961","item_list":{"items":[{"sku":"sku","name":"Item Name","quantity":"5","price":"15","currency":"USD"}]}}],"redirect_urls":{"return_url":"http://localhost:51379/PaymentWithPayPal.aspx?guid=60896","cancel_url":"http://localhost:51379/PaymentWithPayPal.aspx?guid=60896&cancel=true"}}

支付模型创建后

我在此行创建付款

var createdPayment = payment.Create(apiContext);

创建支付

而 createdPayment 变量等于:

{"id":"PAY-8TG15254J2564684XLFQUQHQ","intent":"sale","payer":{"payment_method":"paypal"},"transactions":[{"related_resources":[],"amount":{"currency":"USD","total":"100.00","details":{"subtotal":"75.00","shipping":"10.00","tax":"15.00"}},"description":"Transaction description.","invoice_number":"608961","item_list":{"items":[{"sku":"sku","name":"Item Name","quantity":"5","price":"15.00","currency":"USD"}]}}],"state":"created","create_time":"2017-07-08T21:01:18Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-8TG15254J2564684XLFQUQHQ","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-6PE445186E489192C","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-8TG15254J2564684XLFQUQHQ/execute","rel":"execute","method":"POST"}]}

错误

之后,代码继续运行,没有任何错误,完成后,paypal 窗口关闭,我在 javascript 上收到下一个错误: 错误:没有值传递给付款

Object {stack: "Error: No value passed to payment↵ at https://w…://www.paypalobjects.com/api/checkout.js:2390:13)", errtype: "[object Error]", timestamp: 1499547706746, windowID: "5148517b93", pageID: "510d0e1522"…} country:"US" env:"sandbox" errtype:"[object Error]" host:"www.sandbox.paypal.com" lang:"en" pageID:"510d0e1522" path:"/webapps/hermes/button" referer:"http://localhost:51379" stack:"Error: No value passed to payment↵ at https://www.paypalobjects.com/api/checkout.js:7986:52↵ at https://www.paypalobjects.com/api/checkout.js:7417:54↵ at ZalgoPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:7441:27)↵ at ZalgoPromise.resolve (https://www.paypalobjects.com/api/checkout.js:7386:22)↵ at https://www.paypalobjects.com/api/checkout.js:7363:48↵ at https://www.paypalobjects.com/api/checkout.js:7417:54↵ at ZalgoPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:7441:27)↵ at ZalgoPromise.resolve (https://www.paypalobjects.com/api/checkout.js:7386:22)↵ at https://www.paypalobjects.com/api/checkout.js:7440:42↵ at ZalgoPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:7441:27)↵ at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2471:118)↵ at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2369:77)↵ at messageListener (https://www.paypalobjects.com/api/checkout.js:2390:13)" timestamp : 1499547706746 uid : "8cb15883be" ver : "4.0.89" windowID : "5148517b93" __proto__ : Object

这是我的 PayPal CheckoutJS

paypal.Button.render({
        env: 'sandbox',
        commit: true,
        payment: function () {

            // Set up a url on your server to create the payment
            var CREATE_URL = "@Url.Action("MakePaymentWithPayPal", "Payment")";

            // Make a call to your server to set up the payment
            return paypal.request.post(CREATE_URL)
                .then(function (res) {
                    console.log("res");
                    console.log(res);//this is always empty
                    return res.paymentID;
                }).catch(function (err) {
                    reject("err");
                    reject(err);
                });
        },
        onAuthorize: function (data, actions) {

            // Set up a url on your server to execute the payment
            var EXECUTE_URL = '/demo/checkout/api/paypal/payment/execute/';

            // 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!');
                    console.log(res);
                });
        }
    }, '#paypal-button');`

【问题讨论】:

  • 你能分享你的客户端代码吗?您是否将PAY-XXXXXX id 直接传回 payment() 函数?
  • 准备好了!我已编辑问题。
  • 您的服务器是否在响应中返回了有效的 json,带有content-type: application/json?你能检查一下 chrome 网络标签吗?
  • 响应头只有这些HTTP/1.1 200 OK Cache-Control: private, s-maxage=0 Server: Microsoft-IIS/10.0 X-AspNetMvc-Version: 5.2 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcc3RldmVcRG9jdW1lbnRzXEdpdEh1YlxBTWVtb3J5Rm9yRXZlclxBTWVtb3J5Rm9yRXZlclxQYXltZW50XE1ha2VQYXltZW50V2l0aFBheVBhbA==?= X-Powered-By: ASP.NET Date: Wed, 12 Jul 2017 22:40:26 GMT Content-Length: 0
  • Content-Length: 0 -- 所以没有响应正文?

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


【解决方案1】:

感谢bluepnume让我大开眼界

我将方法从 Void 类型更改为 String 类型 => 此更改是为了将我的服务器的响应返回到客户端 js

在create payment code的最后,我加了一行保存guid号和return

HttpContext.Current.Session.Add("guid", guid); //we need this number on authorize payment
HttpContext.Current.Session.Add(guid, createdPayment.id);
HttpContext.Current.Session.Add("flow-" + guid, this.flow);
return JsonConvert.SerializeObject(createdPayment, Formatting.None); //I return the created payment

现在在 JS,我通过正确的付款 ID 更改了退货

        payment: function () {
            var CREATE_URL = "@Url.Action("MakePaymentWithPayPal", "Payment")";
            return paypal.request.post(CREATE_URL)
                .then(function (res) {
                    //return res.paymentID; //earlier line
                    return res.id;
                });
        },

在授权支付代码的开头,我交换了检索 guid 的行以继续交易,最后我返回执行的支付

//var guid = HttpContext.Current.Request.Params["guid"]; //earlier line
string guid = HttpContext.Current.Session["guid"].ToString();

//code...

return JsonConvert.SerializeObject(executedPayment, Formatting.None);

现在可以付款了。

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 2018-11-14
    • 2018-08-17
    • 2021-06-22
    • 2021-10-28
    • 2015-08-18
    • 2021-10-11
    • 2013-12-05
    • 2018-01-21
    相关资源
    最近更新 更多