@lorensr/ppp

    0.0.2 • Public • Published

    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.

    Install

    npm i @lorensr/ppp

    DownloadsWeekly Downloads

    5

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    8.13 kB

    Total Files

    6

    Last publish

    Collaborators

    • lorensr