Skip to main content

Payments

After createPayment, send the shopper to gw_url. Treat notification and return callbacks as hints — always confirm status with getPayment on the server.
This page covers core payment creation and retrieval operations.

Create payment

import { Currency, createGoPayClient } from 'gopay-sdk';

const client = createGoPayClient({
  goid: 8123456789,
  clientId: process.env.GOPAY_CLIENT_ID!,
  clientSecret: process.env.GOPAY_CLIENT_SECRET!,
  gatewayUrl: 'https://gw.sandbox.gopay.com/api',
});

const payment = await client.createPayment({
  amount: 15900,
  currency: Currency.CZK,
  order_number: 'ORDER-15900',
  order_description: 'Premium subscription',
  payer: {
    contact: {
      email: 'buyer@example.com',
      first_name: 'John',
      last_name: 'Doe',
    },
  },
  callback: {
    return_url: 'https://example.com/payment/return',
    notification_url: 'https://example.com/payment/notify',
  },
});

Automatic defaults

If omitted, the SDK injects:
  • target: { type: 'ACCOUNT', goid: <configured-goid> }
  • lang: <configured-language>

Query payment details

const details = await client.getPayment(payment.id!);

console.log({
  id: details.id,
  state: details.state,
  subState: details.sub_state,
  amount: details.amount,
  currency: details.currency,
});

Card details and card deletion

const card = await client.getCardDetails(123456);
console.log(card.status, card.card_brand, card.card_expiration);

await client.deleteCard(123456);

Embed.js helper

To embed GoPay UI assets with the same gateway environment:
const embedJsUrl = client.getEmbedJsUrl();
// https://gw.sandbox.gopay.com/gp-gw/js/embed.js

Types used

From gopay-sdk exports:
  • CreatePaymentRequest
  • PaymentResponse
  • CardDetailsResponse
  • Currency, Language, PaymentInstrument, and other enums