1.0.7 • Published 10 months ago

@longswipe/longswipe-node v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@longswipe/longswipe-node

Official Node.js SDK for Longswipe merchant integrations.

npm version License: MIT

Installation

npm install @longswipe/longswipe-node

Or with yarn:

yarn add @longswipe/longswipe-node

Usage

import { LongswipeSDK } from '@longswipe/longswipe-node';

// Initialize the SDK
const longswipe = new LongswipeSDK({
  environment:'production' // 'sandbox' for test environment
  publicKey: 'your_public_key',
  secretKey: 'your_secret_key'  // Only required for authenticated endpoints
});

API Reference

Configuration

The SDK constructor accepts a configuration object with the following properties:

interface LongswipeConfig {
  publicKey: string;    // Your Longswipe public key (required for all endpoints)
  secretKey: string;    // Your Longswipe secret key (required only for authenticated endpoints)
}

Authenticated Endpoints

These endpoints require both public and secret keys.

Customer Management

  1. Add New Customer
addNewCustomer(customer: { email: string; name: string }): Promise<ApiResponse>
  1. Update Customer
updateCustomer(customer: { id: string; email: string; name: string }): Promise<ApiResponse>
  1. Delete Customer
deleteCustomer(customerID: string): Promise<ApiResponse>
  1. Fetch Customer by Email
fetchCustomerByEmail(email: string): Promise<CustomerResponse>
  1. Fetch Customers (with pagination)
fetchCustomers(params?: {
  page?: number;
  limit?: number;
  search?: string;
}): Promise<CustomersResponse>

Invoice Management

  1. Create Invoice
createInvoice(invoice: {
  blockchainNetworkId: string;
  currencyId: string;
  dueDate: string;
  invoiceDate: string;
  invoiceItems: Array<{
    description: string;
    quantity: number;
    unitPrice: number;
  }>;
  merchantUserId: string;
}): Promise<ApiResponse>

Public Endpoints

These endpoints only require the public key.

Crypto Networks and Currencies

  1. Fetch Supported Crypto Networks
fetchSupportedCryptoNetworks(): Promise<CryptoNetworksResponse>
  1. Fetch Supported Currencies
fetchSupportedCurrencies(): Promise<CurrenciesResponse>

Voucher Operations

  1. Fetch Voucher Redemption Charges
fetchVoucherRedemptionCharges(request: {
  amount: number;
  lockPin: string;
  toCurrencyAbbreviation: string;
  voucherCode: string;
  walletAddress: string;
}): Promise<VoucherRedemptionChargesResponse>
  1. Redeem Voucher
redeemVoucher(request: {
  amount: number;
  lockPin: string;
  toCurrencyAbbreviation: string;
  voucherCode: string;
  walletAddress: string;
}): Promise<ApiResponse>

Response Types

All API responses follow this structure:

interface ApiResponse {
  code: number;
  message: string;
  status: string;
  data?: any;
}

Specific responses include additional data:

// Customer responses
interface CustomerResponse extends ApiResponse {
  customer?: {
    id: string;
    email: string;
    name: string;
    merchantID: string;
  };
}

// Crypto network response
interface CryptoNetworksResponse extends ApiResponse {
  data?: Array<{
    blockExplorerUrl: string;
    chainID: string;
    cryptocurrencies: Array<{
      currencyAddress: string;
      currencyData: {
        abbrev: string;
        currencyType: string;
        id: string;
        image: string;
        isActive: boolean;
        name: string;
        symbol: string;
      };
      currencyDecimals: string;
      currencyName: string;
      id: string;
      longswipeContractAddress: string;
      networkID: string;
      status: boolean;
    }>;
    id: string;
    networkName: string;
    networkType: string;
    rpcUrl: string;
  }>;
}

// Currencies response
interface CurrenciesResponse extends ApiResponse {
  data?: {
    currencies: Array<{
      abbreviation: string;
      createdAt: string;
      currency: string;
      currencyType: string;
      id: string;
      image: string;
      isActive: boolean;
      symbol: string;
    }>;
  };
}

Error Handling

The SDK throws errors for:

  • Network issues
  • Invalid API keys
  • Missing required fields
  • Server errors

Example error handling:

try {
  await longswipe.addNewCustomer({
    email: 'customer@example.com',
    name: 'John Doe'
  });
} catch (error) {
  if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    console.error('Error response:', error.response.data);
  } else if (error.request) {
    // The request was made but no response was received
    console.error('No response received:', error.request);
  } else {
    // Something happened in setting up the request that triggered an Error
    console.error('Error:', error.message);
  }
}

Development

  1. Clone the repository
git clone https://github.com/longswipe/longswipe-node.git
cd longswipe-node
  1. Install dependencies
npm install
  1. Build the package
npm run build
  1. Run in development mode with watch
npm run dev

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, email support@longswipe.com or visit https://longswipe.com/support

Links

1.0.7

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago