c# - Asp MVC Paypal 交易

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

我正在尝试制作一个 paypal 处理程序。你在输入中输入金额,然后按下捐赠按钮,你将被转发到 Paypal 页面,你可以登录然后按下继续按钮......按下继续按钮后的问题将我转发回 https://www.example.org/Account/PayPalHandler/页,仅此而已。我的代码缺少什么来完成 Paypal 交易?

[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 };
        }

最佳答案

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

链接显示完整流程

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

高度

关于c# - Asp MVC Paypal 交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42175221/

相关文章:

java - 将 'bits' 写入 C++ 文件流

c# - 如何设置PDF边距?

javascript - 为什么我的 MVC Controller 上的数组在 Ajax 回传上为空

c# - Reactive Extension 中的数据服务

c# - 如何将一个not_analyzed字段添加到Elasticsearch中

javascript - AngularJS 将数据发布到 ASP.NET WebForms

c# - 将枚举的内容获取到下拉列表

asp.net - 使用ASP.NET MVC阻止ZmEu攻击

c# - 实体代码优先迁移和删除数据库

c# - RedirectToAction 没有结束响应参数。结果抛出 'Thread was being aborted"异常