Skip to main content

Prerequisites

  • A Grain merchant account with a Merchant ID
  • A server-side API key for creating payment sessions
  • Node.js 18+ (for Next.js applications)

Get Your Credentials

1

Get your Merchant ID

Log in to the Grain Dashboard and navigate to Settings > API Keys. Copy your Merchant ID — this is used to initialize the client-side SDK.
2

Get your API key

From the same page, copy your API Key. This is your server-side secret used to create payment sessions.
Never expose your API key in client-side code. It should only be used in server-side route handlers or backend services.

Configure Environment Variables

Add the following to your .env file:

Add the SDK Mount Point

The Payment SDK renders its payment modal inside a dedicated DOM element. Add this to your root layout:
The SDK creates a Shadow DOM inside this element, so its styles are fully isolated from your application. No CSS conflicts.

Load the SDK Bundle

The client-side SDK is distributed as a UMD bundle. Place it in your public directory:
The SDK service loads this script lazily on first use — no manual script tags needed.

Environment Comparison

Next Steps

Proceed to Initialize the SDK to set up the SDK service and process your first payment.