JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 67
  • Score
    100M100P100Q86180F
  • License MIT

Official Node.js/TypeScript SDK for Stream API - Complete payment processing with consumers, products, subscriptions, invoices, and payment links

Package Exports

  • @streamsdk/typescript

Readme

@streamsdk/typescript ยท Official Stream SDK for TypeScript

Stream Logo

Official Node.js/TypeScript SDK for Stream API

npm version TypeScript License


๐Ÿ“š Table of Contents


Overview

The Stream SDK provides a complete TypeScript/JavaScript interface to the Stream payment platform. Process payments, manage subscriptions, create invoices, and handle customer data with full type safety and modern JavaScript features.

Key Features:

  • ๐Ÿ” Secure API Key authentication
  • ๐Ÿ‘ฅ Customer (Consumer) management
  • ๐Ÿ“ฆ Product catalog management
  • ๐Ÿ’ณ Payment link creation
  • ๐Ÿ”„ Subscription handling
  • ๐Ÿงพ Invoice generation
  • ๐ŸŽŸ๏ธ Coupon & discount management
  • ๐Ÿ“ Full TypeScript support
  • โšก ES Modules and CommonJS compatible

Installation

npm install @streamsdk/typescript

Or install from GitHub:

npm install github:streampayments/streamsdk-typescript#v1.1.0

Add to package.json

{
  "dependencies": {
    "@streamsdk/typescript": "^1.1.0"
  }
}

Quick Start

import StreamSDK from "@streamsdk/typescript";

// Initialize the SDK
const client = StreamSDK.init(process.env.STREAM_API_KEY!);

// Create a payment link
const result = await client.createSimplePaymentLink({
  name: "Monthly Subscription",
  amount: 99.99,
  consumer: {
    email: "customer@example.com",
    name: "Ahmad Ali",
    phone: "+966501234567",
  },
  product: {
    name: "Premium Plan",
    price: 99.99,
  },
  successRedirectUrl: "https://yourapp.com/success",
  failureRedirectUrl: "https://yourapp.com/failure",
});

console.log("Payment URL:", result.paymentUrl);

SDK Features

Core Capabilities

Feature Description
Authentication API Key and Bearer Token support
Consumers Create, update, list, and delete customers
Products Manage your product catalog
Payment Links Generate secure payment links
Subscriptions Handle recurring payments
Invoices Create and manage invoices
Coupons Discount and promotion management
Webhooks Real-time event notifications

Supported Features

  • โœ… Single or multiple products per payment
  • โœ… Guest checkout (no consumer required)
  • โœ… Smart resource matching (automatic deduplication)
  • โœ… SAR currency (default)
  • โœ… Custom metadata support
  • โœ… Full TypeScript type definitions
  • โœ… ESM and CommonJS support

Usage

For detailed usage examples and API documentation, please refer to the API Documentation section below.

Authentication

Initialize the SDK with your API key:

import StreamSDK from "@streamsdk/typescript";

const client = StreamSDK.init(process.env.STREAM_API_KEY!);

For more authentication options and detailed examples for each resource, see the documentation links in the Available Resources and Operations section.


Examples

Explore complete TypeScript SDK examples in the examples directory:

View All Examples โ†’

For Express.js examples, see streamsdk-express


Express.js Integration

For Express.js applications, we provide a separate adapter package with declarative handlers for checkout and webhooks:

streamsdk-express โ†’


API Documentation

Available Resources and Operations

Available methods

Me / Organization

  • getMe() - Get authenticated user and organization info
  • createOrganizationInvite(input) - Invite a user to join the organization

Branches

  • createBranch(input) - Create Branch
  • listBranches() - List Branches
  • getBranch(id) - Get Branch
  • updateBranch(id, input) - Update Branch
  • deleteBranch(id) - Delete Branch

Consumers

Coupons

Invoices

  • create - Create Invoice
  • get - Get Invoice
  • list - List Invoices
  • updateInvoiceInPlace(id, input) - Update invoice items in-place
  • create - Create Payment Link
  • get - Get Payment Link
  • list - List Payment Links
  • updatePaymentLinkCoupons(id, input) - Update coupons on a payment link
  • updatePaymentLinkStatus(id, input) - Activate or deactivate a payment link

Payments

  • list - List Payments
  • get - Get Payment
  • refund - Refund Payment
  • autoChargeOnDemand(id) - Trigger auto-charge on demand
  • markPaymentPaid(id, input) - Mark a payment as paid manually

Products

Subscriptions

  • get - Get Subscription
  • update - Update Subscription
  • list - List Subscriptions
  • create - Create Subscription
  • cancel - Cancel Subscription
  • uncancelSubscription(id) - Un-cancel a subscription
  • deletePendingSubscriptionChange(id) - Delete a pending plan change
  • freeze - Freeze Subscription
  • listFreezes - List Subscription Freezes
  • updateFreeze - Update Subscription Freeze

Subscriptions.Freeze

  • delete - Delete Subscription Freeze

Click on each resource above to see detailed documentation with code examples, parameters, and response types.


Error Handling

The SDK throws errors for failed requests:

try {
  const consumer = await client.createConsumer({
    name: "Ahmad Ali",
    email: "invalid-email",
  });
} catch (error) {
  console.error("Error creating consumer:", error.message);
  console.error("Status:", error.status);
  console.error("Response:", error.response);
}

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/streampayments/streamsdk-typescript.git
cd streamsdk-typescript

# Install dependencies
npm install

# Build the SDK
npm run build

# Run examples
npm run example

Support

Documentation

Help & Issues


License

MIT License - see LICENSE for details.


Made with โค๏ธ by Stream

Website โ€ข Documentation โ€ข GitHub