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

sadad-payment-client

v1.1.3

Published

Node.js client library for Sadad Payment API - payment orders management

Downloads

505

Readme

Sadad Payment Client

A Node.js client library for the Sadad Payment API, providing easy-to-use methods for managing payment orders.

Installation

npm install sadad-payment-client

Features

  • ✅ Full TypeScript support with type definitions
  • ✅ Promise-based API with async/await
  • ✅ Complete Payment Orders API coverage
  • ✅ Built-in authentication (API Key)
  • ✅ Automatic error handling
  • ✅ Configurable base URL and timeout

Quick Start

import { SadadClient } from 'sadad-payment-client';

// Initialize the client
const client = new SadadClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.sadad.example.com', // Optional
  timeout: 30000 // Optional, default 30000ms
});

Usage Examples

Create a Payment Order

const order = await client.paymentOrders.create({
  merchantId: 'merchant-uuid',
  amount: 100.50,
  description: 'Payment for order #123',
  merchantReferance: 'ORDER-123',
  successRedirectUrl: 'https://yoursite.com/payment/success',
  failureRedirectUrl: 'https://yoursite.com/payment/failure',
  expiresInMinutes: 60, // Optional
  metadata: JSON.stringify({ orderId: '123' }) // Optional
});

if (order.isApiSuccess) {
  console.log('Payment Link:', order.response?.paymentLink);
  console.log('Order ID:', order.response?.id);
  console.log('Order Identifier:', order.response?.orderIdentifier);
} else {
  console.error('Error:', order.message);
}

Get Payment Order by Identifier

const order = await client.paymentOrders.getByIdentifier(
  'order-identifier',
  true // skipPreview
);

if (order.isApiSuccess) {
  console.log('Order Status:', order.response?.status);
  console.log('Amount:', order.response?.amount);
  console.log('Merchant:', order.response?.merchantDisplayName);
}

Get Payment Order by Merchant Reference

const order = await client.paymentOrders.getByMerchantReference(
  'merchant-uuid',
  'ORDER-123'
);

if (order.isApiSuccess) {
  console.log('Order found:', order.response);
}

List Payment Orders for a Merchant

const orders = await client.paymentOrders.listByMerchant(
  'merchant-uuid',
  {
    begin: 0,        // Starting index (default: 0)
    count: 20,       // Number of items (default: 20)
    status: 'paid'   // Optional: filter by status
  }
);

if (orders.isApiSuccess) {
  console.log('Total Orders:', orders.totalCount);
  console.log('Page Count:', orders.pageCount);
  
  orders.response?.forEach(order => {
    console.log(`Order ${order.id}: ${order.amount} ${order.currency} - ${order.status}`);
  });
}

Cancel a Payment Order

const result = await client.paymentOrders.cancel({
  orderId: 'order-uuid',
  cancelReason: 'Customer requested cancellation'
});

if (result.isApiSuccess) {
  console.log('Order cancelled successfully');
} else {
  console.error('Cancellation failed:', result.message);
}

Get Internal Order Details

const details = await client.paymentOrders.getInternalById('order-uuid');

if (details.isApiSuccess) {
  console.log('Order Details:', details.response);
}

API Reference

SadadClient

Main client class for interacting with the Sadad API.

Constructor Options

interface SadadClientConfig {
  apiKey?: string;        // API Key for authentication
  baseUrl?: string;       // Base URL (optional)
  timeout?: number;       // Request timeout in ms (default: 30000)
}

Note: apiKey must be provided.

PaymentOrdersApi

All payment order operations are available through client.paymentOrders:

Methods

  • create(request) - Create a new payment order
  • getByIdentifier(orderIdentifier, skipPreview?) - Get order by identifier
  • getByMerchantReference(merchantId, merchantReference) - Get order by merchant reference
  • getInternalById(orderId) - Get internal order details
  • listByMerchant(merchantId, options?) - List orders for a merchant with pagination
  • cancel(request) - Cancel a payment order

Types

CreatePaymentOrderRequest

interface CreatePaymentOrderRequest {
  merchantId: string;              // Required: UUID of merchant
  amount: number;                  // Required: Payment amount (min: 0.01)
  successRedirectUrl: string;      // Required: Success redirect URL
  failureRedirectUrl: string;      // Required: Failure redirect URL
  description?: string;            // Optional: Max 250 chars
  merchantReferance?: string;      // Optional: Max 100 chars
  metadata?: string;               // Optional: Any metadata
  expiresInMinutes?: number;       // Optional: Min 1
}

PaymentOrderResponse

interface PaymentOrderResponse {
  id: string;
  merchantDisplayName: string;
  logoUrl: string;
  providerType: string;
  orderIdentifier: string;
  paymentLink: string;
  amount: number;
  status: string;
  description: string;
  metadata: string;
  createdAt: string;
  expiresAt: string;
  merchantReference: string;
  successRedirectUrl: string;
  failureRedirectUrl: string;
}

CancelPaymentOrderRequest

interface CancelPaymentOrderRequest {
  orderId: string;           // Required: UUID of order
  cancelReason: string;      // Required: Max 250 chars
}

Error Handling

The client automatically handles errors and provides meaningful error messages:

try {
  const order = await client.paymentOrders.create(orderRequest);
  
  if (!order.isApiSuccess) {
    console.error('API Error:', order.errorCodeStr, order.message);
  }
} catch (error) {
  console.error('Request failed:', error.message);
}

Authentication

The Sadad API supports two authentication methods:

API Key - Passed as X-API-Key header

You can provide either or both in the client configuration.

Development

Build

npm run build

This compiles TypeScript files from src/ to dist/.

Project Structure

sadad-payment-client/
├── src/
│   ├── index.ts              # Main entry point
│   ├── sadad-client.ts       # Main client class
│   ├── payment-orders.ts     # Payment Orders API
│   ├── http-client.ts        # HTTP client wrapper
│   └── types.ts              # TypeScript interfaces
├── dist/                     # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
└── README.md

License

MIT

Support

For issues and questions, please refer to the Sadad API documentation or contact support.