npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@paykit-sdk/gopay

v1.1.1

Published

GoPay provider for PayKit

Readme

@paykit-sdk/gopay

GoPay provider for PayKit

Quick Start

import { createEndpointHandlers, PayKit } from '@paykit-sdk/core';
import { gopay, createGopay } from '@paykit-sdk/gopay';

// Method 1: Using environment variables
const provider = gopay(); // Ensure required environment variables are set

// Method 2: Direct configuration
const provider = createGopay({
  clientId: process.env.GOPAY_CLIENT_ID,
  clientSecret: process.env.GOPAY_CLIENT_SECRET,
  goId: process.env.GOPAY_GO_ID,
  isSandbox: true,
  webhookUrl: 'https://your-domain.com/api/paykit/webhooks',
  debug: true, // Enable to see helpful logs about provider_metadata
});

export const paykit = new PayKit(provider);
export const endpoints = createEndpointHandlers(paykit);

Next.js Catch All API Route (/api/paykit/[...endpoint]/route.ts)

import { endpoints } from '@/lib/paykit';
import { EndpointPath } from '@paykit-sdk/core';
import { NextRequest, NextResponse } from 'next/server';

export async function POST(
  request: NextRequest,
  { params }: { params: Promise<{ endpoint: string[] }> },
) {
  try {
    const { endpoint: endpointArray } = await params;
    // Construct the endpoint path with full type safety
    const endpoint = ('/' + endpointArray.join('/')) as EndpointPath;
    const handler = endpoints[endpoint];

    if (!handler) {
      return NextResponse.json({ message: 'Endpoint not found' }, { status: 404 });
    }

    // Parse request body
    const body = await request.json();
    const { args } = body;

    const result = await handler(...args);

    return NextResponse.json({ result });
  } catch (error) {
    console.error('PayKit API Error:', error);
    return NextResponse.json(
      { message: error instanceof Error ? error.message : 'Internal server error' },
      { status: 500 },
    );
  }
}

Next.js Webhooks (/api/paykit/webhooks/route.ts)

⚠️ IMPORTANT: GoPay webhooks use GET requests instead of POST. Your webhook route must export a GET handler, not POST.

import { paykit } from '@/lib/paykit';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
  const webhook = paykit.webhooks
    .setup({ webhookSecret: '' }) // GoPay doesn't use webhook secrets
    .on('customer.created', async event => {
      console.log('Customer created:', event.data);
    })
    .on('subscription.created', async event => {
      console.log('Subscription created:', event.data);
    })
    .on('payment.created', async event => {
      console.log('Payment created:', event.data);
    })
    .on('refund.created', async event => {
      console.log('Refund created:', event.data);
    })
    .on('invoice.generated', async event => {
      console.log('Invoice generated:', event.data);
    });

  const headers = request.headers;
  const url = request.url;

  try {
    console.log('Webhook handled');
    await webhook.handle({ body: '', headers, fullUrl: url });
    return NextResponse.json({ success: true });
  } catch (error) {
    console.error('Webhook error:', error);
    return NextResponse.json({ success: false }, { status: 500 });
  }
}

Express.js with Webhook Handler

import { paykit, endpoints } from '@/lib/paykit';
import { EndpointPath } from '@paykit-sdk/core';
import express from 'express';

const app = express();

// IMPORTANT: GoPay webhooks use GET requests, not POST
app.get('/api/webhooks/gopay', async (req, res) => {
  try {
    const webhook = paykit.webhooks
      .setup({ webhookSecret: '' }) // GoPay doesn't use webhook secrets
      .on('customer.created', async event => {
        console.log('Customer created:', event.data);
      })
      .on('subscription.created', async event => {
        console.log('Subscription created:', event.data);
      })
      .on('payment.created', async event => {
        console.log('Payment created:', event.data);
      })
      .on('refund.created', async event => {
        console.log('Refund created:', event.data);
      })
      .on('invoice.generated', async event => {
        console.log('Invoice generated:', event.data);
      });

    const body = ''; // GoPay sends data via URL query params
    const headers = req.headers;
    const url = req.url;
    await webhook.handle({ body, headers, fullUrl: url });

    // Return immediately, processing happens in background
    res.json({ success: true });
  } catch (error) {
    console.error('Webhook error:', error);
    res.status(500).json({
      message: error instanceof Error ? error.message : 'Webhook processing failed',
    });
  }
});

// Regular API routes use JSON middleware
app.use(express.json());

app.post('/api/paykit/*', async (req, res) => {
  try {
    const endpoint = req.path.replace('/api/paykit', '') as EndpointPath;
    const handler = endpoints[endpoint];

    if (!handler) {
      return res.status(404).json({ message: 'Endpoint not found' });
    }

    const { args } = req.body;
    const result = await handler(...args);

    res.json({ result });
  } catch (error) {
    res.status(500).json({
      message: error instanceof Error ? error.message : 'Internal server error',
    });
  }
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Subscription Management

// Cancel subscription
await paykit.subscriptions.cancel('sub_123');

Provider Metadata

GoPay requires specific provider_metadata fields for different operations. Enable debug: true when initializing the provider to see helpful console logs that recommend which fields to use.

const checkout = await paykit.checkouts.create({
  customer: { email: '[email protected]' },
  item_id: 'item_123',
  session_type: 'one_time',
  quantity: 1,
  metadata: { plan: 'pro' },
  success_url: 'http://localhost:3000/success',
  cancel_url: 'http://localhost:3000/cancel',
  provider_metadata: {
    amount: '2900',
    currency: 'CZK',
    lang: 'en', // Language for the payment gateway (default: 'EN')
  },
});

Environment Variables

GOPAY_CLIENT_ID=140...
GOPAY_CLIENT_SECRET=n6W...
GOPAY_GO_ID=864....
GOPAY_SANDBOX=true
GOPAY_WEBHOOK_URL=https://your-domain.com/api/paykit/webhooks

Documentation

For detailed documentation, including setup guides, webhook configuration, and provider metadata requirements, see the GoPay Provider Documentation.

Support

License

ISC