8

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.

3 Answers 3

18

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()
                                      }
                          });
        }
12
  • I've set TaxTotal, ShippingTotal, ItemTotal, and OrderTotal. These all work except when a discount code is set, as the item + shipping + tax won't add up to the OrderTotal since the OrderTotal has an amount taken off of it. There's nowhere that I can find to set a discount amount. Any ideas? Aug 9, 2011 at 21:30
  • 4
    Are you saying that I need to create an item and set the value to negative? And then update the ItemTotal to reflect all items as well as the negative item that I added to account for the discount? Aug 9, 2011 at 21:40
  • 3
    The PayPal 'Customizing' documentation mentions "You may provide a negative value to reflect a discount on an order, for example." in the description of the Amount field for order details, but nowhere else. @Skomski – I can read, but I missed that info because I didn't think including discounts would be considered 'customizing' PayPal checkout. Also, the documentation for both the SetExpressCheckout and DoExpressCheckoutPayment operations does not include that info in the description of the same field. Jul 19, 2012 at 20:51
  • 1
    @therobyouknow I didn't use a form field for the discount, that would be dangerous #1, and #2 it doesn't need to be on the UI, this is all handled server side. I query my promo code service, determine the discount and then send paypal essentially another product, but it's named promo code with a negative amount. I'll update with code.. Jun 7, 2013 at 21:11
  • 1
    @therobyouknow No problem. I say don't use the form based solution as you originally got the discount server side, sent it to the client, and then the client sent it to you. And because what if they modify the form field? Might as well skip all of that. The code I provided is for a discount on the entire cart but this same logic could be extended to do a discount per item by just adding more discount items. Jun 8, 2013 at 20:08
1

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.

0

Add the discount value to the PAYMENTREQUEST_0_ITEMAMT parameter and it will works fine.

In other words, if you consider your discount as a product, passing it through L_PAYMENTREQUEST_0_NAME(i), L_PAYMENTREQUEST_0_AMT(i) and L_PAYMENTREQUEST_0_QTY(i), then you have to sum the discount value to the products value and pass the result into the PAYMENTREQUEST_0_ITEMAMT param.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.