【问题标题】:Asp MVC PayPal TransactionAsp MVC 贝宝交易
【发布时间】:2017-06-29 17:40:35
【问题描述】:

我正在尝试制作一个贝宝处理程序。您在输入中输入金额,然后按捐赠按钮,您将被转发到贝宝页面,您可以登录,然后按继续按钮...按继续按钮后的问题将我转发回@ 987654321@ 页,仅此而已。我的代码中缺少什么来完成贝宝交易?

[HttpPost]
        public ActionResult DoPaymentPaypall(UserModel User_)
        {
            ResultModel<ManageAccountListModel> res_ = new ResultModel<ManageAccountListModel>();
            res_.DataSelect = new ManageAccountListModel();

            if (SessionManagement.LoginnedUser != null)
            {
                var config = ConfigManager.Instance.GetProperties();
                var accessToken = new OAuthTokenCredential(config).GetAccessToken();
                var apiContext = new APIContext(accessToken);
                string moneyCount_ = User_.moneycount.ToString();
                var payment = Payment.Create(apiContext, new Payment
                {
                    intent = "sale",
                    payer = new Payer
                    {
                        payment_method = "paypal"
                    },
                    transactions = new List<Transaction>
                                    {
                                        new Transaction
                                        {
                                            description = "Donation",
                                            invoice_number = "001",
                                            amount = new Amount
                                            {
                                                currency = "USD",
                                                total = moneyCount_,
                                                details = new Details
                                                {
                                                    tax = "0",
                                                    shipping = "0",
                                                    subtotal = moneyCount_
                                                }
                                            },
                                            item_list = new ItemList
                                            {
                                                items = new List<Item>
                                                {
                                                    new Item
                                                    {
                                                        name = "Donation",
                                                        currency = "USD",
                                                        price = moneyCount_,
                                                        quantity = "1",
                                                        sku = "Custom Package"
                                                    }
                                                }
                                            }
                                        }
                                    },
                    redirect_urls = new RedirectUrls
                    {
                        return_url = "https://www.example.org/Account/PayPalHandler/",
                        cancel_url = "https://www.example.org/"
                    }
                });

                res_.SuccessMessage = payment.links.ToList()[1].href;

            }
            res_.Success = true;
            return new JsonResult { Data = res_, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

【问题讨论】:

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


    【解决方案1】:

    您上面的代码似乎只显示了流程的初始/开始...所以假设您的意思是在用户批准您的之后请求 使用 Paypal 付款(不要将此混淆为“付款” - 此步骤仅表示用户同意使用 Paypal 付款)您需要Execute the payment。

    链接显示完整流程

    • Create 付款(这是您上面的代码所映射的内容)- 在此步骤中您将获得 payment id
    • 使用您收到的id 将用户重定向到 Paypal approval_url 以获得批准(上面Create 中的详细信息)
    • Paypal 将用户发送回您的网站,并提供有关如何Execute 付款的信息(如果用户批准)
    • Execute 付款(在您的网站/应用中完成)

    第

    【讨论】:

    • 我已经成功了,我刚刚再次阅读了贝宝文档.. :) 不过还是谢谢!
    猜你喜欢
    • 2012-08-31
    • 2015-10-13
    • 1970-01-01
    • 2015-08-11
    • 2014-03-16
    • 2013-07-11
    • 1970-01-01
    • 2014-07-25
    • 2015-12-30
    相关资源
    最近更新 更多