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

Viewed 10018

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?

4 Answers

Make negative value of coupon discount amount. It worked for me.

$itemArray = array();

    if (isset($request->couponId)) {

        // coupon object
        $coupon = (new Promocodes())->check($request->couponId);
    
        if (isset($coupon->code)) {
           $item = new Item();
           $item->setName('Coupon Discount')
                ->setCurrency('GBP')
                ->setQuantity(1)
                ->setPrice(($coupon->reward * (-1)));
    
           // to reduce reward amount from total
           $totalAmount -= $coupon->reward;
           array_push($itemArray, $item);
        }
    }
Related