PlexySDK DOCS

Node.js SDK

Integrate Plexy with Node.js and TypeScript applications

Node.js SDK

The official Plexy server-side SDK for Node.js and TypeScript.

Server-side SDKs are still in development and not yet available. For now, integrate by calling the Plexy REST API directly over HTTPS.

Installation

npm install @plexy/plexy-web
# or
pnpm add @plexy/plexy-web
# or
yarn add @plexy/plexy-web

Quick Start

import { Plexy } from '@plexy/plexy-web';

const plexy = new Plexy({
  apiKey: process.env.PLEXY_SECRET_KEY,
});

// Create a payment
const payment = await plexy.payments.create({
  amount: 10000,
  currency: 'KZT',
  description: 'Order #12345',
});

Configuration Options

const plexy = new Plexy({
  apiKey: process.env.PLEXY_SECRET_KEY,
  // Optional configuration
  baseUrl: 'https://api.plexy.money', // Custom API URL
  timeout: 30000, // Request timeout in ms
  maxRetries: 3, // Auto-retry failed requests
});

Payments

Create a Payment

const payment = await plexy.payments.create({
  amount: 10000,
  currency: 'KZT',
  description: 'Order #12345',
  metadata: {
    orderId: '12345',
    customerId: 'cust_abc123',
  },
  returnUrl: 'https://yoursite.com/success',
  cancelUrl: 'https://yoursite.com/cancel',
});

Retrieve a Payment

const payment = await plexy.payments.retrieve('pay_abc123');

List Payments

const payments = await plexy.payments.list({
  limit: 10,
  status: 'completed',
});

// Iterate over all payments
for await (const payment of plexy.payments.list()) {
  console.log(payment.id);
}

Webhooks

Verify Webhook Signature

import { Plexy } from '@plexy/plexy-web';

const event = Plexy.webhooks.constructEvent(
  rawBody,
  signature,
  process.env.PLEXY_WEBHOOK_SECRET,
);

switch (event.type) {
  case 'payment.completed':
    const payment = event.data;
    // Handle successful payment
    break;
  case 'payment.failed':
    // Handle failed payment
    break;
}

Error Handling

import { Plexy, PlexyError } from '@plexy/plexy-web';

try {
  const payment = await plexy.payments.create({ ... });
} catch (error) {
  if (error instanceof PlexyError) {
    console.error('API Error:', error.message);
    console.error('Error Code:', error.code);
    console.error('Status:', error.status);
  }
}

TypeScript Support

The SDK includes full TypeScript definitions:

import type { Payment, PaymentCreateParams } from '@plexy/plexy-web';

const params: PaymentCreateParams = {
  amount: 10000,
  currency: 'KZT',
};

const payment: Payment = await plexy.payments.create(params);

On this page