1.0.0 • Published 1 year ago

@wirexapp/wirex-pay-sdk v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

WirexPay SDK

This SDK provides an easy interface to interact with the Wirex Pay API, including features like user management, card operations, transactions, wallet management, and action confirmation. The SDK also supports real-time WebSocket updates for changes such as balance or transaction updates.


Table of Contents


Installation

Install the SDK via npm:

npm install wirex-pay-sdk

Setup and Initialization

To begin using the SDK, import the WirexPay class and initialize it with the necessary configuration options.

Configuration Interface

export interface IConfig {
  token: string;              // API token for authentication (required)
  subscribeToSocket?: boolean; // Enable WebSocket subscription (optional)
  socketUrl?: string;          // WebSocket server URL (optional)
  apiUrl?: string;             // API base URL (optional)
}

Initializing WirexPay SDK

import { WirexPay } from 'wirex-pay-sdk';

const config = {
  token: 'your-user-specific-token',
  subscribeToSocket: true, // Enable real-time updates via WebSocket
};

WirexPay.init(config);

Services

UserService

The UserService provides methods to manage users, such as updating phone numbers, and fetching user information.

Methods:

  • getUserInfo(): Fetch user information.
  • updatePhoneNumber(request: UpdatePhoneNumberRequest): Update phone number.
  • confirmPhoneNumber(request: ConfirmPhoneNumberRequest): Confirm phone number.
  • getVerificationLink(): Get verification link.
  • getUserAccessToken(): Generate an access token.
  • subscribeToUserChange(callback): Subscribe to user change events.

Usage Examples:

Retrieving user info

WirexPay.user.getUserInfo()
  .then(response => console.log('User info:', response))
  .catch(error => console.error('Error:', error));

Subscribing to User Changes

WirexPay.user.subscribeToUserChange((userData) => {
  console.log('User data changed:', userData);
});

CardService

The CardService allows you to manage cards, including blocking, unblocking, activating, and setting limits.

Methods:

  • getCards(page: number, size: number): List all cards.
  • createPlasticCard(request: CreatePlasticCardRequest): Issue a new plastic card.
  • activateCard(cardId, request: ActivateCardRequest): Activate a card.
  • blockCard(cardId): Block a card.
  • unblockCard(cardId): Unblock a card.
  • closeCard(cardId): Close a card.
  • setCardLimit(cardId, request: SetCardLimitRequest): Set card spending limit.
  • setActiveBalance(cardId, tokenSymbol): Set active balance for card.
  • getCardCvv(cardId, actionToken): Retrieve card CVV.
  • getCardPin(cardId, actionToken): Retrieve card PIN.
  • subscribeToCardsChange(callback): Subscribe to cards change events.

Usage Examples:

Fetching cards

WirexPay.card.getCards(1, 10)
  .then(response => console.log('Cards list:', response))
  .catch(error => console.error('Error:', error));

Setting Card Spending Limit

WirexPay.card.setCardLimit('card123', { limit: 5000 })
  .then(() => console.log('Limit set successfully'))
  .catch(error => console.error('Error setting limit:', error));

Subscribing to Cards Changes

WirexPay.card.subscribeToCardsChange((userData) => {
  console.log('User data changed:', userData);
});

TransactionService

The TransactionService handles transaction history and real-time updates for card transactions.

Methods:

  • getCardTransactions(page: number, size: number): Fetch card transactions.
  • subscribeToTransactionChanges(callback): Subscribe to transaction change events.

Usage Examples:

Fetching Card Transactions

WirexPay.transaction.getCardTransactions(1, 10)
  .then(response => console.log('Transactions:', response))
  .catch(error => console.error('Error fetching transactions:', error));

Subscribing to Transaction Changes

WirexPay.transaction.subscribeToTransactionChanges((transaction) => {
  console.log('Transaction changed:', transaction);
});

WalletService

The WalletService manages wallet balances and provides real-time updates for balance changes.

Methods:

  • getWallet(): Retrieve wallet information.
  • subscribeToBalanceChanges(callback): Subscribe to balance change events.

Usage Examples:

Fetching wallet information

WirexPay.wallet.getWallet()
  .then(response => console.log('Wallet info:', response))
  .catch(error => console.error('Error fetching transactions:', error));

Subscribing to Wallet Balance Changes

WirexPay.wallet.subscribeToBalanceChanges((wallet) => {
  console.log('Wallet balance changed:', wallet);
});

ActionConfirmationService

The ActionConfirmationService manages SMS confirmations for various user actions.

Methods:

  • createSmsConfirmation(request: CreateSmsConfirmationRequest): Start an SMS confirmation session.
  • completeSmsConfirmation(request: CompleteSmsConfirmationRequest): Verify an OTP code and complete the session.

Usage Examples:

Completing SMS confirmation

WirexPay.actionConfirmation.completeSmsConfirmation({ code: '123456', session_id: 'some-id' })
  .then(response => console.log('SMS confirmation token:', response))
  .catch(error => console.error('Error fetching transactions:', error));

1.0.0

1 year ago