I've been unable to find an accurate answer for this.
As we know already, PayPal's REST API doesn't have a option for applying discount code. However, we can append another item to the item_list with a description of a I.e. Promo / Discount code.
So e.g. breaking this into human readable data, here's what I'm passing to the API.
Transaction
Amount: 100
item_list: [ product1, 60 ], [ product2, 60 ], [ coupon_code, -20 ]
Visually, This route should work (as it does in the classic API). However, the PayPal API doesn't allow negative numbers.
Ideally, we want to use the signed / OAuth route via PayPal REST API Vs. the open / classic API.
Update 1/13/2014 I noticed Storenvy has the ability to apply discounts to their connected user's PayPal accounts. However, If I recall Storenvy has a partnership with PayPal - I'm wondering if they're on a specific internal rest API version for the discount support?
What worked for me:
Add a discount
field to the breakdown
:
'discount' => [
'currency_code' => $order->currency,
'value' => $order->coupon_total,
]
See PayPal's docs: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
The discount will the show up as discount in the price breakdown.
I do it creating another item, and giving a negative price.
$item = new Item();
$price = -11.20;
......
$item->setName($name)
->setCurrency($currency)
->setQuantity($quantity)
->setSku($sku)
->setPrice($price);
For this example I have a Promo code of -11.20 euro:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With