JSPM

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

TypeScript SDK for Iyzico Payment Gateway with dynamic request loading and clean architecture

Package Exports

  • @uzansadik/iyzico-sdk
  • @uzansadik/iyzico-sdk/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@uzansadik/iyzico-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Iyzico SDK

A modern TypeScript SDK for Iyzico Payment Gateway with dynamic request loading and clean architecture.

Features

  • 🚀 Dynamic Request Loading: Automatically loads request classes based on method names
  • 🏗️ Clean Architecture: Separation of concerns between HTTP handling and request logic
  • 🔒 Type Safe: Full TypeScript support with comprehensive type definitions
  • Single Instance: Efficient singleton pattern with caching
  • 🎯 Easy to Extend: Add new endpoints by simply creating request classes
  • 🔐 Built-in Authentication: Automatic HMAC-SHA256 signature generation
  • 🌐 Next.js Compatible: Registry-based loading works in all JavaScript environments

Installation

npm install @uzansadik/iyzico-sdk

Quick Start

import { Iyzi } from '@uzansadik/iyzico-sdk';

// Initialize with environment variables
const iyzi = Iyzi.getInstance();

// Or initialize with configuration
const iyzi = Iyzi.getInstance({
  apiKey: 'your-api-key',
  secretKey: 'your-secret-key',
  baseUrl: 'https://sandbox-api.iyzipay.com',
});

Environment Variables

Create a .env file in your project root:

BASE_URL=https://sandbox-api.iyzipay.com
API_KEY=your-api-key
SECRET_KEY=your-secret-key

Usage Examples

Bin Check

const response = await iyzi.bincheck({
  binNumber: '589004',
  conversationId: '123456789',
  locale: 'tr',
});

console.log('Bank:', response.bankName);
console.log('Card Type:', response.cardType);

Installment Info

const response = await iyzi.installment({
  binNumber: '589004',
  price: 100,
  locale: 'tr',
});

console.log('Installment Details:', response.installmentDetails);

Next.js Usage

The SDK is fully compatible with Next.js. Use it in API routes:

// app/api/bincheck/route.ts
import { Iyzi } from '@uzansadik/iyzico-sdk';

export async function POST(request: Request) {
  try {
    const { binNumber } = await request.json();

    const iyzi = Iyzi.getInstance({
      apiKey: process.env.IYZI_API_KEY,
      secretKey: process.env.IYZI_SECRET_KEY,
      baseUrl: process.env.IYZI_BASE_URL,
    });

    const response = await iyzi.bincheck({ binNumber });

    return Response.json(response);
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 });
  }
}

Environment variables (.env.local):

IYZI_API_KEY=your-api-key
IYZI_SECRET_KEY=your-secret-key
IYZI_BASE_URL=https://sandbox-api.iyzipay.com

Dynamic Request Loading

The SDK automatically loads request classes based on method names:

// Calls requests/BinCheck.ts
await iyzi.bincheck(data);

// Calls requests/Installment.ts
await iyzi.installment(data);

// Calls requests/Payment.ts (when you create it)
await iyzi.payment(data);

Adding New Endpoints

To add a new endpoint, create a request class in the requests folder:

// requests/Payment.ts
import { RequestConfig } from '../Iyzi';

export interface PaymentRequest {
  price: number;
  paidPrice: number;
  currency: string;
  // ... other fields
}

export interface PaymentResponse {
  status: string;
  paymentId: string;
  // ... other fields
}

export class Payment {
  getConfig(): RequestConfig<PaymentRequest, PaymentResponse> {
    return {
      endpoint: '/payment/auth',
      method: 'POST',
      validateRequest: this.validateRequest,
      processRequest: this.processRequest,
      processResponse: this.processResponse,
    };
  }

  private validateRequest(request: PaymentRequest): void {
    if (!request.price || request.price <= 0) {
      throw new Error('Price is required and must be greater than 0');
    }
  }

  private processRequest(request: PaymentRequest): PaymentRequest {
    return {
      ...request,
      conversationId: request.conversationId || this.generateConversationId(),
    };
  }

  private processResponse(data: any): PaymentResponse {
    return data;
  }

  private generateConversationId(): string {
    return Math.random().toString(36).substring(2, 15);
  }
}

Then use it:

const response = await iyzi.payment({
  price: 100,
  paidPrice: 100,
  currency: 'TRY',
});

Available Methods

  • bincheck(request) - Check bin number information
  • installment(request) - Get installment information

More methods will be added based on Iyzico API endpoints.

TypeScript Support

The SDK is written in TypeScript and provides full type definitions:

import {
  Iyzi,
  IyziConfig,
  BinCheckRequest,
  BinCheckResponse,
  InstallmentRequest,
  InstallmentResponse,
} from '@uzansadik/iyzico-sdk';

API Reference

Iyzi Class

getInstance(config?: IyziConfig): Iyzi

Creates or returns the singleton instance.

Configuration

interface IyziConfig {
  apiKey?: string;
  secretKey?: string;
  baseUrl?: string;
}

Request Configuration

interface RequestConfig<TRequest, TResponse> {
  endpoint: string;
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
  processRequest?: (data: TRequest) => any;
  processResponse?: (data: any) => TResponse;
  validateRequest?: (data: TRequest) => void;
}

Development

# Install dependencies
npm install

# Build the project
npm run build

# Watch mode
npm run build:watch

# Clean build artifacts
npm run clean

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For support, please open an issue on GitHub.