Skip to content

JavaScript SDK Installation

Install the GoPayLocal JavaScript SDK for vanilla JS, Vue, Svelte, and other frameworks.

The JavaScript SDK provides an imperative API for adding PPP discounts to any JavaScript application — vanilla JS, Vue, Svelte, WordPress, or any framework.

Terminal window
npm install @gopaylocal/js
  1. Create a client instance

    import { GoPayLocal } from '@gopaylocal/js';
    const gpl = new GoPayLocal({
    apiKey: 'gpl_pk_live_abc123',
    });
  2. Initialize and fetch PPP data

    const data = await gpl.init();
    if (data?.show) {
    console.log(`${data.countryName}: ${data.discount}% off`);
    console.log(`Coupon: ${data.code}`);
    }
  3. Get localized prices

    const pricing = gpl.getPrice(99.99);
    console.log(pricing.formatted); // "₹4,999"
    console.log(pricing.formattedOriginal); // "$99.99"
    console.log(pricing.hasDiscount); // true
const gpl = new GoPayLocal({
// Required
apiKey: 'gpl_pk_live_abc123',
// Optional
apiBase: 'https://api.gopaylocal.com', // Custom API URL
environment: 'production', // 'production' | 'sandbox'
baseCurrencyCode: 'USD', // Your base currency
baseCurrencySymbol: '$', // Your base currency symbol
cacheTtl: 5 * 60 * 1000, // Cache TTL in ms (default: 5 min)
// Callbacks
onLoad: (data) => console.log('Loaded:', data),
onError: (error) => console.error('Error:', error),
});
OptionTypeDefaultDescription
apiKeystring(required)Public API key (starts with gpl_pk_)
apiBasestring'https://api.gopaylocal.com'API base URL
environment'production' | 'sandbox''production'Target environment
baseCurrencyCodestring'USD'Base currency code
baseCurrencySymbolstring'$'Base currency symbol
cacheTtlnumber300000 (5 min)Cache TTL in milliseconds
onLoad(data: PPPData) => voidCalled when data loads
onError(error: Error) => voidCalled on error
import { GoPayLocal, formatCurrency, countryToFlag, splitPrice } from '@gopaylocal/js';
ExportDescription
GoPayLocalMain SDK class
formatCurrencyFormat a number as currency
countryToFlagConvert country code to flag emoji
splitPriceSplit formatted price into integer/decimal parts

Full type definitions are included:

import type { GoPayLocalConfig, PPPData, PricingResult, BannerOptions } from '@gopaylocal/js';
Banner ScriptJavaScript SDK
SetupOne <script> tagnpm install + code
ControlDashboard onlyFull programmatic control
Custom UINoYes — build any UI
Data accessNoFull access to PPP data
FrameworkAny (HTML)Any (JS runtime)
Best forQuick setupCustom pricing displays