@lorensr/ppp
v0.0.2
Published
Purchasing power parity—sell products at comparable prices around the world 🌎🌍🌏
Downloads
3
Maintainers
Readme
Background: Purchasing power parity
npm install @lorensr/ppp
If we had a product that cost $50 USD in the United States, and we had a customer in India, then we would charge them 26.5% of the full cost—$13.27 USD:
import getPpp from '@lorensr/ppp'
const originalPrice = 50;
const countryCode = 'IN'
getPpp(countryCode).then(ppp => {
const discountPrice = ppp.pppConversionFactor * originalPrice
console.log(discountPrice)
console.log(ppp)
});
13.2690310135
{ currenciesCountry: [ { code: 'INR', name: 'Indian rupee', symbol: '₹' } ],
countryCodeIsoAlpha3: 'IND',
currencyMain:
{ exchangeRate: 67.39,
code: 'INR',
name: 'Indian rupee',
symbol: '₹' },
ppp: 17.884,
pppConversionFactor: 0.26538062027006976 }
We recommend running this code on the server, as deciding pricing on the client is insecure. To determine the client's location, you can use their IP address and a geolocation API like ipstack, or if you use Cloudflare, you use their CF_IPCOUNTRY
HTTP header, which contains the client's country code. The latter method is less able to be tricked by proxies and VPNs.