12

I'm currently posting a regular transaction to Paypal Express and am reaching the gateway without error.

I would like to now configure my cart to send a discount to the gateway. My first thought was to modify the 'AMT' value that is sent to the gateway. However, it seems that Paypal validates the 'AMT' field by calculating the total of the ITEMAMT, TAXAMT and SHIPPINGAMT fields to ensure the total is unchanged:

[L_AMT0] => 49.99
[L_NUMBER0] => 3706{3}8
[L_QTY0] => 1
[L_TAXAMT0] => 0.00
[ITEMAMT] => 49.99
[TAXAMT] => 0
[SHIPPINGAMT] => 14.95
[AMT] => 64.94

How many I send a discount to Paypal? I have looked through what documentation I can find, with no luck; the similar questions here on SO were no help, either. Thanks.

Edit: I've noticed I can pass through the field SHIPDISCAMT. I don't know if this will let me do what I need it to though - I am still getting errors that indicate soemthing is 'mismatched'.

pb149
  • 2,298
  • 1
  • 22
  • 30
  • Could you not pre-calculate the discount and factor that into your PayPal variables? – Josh Mar 14 '12 at 21:01
  • @Josh How could I do that? PayPal will recalculate the 'total' by looking at the individual L_* elements; if its calculation does not match the 'AMT' field that I would have emended then it will return a gateway error. I did think of modifying each individual `L_AMT*` to take a portion of the discount value off of each, but that seems like a terrible solution. Are you able to offer a more in-depth reply? (Thanks for the post.) – pb149 Mar 14 '12 at 21:11
  • @Josh Answered my own question. Nonetheless, thanks for your help! – pb149 Mar 14 '12 at 21:40

3 Answers3

23

Got it.

It turns out that you can pass a negative amount through as a line item and label it as a discount yourself. I had to add the above code:

$params['L_NAME1'] = 'Discount Coupon';
$params['L_AMT1'] = -$discountCodeAmount;
$params['L_QTY1'] = 1;
$params['ITEMAMT'] -= $discountCodeAmount;
$params['AMT'] -= $discountCodeAmount;

This had the following effect:

enter image description here

I found my answer in this PDF:

https://cms.paypal.com/cms_content/CA/en_US/files/developer/PP_ExpressCheckout_IntegrationGuide.pdf

For some reason, that information was not given in several other official PayPal express articles/documents I had read.

pb149
  • 2,298
  • 1
  • 22
  • 30
  • I couldn't find it either, although it was documented for other PayPal solutions. Great find. – Josh Mar 14 '12 at 21:42
0

I've used the negative price line item technique to achieve the discount, but have faced with a problem - if a discount value is equal to product price, e.g. line items like:

[L_NAME0] => Product #1
[L_COST0] => 18.99
[L_QTY0] => 1
[L_NAME1] => Discount
[L_COST1] => -18.99
[L_QTY1] => 1
[ITEMAMT] => 0.00
[FREIGHTAMT] => 15.00
[HANDLINGAMT] => 0.00

Then it produces the PayPal error "Field format error: 10431-Item amount is invalid.".

However, removing the discount product and sending instead of it "DISCOUNT" field fixed this issue and gave new one :-) PayPal always shows this field as "Shipping discount", while it is actually item discount. At least, it works...

random
  • 1
0

Please refer this Paypal URL HTML Variable List

<input type="hidden" name="discount_amount_cart" id="discount_amount_cart"  value="3.00">

You can send Cart wide Discount (discount_amount_cart), Product wide Discount (discount_amount) using this parameters. You can find more in provide link. Make sure to pass Positive Integer value. PayPal Does not accept Negative Value.

Milan Malani
  • 1,818
  • 1
  • 22
  • 34