DEV Community

Waruna
Waruna

Posted on

Ruby on Rails - Calculating pricing based user's purchasing power parity

Recently, I published a simple ruby gem for calculating pricing for digital products based on the user's purchasing power parity.

Not everyone can afford the default pricing of the high-income world. A cup of Coffee in India or Argentina costs less than in the USA or Singapore. Therefore, I wanted to apply the same principle to a digital product I'm building. I couldn't find an easy way to calculate this with Ruby. Looking around, I got inspired by an NPM package called purchasing-power-parity npm and created a similar library using Ruby.

If you would like to take a look at the source code or would like to contribute here in the link to Github repo.

https://github.com/warunacds/geo_ppp

Library is pretty simple to use. Add this line to your application's Gemfile like any other library

gem 'geo_ppp'
Enter fullscreen mode Exit fullscreen mode

and run bundle

bundle install
Enter fullscreen mode Exit fullscreen mode

now you can call it anywhere you like and it would look like this.

def index
  original_price = 79.99

  begin
    response = GeoPPPFetcher.fetch
     discounted_price = original_price * response['pppConversionFactor']
     data = { original_price: original_price, discounted_price: discounted_price }
     render json: { success: true, data: data }
  rescue StandardError => e
    render json: { success: false, error: e.message }, status: :unprocessable_entity
  end
end
Enter fullscreen mode Exit fullscreen mode

That pretty much it for now. If you like this project or find it useful don't forget to give a star on github.

Retry later

Top comments (1)

Collapse
 
sulmanweb profile image
Sulman Baig

Added an issue. Good work 👍
github.com/warunacds/geo_ppp/issues/1

Retry later
Retry later