This content originally appeared on DEV Community and was authored by Waruna
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'
and run bundle
bundle install
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
That pretty much it for now. If you like this project or find it useful don't forget to give a star on github.
This content originally appeared on DEV Community and was authored by Waruna

Waruna | Sciencx (2025-01-10T18:12:29+00:00) Ruby on Rails – Calculating pricing based user’s purchasing power parity. Retrieved from https://www.scien.cx/2025/01/10/ruby-on-rails-calculating-pricing-based-users-purchasing-power-parity/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.