Skip to main content

MyazaPOS

The main SDK class. All methods are available after calling init().

Constructor

const pos = new MyazaPOS(config: MyazaPOSConfig);
See Configuration for all options.

init()

Initialize the SDK and fetch the merchant profile. Must be called before any other method.
await pos.init(): Promise<MyazaPOS>;
Returns: The SDK instance (for chaining). Throws: GridlogAPIError if the merchant ID is invalid or the API is unreachable.

checkout(params)

Opens the checkout modal where the customer selects a chain and token, then creates a payment session and polls for confirmation.
await pos.checkout(params: CheckoutParams): Promise<PaymentSession | null>;
Parameters:
ParamTypeRequiredDescription
amountnumberYesFiat amount to charge
currencystringNoCurrency code (default: 'NGN')
payoutAccountNumberstringNoBank account for fiat settlement
payoutNetworkIdstringNoBank network ID (from getBanks())
Returns: PaymentSession if the customer completes selection, null if they close the modal.

createSession(params)

Create a payment session directly, bypassing the checkout modal. Use this when you handle chain/token selection yourself.
await pos.createSession(params: CreateSessionParams): Promise<PaymentSession>;
Parameters:
ParamTypeRequiredDescription
amountnumberYesFiat amount
chainstringYesBlockchain (e.g. 'polygon')
tokenstringYesToken symbol (e.g. 'USDC')
metadataRecord<string, unknown>NoCustom data attached to the session
payoutAccountNumberstringNoBank account for settlement
payoutNetworkIdstringNoBank network ID

getNetworks()

Fetch supported blockchains and their tokens.
await pos.getNetworks(): Promise<SupportedNetwork[]>;
Response type:
interface SupportedNetwork {
  chain: string;        // e.g. 'polygon'
  name: string;         // e.g. 'Polygon'
  logo?: string;
  supportedTokens: TokenInfo[];
}

interface TokenInfo {
  symbol: string;       // e.g. 'USDC'
  logoUrl?: string;
}

getExchangeRate(currency, coin)

Get the current exchange rate between a fiat currency and a crypto token.
await pos.getExchangeRate(currency: string, coin: string): Promise<ExchangeRate>;
Response type:
interface ExchangeRate {
  rate: number;
  buyRate: number;
  sellRate: number;
  fxMargin: number;
  source?: string;
  currency: string;  // e.g. 'USD'
  coin: string;      // e.g. 'USDC'
}

getBanks(currency)

List available banks for fiat payout in a given currency.
await pos.getBanks(currency: string): Promise<Bank[]>;
Response type:
interface Bank {
  id: string;
  name: string;
  networkId: string;   // pass to resolveAccount() and checkout()
  currency: string;
  country: string;
  available: boolean;
}

resolveAccount(networkId, accountNumber)

Verify a bank account holder before initiating payout.
await pos.resolveAccount(networkId: string, accountNumber: string): Promise<BankAccountResolution>;
Response type:
interface BankAccountResolution {
  networkId: string;
  accountNumber: string;
  accountName: string;    // verified account holder name
  matched: boolean;
}

on / once / off

Subscribe to SDK events. See Events for all event types.
pos.on<K extends SDKEventName>(event: K, handler: (payload: SDKEventMap[K]) => void): MyazaPOS;
pos.once<K extends SDKEventName>(event: K, handler: (payload: SDKEventMap[K]) => void): MyazaPOS;
pos.off<K extends SDKEventName>(event: K, handler: (payload: SDKEventMap[K]) => void): MyazaPOS;

use(plugin)

Register a plugin at runtime.
pos.use(plugin: MyazaPlugin): MyazaPOS;
See Plugins for details.

registerMerchant(config)

Register an additional merchant configuration for multi-tenant setups.
pos.registerMerchant(config: MerchantConfig): MyazaPOS;
Parameters:
interface MerchantConfig {
  merchantId: string;
  apiKey: string;
  theme?: ThemeConfig;
  successUrl?: string;
  cancelUrl?: string;
  fraud?: FraudConfig;
}

getState()

Returns the current SDK state machine state.
pos.getState(): SDKState;

terminate()

Shut down the SDK, cancel any active polling, close the modal, and clean up resources.
await pos.terminate(): Promise<void>;

Error Types

GridlogAPIError

Thrown when an API request fails.
class GridlogAPIError extends Error {
  status: number;          // HTTP status code
  code: string;            // machine-readable error code
  correlationId: string;   // request correlation ID
}

CircuitOpenError

Thrown when the API circuit breaker is open (too many recent failures).
class CircuitOpenError extends Error {}

MaxRetriesExceededError

Thrown when all retry attempts are exhausted.
class MaxRetriesExceededError extends Error {
  attempts: number;
  lastError: unknown;
}

StateMachineError

Thrown when an illegal state transition is attempted.
class StateMachineError extends Error {
  code: 'ILLEGAL_TRANSITION' | 'GUARD_REJECTED';
  from: SDKState;
  to: SDKState;
}