16 Aug 2018  |  Engineering

How We Updated Our Pricing API

3 minute read

I’m Himangini, an Associate Engineer at Paddle. Having been here for a couple of months I wanted to highlight some of the work I’m been doing on our Pricing API. Let’s look at what was changed in the process.

Our Pricing API

In my first month as an Associate Engineer, I picked up a ticket for improvements on our Pricing API, which we launched last year. However, for those relying mainly on sales and discounts, a problem occured where they couldn’t show the original price using the Pricing API when there were ongoing sales, so we decided to make it better!

This required changing the way the list_price was returned as a response from the API.

A typical pricing API response would look like this:

Request
https://checkout.paddle.com/api/2.0/prices?product_ids=123456&customer_country=GB

Response
{
    "success": true,
    "response": {
        "customer_country": "GB",
        "products": [
            {
                "product_id": 123456,
                "product_title": "My Product 3",
                "currency": "GBP",
                "vendor_set_prices_included_tax": true,
                "price": {
                    "gross": 34.95,
                    "net": 29.13,
                    "tax": 5.83
                },
                "list_price": {
                    "gross": 34.95,
                    "net": 29.13,
                    "tax": 5.83
                },
                "applied_coupon": []
            }
        ]
    }
}

The challenges we encountered

The problem was ocurring when we had a sale applied to the product, as the list_price used to be the same as price with the sale applied. This meant that if our sellers had ongoing sales for their products, they couldn’t show the original price of the product to highlight how much discount their customers were getting.

The solution was simple. Make a change so that list_price returns the original price of the product, if the product had an ongoing sale applied to it.

£100 => £50 [50% discount]

The impact of the API

We rolled out this change making a positive impact for a lot of our sellers, especially those who rely heavily on frequent sales and discounts for their products. Following this change our sellers can how do this on their website using the Pricing API responses, which makes it easier for them to highlight the discounts and attract more buyers and thus make more sales.

Here are some typical responses from Pricing API with various scenarios.

1 : When you have no discount on the product with no active sale applied:

Request : https://checkout.paddle.com/api/2.0/prices?product_ids=123456&customer_country=GB

Response:
{
    "success": true,
    "response": {
        "customer_country": "GB",
        "products": [
            {
                "product_id": 123456,
                "product_title": "My Product",
                "currency": "INR",
                "vendor_set_prices_included_tax": true,
                "price": {
                    "gross": 100,
                    "net": 83.33,
                    "tax": 16.67
                },
                "list_price": {
                    "gross": 100,
                    "net": 83.33,
                    "tax": 16.67
                },
                "applied_coupon": []
            }
        ]
    }
}

2: When you have 20% discount coupon on the product with no active sale applied:

Request : https://checkout.paddle.com/api/2.0/prices?product_ids=123456&customer_country=GB&coupons=PADDLE20
Response: 
{
    "success": true,
    "response": {
        "customer_country": "GB",
        "products": [
            {
                "product_id": 123456,
                "product_title": "My Product",
                "currency": "INR",
                "vendor_set_prices_included_tax": true,
                "price": {
                    "gross": 80,
                    "net": 66.67,
                    "tax": 13.33
                },
                "list_price": {
                    "gross": 100,
                    "net": 83.33,
                    "tax": 16.67
                },
                "applied_coupon": {
                    "code": "PADDLE20",
                    "discount": 20
                }
            }
        ]
    }
}

3: When you have no discount coupon on the product with 20% discount sale applied:

Request : https://checkout.paddle.com/api/2.0/prices?product_ids=123456&customer_country=GB
Response:
{
    "success": true,
    "response": {
        "customer_country": "GB",
        "products": [
            {
                "product_id": 123456,
                "product_title": "My Product",
                "currency": "GBP",
                "vendor_set_prices_included_tax": true,
                "price": {
                    "gross": 405,
                    "net": 337.5,
                    "tax": 67.5
                },
                "list_price": {
                    "gross": 450,
                    "net": 375,
                    "tax": 75
                },
                "applied_coupon": []
            }
        ]
    }
}

4: When you have 15% discount coupon on the product with 10% discount sale applied:

Request : https://checkout.paddle.com/api/2.0/prices?product_ids=123456&customer_country=GB&coupons=PADDLE1  
5
Response: 
{
    "success": true,
    "response": {
        "customer_country": "US",
        "products": [
            {
                "product_id": 123456,
                "product_title": "My Product",
                "currency": "USD",
                "vendor_set_prices_included_tax": true,
                "price": {
                    "gross": 76.5,
                    "net": 76.5,
                    "tax": 0
                },
                "list_price": {
                    "gross": 100,
                    "net": 100,
                    "tax": 0
                },
                "applied_coupon": {
                    "code": "PADDLE15",
                    "discount": 15
                }
            }
        ]
    }
}

What I learned

This was a good first ticket for me to pick-up how a pricing API works. I now know that if we specify multiple coupons in the request (either a percentage or flat or both), the API will calculate the price based on the coupon that gives the highest discount. Sweet!!

Delighting our customers is one of our core values, so I was pretty pleased to improve a service that enhanced our sellers’ checkouts - and looking forward to the next project!