Node.js SDK
Official Node.js SDK for Longswipe merchant integrations.
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({
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
- Add New Customer
addNewCustomer(customer: { email: string; name: string }): Promise<ApiResponse>
- Update Customer
updateCustomer(customer: { id: string; email: string; name: string }): Promise<ApiResponse>
- Delete Customer
deleteCustomer(customerID: string): Promise<ApiResponse>
- Fetch Customer by Email
fetchCustomerByEmail(email: string): Promise<CustomerResponse>
- Fetch Customers (with pagination)
fetchCustomers(params?: {
page?: number;
limit?: number;
search?: string;
}): Promise<CustomersResponse>
Invoice Management
- 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
- Fetch Supported Crypto Networks
fetchSupportedCryptoNetworks(): Promise<CryptoNetworksResponse>
- Fetch Supported Currencies
fetchSupportedCurrencies(): Promise<CurrenciesResponse>
Voucher Operations
- Fetch Voucher Redemption Charges
fetchVoucherRedemptionCharges(request: {
amount: number;
lockPin: string;
toCurrencyAbbreviation: string;
voucherCode: string;
walletAddress: string;
}): Promise<VoucherRedemptionChargesResponse>
- 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);
}
}
Support
For support, email support@longswipe.com or visit https://longswipe.com/support