Quickstart Guide
Accept a payment
This guide shows you how to integrate Kopo Pay to accept payments on your website. We'll use a server-side SDK to create a Payment Intent and Kopo.js to handle the frontend flow.
1
Install the SDK
First, add the Kopo Pay library to your project using your preferred package manager.
npm install @kopopay/kopopay-node2
Initialize the client
Use your secret API key to initialize the Kopo Pay client. Never share this key on the client-side.
const kopopay = require('kopopay')('sk_test_...');
// Or using ES modules
import KopoPay from 'kopopay';
const kopopay = new KopoPay('sk_test_...');3
Create a Payment Intent
Create a PaymentIntent on your server to track a payment. This returns a client_secret.
const paymentIntent = await kopopay.paymentIntents.create({
amount: 2000,
currency: 'usd',
automatic_payment_methods: { enabled: true },
});
const clientSecret = paymentIntent.client_secret;4
Confirm on the client
Use Kopo.js on your frontend to collect payment details and confirm the payment.
const { error } = await kopopay.confirmPayment({
elements,
confirmParams: {
return_url: 'https://example.com/order/123/complete',
},
});Security Note
Always use your **Secret Key** (`sk_test_...`) on your server and your **Publishable Key** (`pk_test_...`) on your client. Never expose your secret key in your frontend code or public repositories.