簡體   English   中英

ASP MVC PayPal交易

[英]Asp MVC PayPal Transaction

我試圖做一個貝寶處理程序。 您在輸入中輸入金額,然后按“捐贈”按鈕,您將被轉發到貝寶頁面,您可以登錄,然后按“繼續”按鈕...按“繼續”按鈕后的問題將其轉發回https ://www.example.org/Account/PayPalHandler/頁面,僅此而已。 完成我的貝寶交易的代碼中缺少什么?

[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付款

鏈接顯示完整流程

  • Create付款(這是您上面的代碼所映射的內容)-在此步驟中,您將獲得payment id
  • 使用您收到的id將用戶重定向到Paypal approval_url網址(在上面Create中的詳細信息)以進行批准
  • 貝寶將用戶返回到您的網站,並提供有關如何Execute付款的信息(如果用戶批准)
  • Execute付款(在您的網站/應用上完成)

高度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM