Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal REST API - Coupon / Discount Code (Negative Numbers)

Tags:

paypal

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?

like image 611
MKN Web Solutions Avatar asked Dec 20 '13 19:12

MKN Web Solutions


2 Answers

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.

like image 170
yiddishe-kop Avatar answered Oct 06 '22 08:10

yiddishe-kop


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:

promo code

like image 6
soipo Avatar answered Oct 06 '22 09:10

soipo