Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 服务器端REST paypal不';t工作:executePayment方法不';行不通_C#_Asp.net_Asp.net Mvc_Paypal_Paypal Rest Sdk - Fatal编程技术网

C# 服务器端REST paypal不';t工作:executePayment方法不';行不通

C# 服务器端REST paypal不';t工作:executePayment方法不';行不通,c#,asp.net,asp.net-mvc,paypal,paypal-rest-sdk,C#,Asp.net,Asp.net Mvc,Paypal,Paypal Rest Sdk,我对Paypal的执行付款方式有问题。我正在尝试将服务器端Rest集成到我的Asp.net MVC应用程序中。我对这种方法有一个问题: 在服务器端,我使用了这个方法,它应该接收paymentId和payerID [HttpPost] public JsonResult executePayment(string paymentId,string PayerID) { // Authenticate with PayPal var config =

我对Paypal的执行付款方式有问题。我正在尝试将服务器端Rest集成到我的Asp.net MVC应用程序中。我对这种方法有一个问题: 在服务器端,我使用了这个方法,它应该接收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>

paypal.Button.render({
env:'沙盒',//沙盒|生产
//在结账流程中向买家显示“立即付款”按钮
承诺:对,
//单击按钮时调用payment()
支付:功能(){
//在服务器上设置url以创建付款
var CREATE_URL='localhost:59679/Home/createPayment';
//致电您的服务器设置付款
返回paypal.request.post(创建URL)
.然后(功能(res){
返回res.paymentID;
});
},
//当买方批准付款时调用onAuthorize()
onAuthorize:函数(数据、操作){
//在服务器上设置url以执行付款
var EXECUTE_URL='localhost:59679/Home/executePayment';
//设置需要传递到服务器的数据
风险值数据={
paymentID:data.paymentID,
payerID:data.payerID
};
//致电您的服务器以执行付款
返回paypal.request.post(执行URL,数据)
.然后(功能(res){
window.alert('Payment Complete!');
});
}
}“#贝宝按钮容器”);
客户端的付款方式很好,但onAuthorize不起作用。我发现以下代码错误: -MLHttpRequest无法加载本地主机:59679/Home/createPayment。跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https。 -未捕获错误:请求发布本地主机:59679/Home/createPayment失败:[object ProgressEvent]


解决办法是什么?谢谢你的帮助

您是否尝试过在CREATE_URL和EXECUTE_URL变量的开头添加“http://”?因为它说跨站点的原始请求只受HTTP调用的支持,所以我猜它没有将其检测为HTTP调用。我已经尝试过了,但它仍然不能工作只是为了确定。您在开始时使用“http://”进行AJAX调用,但是包含javascript的html文件是否也通过http提供服务?我的意思是,如果你看你的url,它看起来像“”还是“file://SendRequests.html"? 因为您还需要通过HTTP加载该页面以使其工作。是的,HTML文件包含我的javascript。我的url看起来像: