Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Dynamic Stripe Pricing Tables</h1>
<h2> My proof of concept: Load pricing tables dynamically based on the country of origin of the visitor, with Stripe</h2>
              
            
!

CSS

              
                body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Helvetica Neue", Arial, sans-serif;
}

              
            
!

JS

              
                let tablePrices = async () => {
  const options = {
    method: "GET",
    headers: {
      // Yup this is my API Key, please don't abuse it, it's capped at $1 a year - hope the cap works haha.
      "X-RapidAPI-Key": "759abd0b40mshcb4187678afa953p1251a4jsn1ae9f5f9bedd",
      "X-RapidAPI-Host": "ip-geo-location.p.rapidapi.com"
    }
  };

  let continents = {
    //Here you can add more currencies, and the ID of the pricing table to load
    USD: "prctbl_1L6RzqIoFS43TaCmAA8AsvdR",
    EUR: "prctbl_1LAizDIoFS43TaCmlCkDEkvd",
    RUB: "prctbl_1LAizDIoFS43TaCmlCkDEkvd"
  };

  // I fetch this endpoint which returns information about the visitor's IP
  let result = await fetch(
    "https://ip-geo-location.p.rapidapi.com/ip/check?format=json",
    options
  )
    .then((response) => response.json())
    // You can change the pricing table after the OR (||) to default to a specific pricing table in case you don't support the currency
    .then(
      (response) =>
        continents[response.currency.code] || "prctbl_1LAizDIoFS43TaCmlCkDEkvd"
    )
    .catch((err) => console.error("Err", err));

  return result;
};

async function loadjs() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.async = true;
  script.src = "https://js.stripe.com/v3/pricing-table-outer.js";
  script.dataset["id"] = await tablePrices();
  script.dataset["pk"] =
    "pk_test_51IvQ97IoFS43TaCmnBqIdTvOwzApYcQUQAAS77mbL7lOGnQb8MSmzD8SyXr53jPi5wSg5zp8b8GB7qC6fJky7AFY00YfEt2aFy";
  document.body.appendChild(script);
}

window.onload = (event) => {
  loadjs();
};

              
            
!
999px

Console