npm package: @payotex.com/node
Description: Server-side SDK for Payotex crypto payment processing
Latest version: 1.0.1

# @payotex.com/node

Server-side SDK for Payotex crypto payment processing. Accept cryptocurrency payments with cross-chain swap support.

## Installation

```bash
npm install @payotex.com/node
```

## Requirements

- Node.js 18+ (uses native `fetch`)
- Zero runtime dependencies

## Quick Start

```typescript
import { Payotex } from '@payotex.com/node';

const payotex = new Payotex({
  secretKey: 'sk_live_your_secret_key_here',
});

// Create a checkout session
const session = await payotex.checkout.create({
  amount: '49.99',
  currency: 'USD',
});

console.log(session.sessionId); // Redirect user to pay
```

## API Reference

### Constructor

```typescript
const payotex = new Payotex({
  secretKey: 'sk_live_...', // Required. Your secret API key.
  baseUrl: 'https://payotex.com', // Optional. Defaults to https://payotex.com
});
```

### Keys

#### `payotex.keys.create(params)`

Create a new API key pair for a merchant.

```typescript
const keys = await payotex.keys.create({
  payoutChain: 'ETH',
  payoutToken: 'ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48',
  payoutAddress: '0xYourAddress...',
  // Optional secondary payout
  payoutChain2: 'BTC',
  payoutToken2: 'BTC.BTC',
  payoutAddress2: 'bc1q...',
  label: 'My Store',
});

console.log(keys.secretKey);      // sk_live_...
console.log(keys.publishableKey); // pk_live_...
```

#### `payotex.keys.verify()`

Verify the current API key and get merchant configuration.

```typescript
const info = await payotex.keys.verify();
console.log(info.payoutChain);  // "ETH"
console.log(info.configValid);  // true
console.log(info.isActive);     // true
```

### Checkout

#### `payotex.checkout.create(params)`

Create a new checkout session.

```typescript
const session = await payotex.checkout.create({
  amount: '100.00',       // Required. Amount as string or number.
  currency: 'USD',        // Required. USD, EUR, GBP, or crypto asset.
  metadata: {             // Optional. Custom metadata (max 4096 chars).
    orderId: 'order-123',
    customerId: 'cust-456',
  },
  expiresIn: 60,          // Optional. Minutes until expiry (5-1440, default 30).
});

console.log(session.sessionId); // Use to track payment
console.log(session.status);    // "pending"
```

### Sessions

#### `payotex.sessions.get(sessionId)`

Get details for a checkout session. This is a public endpoint (no auth required).

```typescript
const details = await payotex.sessions.get('session-id-here');
console.log(details.status);           // "pending" | "paid" | "expired"
console.log(details.payotex_fee_percent);
```

#### `payotex.sessions.getAssets(sessionId)`

Get available payment assets for a session.

```typescript
const assets = await payotex.sessions.getAssets('session-id-here');
assets.forEach(asset => {
  console.log(`${asset.symbol} on ${asset.chain}`);
});
```

#### `payotex.sessions.createQuote(sessionId, params)`

Create a swap quote for a session.

```typescript
const quote = await payotex.sessions.createQuote('session-id-here', {
  fromAsset: 'BTC.BTC',
});

console.log(quote.inbound_address);     // Where to send funds
console.log(quote.expected_amount_in);   // Amount to send
console.log(quote.expected_amount_out);  // Amount merchant receives
console.log(quote.memo);                 // Include in transaction if present
```

## Error Handling

All methods throw on errors. Errors from the API include a `status` code and `response` object.

```typescript
try {
  const session = await payotex.checkout.create({
    amount: '100',
    currency: 'USD',
  });
} catch (err) {
  console.error(err.message);  // Human-readable error
  console.error(err.status);   // HTTP status code (e.g., 400, 401)
  console.error(err.response); // Full API response body
}
```

## TypeScript

All types are exported from the main entry point:

```typescript
import {
  Payotex,
  PayotexConfig,
  CreateKeysRequest,
  CreateKeysResponse,
  VerifyKeyResponse,
  CreateCheckoutSessionRequest,
  CheckoutSession,
  SessionDetails,
  SessionAsset,
  CreateQuoteRequest,
  SessionQuote,
  PayotexError,
} from '@payotex.com/node';
```

## Security Best Practices

- **Never expose your secret key (`sk_live_`) client-side.** Use it only in server-side code.
- Use the publishable key (`pk_live_`) for client-side integrations.
- Store your secret key in environment variables, never in source code.
- The SDK validates key format on initialization and rejects publishable keys to prevent misuse.

## License

MIT