Priceur.js integration


What is Priceur.js?

priceur.js wraps the Priceur API into a lightweight javascript library for easy integration into your website or javascript application.

With priceur.js you can:

  • Fetch localized plans into the client browser.
  • Update landing pages, marketing pages and payment workflow to show localized plans.
  • Integrate localized plans into your javascript application.

Loading

Use the following javascript snippet to load the library:

(function(pr, i, c, e, u, r) {
  pr['PriceurCommand'] = e;
  pr[e] = pr[e] || function() { (pr[e].q = pr[e].q || []).push(arguments) };
  u = i.createElement('script');
  r = i.getElementsByTagName('script')[0];
  u.async = 1;
  u.src = c;
  r.parentNode.insertBefore(u, r);
})(window, document, "//priceur.com/api/v1/priceur.js", 'priceur');

Upon loading, the script registers a global priceur() function that you can use to interact with Priceur. The first argument of the priceur() is the command to execute (see below for the list of commands).

The first command to execute is priceur('init', 'public_test_123EXAMPLE321');.
init fetches the localized plans and store them locally.

Available Commands

Command Arguments Description
fetch
  1. callback function (optional)
Fetches the localized plans from the API and store them in memory.
If a callback is passed, the callback will be called with the plans object as argument.
Example:
  • priceur('fetch',);
  • priceur('fetch', setAllPlansIntoMyApp);
get
  1. plan id (mandatory)
  2. callback function (optional)
Returns the plan curresponding to the given id.
If a callback is passed, the callback will be called with the plan as argument.
Examples:
  • var plan = priceur('get', 'test_plan');
  • priceur('get', 'test_plan', setPlanIntoMyApp);
getAll
  1. callback function (optional)
Returns all plans (as an object with plan IDs as keys).
If a callback is passed, the callback will be called with the plans object as argument.
Examples:
  • var plans = priceur('getAll');
  • priceur('getAll', setAllPlansIntoMyApp);
getAPIKey
  1. callback function (optional)
Returns the Priceur API Key set during init.
If a callback is passed, the callback will be called with the API key as argument.
Examples:
  • var apiKey = priceur('getAPIKey');
  • priceur('getAPIKey', checkAPIKey);
getMeta
  1. meta key (mandatory)
  2. callback function (optional)
Returns the value of the meta information for the given key.
Possible meta keys are:
  • currency_code: the currency of the localized plans.
  • live_mode: whether or not the plans returned are from a live Stripe account (true/false).
If a callback is passed, the callback will be called with the meta value as argument.
Examples:
  • var localCurrency = priceur('getMeta', 'currency_code');
getValue
  1. plan id (mandatory)
  2. key path (optional, defaults to amount.tag)
  3. callback function (optional)
Returns the value of the plan at the given key path.
Possible values for path: see result example in API Documentation.
If a callback is passed, the callback will be called with the value as argument.
Examples:
  • var planPrice = priceur('getValue', 'test_plan');
  • var planCurrency = priceur('getValue', 'test_plan', 'currency.symbol');
  • priceur('getValue', 'test_plan', 'currency.symbol', setCurrencySymbol);
init
  1. Priceur API Key (mandatory)
  2. updatePage (true/false, optional, defaults to false)
  3. document object to update (optional, default to window.document)
Sets the API Key, fetches the localized plans from the API and store them in memory. This command needs to be executed before any other.
If updatePage is set to true, Priceur will update the page with localized plans.
Example:
  • priceur('init', 'public_test_123EXAMPLE321');
  • priceur('init', 'public_test_123EXAMPLE321', true); (also updates page).
update
  1. document object to update (optional, default to window.document)
Update the page with localized plans once fetched (see Landing Page integration section for more informations).
Example:
  • priceur('update');
  • priceur('update', document.getElementById("MyIframe").contentDocument); (if document to update is in an iframe).