Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal Express Checkout: Apply order discount

Tags:

c#

paypal

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.

like image 452
StephenPAdams Avatar asked Aug 09 '11 21:08

StephenPAdams


2 Answers

Another option for sending a discount via the PayPal API use the PAYMENTREQUEST_n_SHIPDISCAMT

Which is actually a shipping discount, but works just fine, and is a one line.

But it does say shipping discount at the PalPal end.

like image 24
TheAlbear Avatar answered Oct 06 '22 20:10

TheAlbear


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()
                                      }
                          });
        }
like image 164
Skomski Avatar answered Oct 06 '22 18:10

Skomski