Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

c# - Paypal Express Checkout: Apply order discount

Have an ecommerce site running ZNode. We send tax, shipping, order total, etc. Everything works fine until an order level discount is applied (say 50%). We get a response from PayPal that says the following:

The totals of the cart item amounts do not match order amounts.

I'm traversing the API, and I can't find anything to apply an order level discount. FWIW, the user is applying discount codes on our site, and then is being transferred to PayPal.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think your problem is not the PayPal API. You checked that everything works perfect with your parameters passed to paypal in this 50% discount case?

After the PayPal Documentation you should provide a negative value to reflect a discount on an order. So everything adds up to the total amount.

Source: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing

enter image description here

Update with code: (by Nick)

I have a paypal service that does all kinds of stuff, but the following code should give you an idea of how the discount works. The discount is not a special type, it's a product just like any other except it's disguised by naming it like a discount and setting it's price to a negative number.

            List<PaymentDetailsItemType> items = paymentDetails.PaymentDetailsItem;

        foreach (ShoppingCartItem item in cart.ShoppingCartItems)
        {
            items.Add(new PaymentDetailsItemType
                          {
                              Name = item.Book.Title,
                              Quantity = item.Quantity,
                              Number = item.BookId.ToString(),
                              Amount =
                                  new BasicAmountType
                                      {currencyID = CurrencyCodeType.USD, 
                                       value = (item.Book.Price).To2Places()}
                          });
        }
        if (cartTotals.Discount > 0)
        {
            items.Add(new PaymentDetailsItemType
                          {
                              Name = "Promo Code Discount",
                              Quantity = 1,
                              Number = "PromoCode",
                              Amount =
                                  new BasicAmountType
                                      {
                                          currencyID = CurrencyCodeType.USD,
                                          value = (cartTotals.Discount*-1).To2Places()
                                      }
                          });
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...