Skip to Content
Docs

Install and initialize

Install Pay.com.js via npm or CDN and initialize it with your merchant ID.

Install Pay.com.js and initialize it with your merchant ID before rendering Universal checkout, Headless checkout, or secure card fields.

Before you begin, retrieve these credentials from the Developers tab of the Pay.com dashboard:

  • API key: Used on your server to create sessions. Never expose it in browser code.
  • Merchant ID: Passed to Pay.com({ identifier }) in the browser.

Set up Pay.com.js

Install the package or load the script, then initialize it with your merchant ID.

  1. 1

    Install Pay.com.js

    Install @pay-com/js with npm or yarn, or load it from the CDN. Both provide the full SDK.

    Install the package with npm or yarn:

    npm install --save @pay-com/js
    # or
    yarn add @pay-com/js

    Import Pay.com.js in your module:

    import Pay from '@pay-com/js'

    The package includes TypeScript definitions, so you can import types directly from @pay-com/js without a separate @types package:

    import type { UniversalOpts } from '@pay-com/js'
    
    const style: UniversalOpts['style'] = {
      base: { fontFamily: "'Inter', sans-serif" }
    }

    UniversalOpts is the type of the options object you pass to checkout.universal(). Typing your style overrides as UniversalOpts['style'] gives you editor autocomplete before you pass them to checkout.universal(). See Customize the checkout for usage.

  2. 2

    Initialize Pay.com.js

    Initialize Pay.com.js with your merchant ID (identifier) to obtain a pay instance. The payment session is attached later via clientSecret in pay.checkout().

    With @pay-com/js, Pay.com() returns a promise and defaults to the sandbox. Pass live: true in live.

    import Pay from '@pay-com/js'
    
    const pay = await Pay.com({
      identifier: 'YOUR_MERCHANT_ID',
      // live: true, // Uncomment for live payments
    })

    With the npm package, match live to your sessions. Pass live: true with sessions you create on https://api.pay.com/v1, and leave it out with sessions you create on https://api.sandbox.pay.com/v1.

SDK architecture

Pay.com.js is organized around three objects (the top-level Pay module, a pay instance returned by Pay.com(), and a checkout instance returned by pay.checkout()).

Choose your integration mode

Continue with the guide for your checkout architecture:

Was this page helpful?