付款方式的C#PayPal集成问题

时间:2018-07-22 08:04:12

标签: c# asp.net paypal transactions payment

我目前有一个有效的PayPal结帐系统,但是,一次只能结帐1个项目。当我尝试在我的transactionList中添加多个交易并继续使用付款方式时,出现400错误。

我是否可以同时结帐多个产品?

请帮助!

这是我的代码:

(ConfirmOrder.aspx)

        // scList has 2 values inside.
        List<UserShoppingCartDAO> scList = 
        UserShoppingCartDAO.GetCartOfUser(uID);

        var examPaperItem = new Item();
        for (int i = 0; i < scList.Count; i++)
        {

            Product p = Product.getProduct(scList[i].ProductID.ToString());
            decimal deliveryCharges = p.price * 0.05m;
            string deliveryChargesStr = deliveryCharges.ToString();
            decimal postagePackingCost = 10m;
            decimal examPaperPrice = p.price;
            int quantityOfExamPapers = scList[i].ProductQuantity;
            decimal subtotal = (quantityOfExamPapers * examPaperPrice);
            decimal total = subtotal + postagePackingCost;


            examPaperItem.name = p.productName;
            examPaperItem.currency = "SGD";
            examPaperItem.price = examPaperPrice.ToString();
            examPaperItem.sku = p.productID.ToString();

            examPaperItem.quantity = quantityOfExamPapers.ToString();


            List<Item> itms = new List<Item>();
            itms.Add(examPaperItem);
            ItemList itemList = new ItemList();
            itemList.items = itms;




            var transactionDetails = new Details();
            transactionDetails.tax = "0";
            transactionDetails.shipping = postagePackingCost.ToString();
            transactionDetails.subtotal = subtotal.ToString("0.00");

            var transactionAmount = new Amount();
            transactionAmount.currency = "SGD";
            transactionAmount.total = total.ToString("0.00");
            transactionAmount.details = transactionDetails;


            Transaction tran = new Transaction();
            tran = new Transaction();
            tran.description = "Your order of Past Exam Papers";
            tran.invoice_number = Guid.NewGuid().ToString();
            tran.amount = transactionAmount;

            //    transaction.item_list = new List<Item>();
            tran.item_list = itemList;
            transactionList.Add(tran);



    }

    //Authenticate with paypal
    var config = ConfigManager.Instance.GetProperties();
    var accessToken = new OAuthTokenCredential(config).GetAccessToken();

    //Get APIContent Object
    var apiContext = new APIContext(accessToken);

    var payer = new Payer();
    payer.payment_method = "paypal";

    var redirectUrls = new RedirectUrls();
    redirectUrls.cancel_url = "http://localhost:55099/Cancel.aspx";
    redirectUrls.return_url = "http://localhost:55099/CompletePurchase.aspx"



    var payment = Payment.Create(apiContext, new Payment
    {

        intent = "sale",
        payer = payer,
        transactions = transactionList,
        redirect_urls = redirectUrls

    });

    Session["paymentId"] = payment.id;

    foreach (var link in payment.links)
    {
        if (link.rel.ToLower().Trim().Equals("approval_url"))
        {
            Response.Redirect(link.href);
        }
    }

0 个答案:

没有答案