Installation  
Install the Receeco Node.js SDK via npm: 
npm  install  @receeco/node-sdk  
 
Or with yarn: 
yarn  add  @receeco/node-sdk  
 
Quick Start  
const  {  ReceecoPOS  }  =  require ( "@receeco/node-sdk" );  
 
// Initialize client  
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "your-merchant-id" ,  
  apiKey:  "pos_live_abc123..." ,  // Optional for enhanced security  
  baseUrl:  "https://receeco.com/api/trpc" ,  // Optional, defaults to production  
});  
 
// Create a receipt  
async  function  processTransaction ( saleData ) {  
  try  {  
    const  receipt  =  await  receeco . createReceipt ({  
      items:  saleData . items ,  
      totalAmount:  saleData . total ,  
      currency:  "NGN" ,  
      paymentMethod:  saleData . paymentMethod ,  
      location:  "Main Branch" ,  
    });  
 
    console . log ( "Receipt created:" ,  receipt . token );  
    console . log ( "Short code:" ,  receipt . shortCode );  
    console . log ( "QR code URL:" ,  receipt . qrCodeUrl );  
 
    return  receipt ;  
  }  catch  ( error ) {  
    console . error ( "Transaction failed:" ,  error . message );  
    throw  error ;  
  }  
}  
 
Configuration  
Basic Configuration  
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "grocery-store-001" ,  
  merchantName:  "Fresh Foods Market" ,  
  merchantLogo:  "https://example.com/logo.png" ,  
  accentColor:  "#22c55e" ,  
});  
 
Advanced Configuration  
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "grocery-store-001" ,  
  apiKey:  process . env . RECEECO_API_KEY ,  
  baseUrl:  "https://receeco.com/api/trpc" ,  
  timeout:  10000 ,  // 10 seconds  
  retries:  3 ,  
  offline:  {  
    enabled:  true ,  
    queueSize:  1000 ,  
    retryInterval:  30000 ,  // 30 seconds  
  },  
});  
 
API Methods  
createReceipt(data)  
Creates a new digital receipt. 
Transaction data object Currency code (defaults to “NGN”) 
 
const  receipt  =  await  receeco . createReceipt ({  
  items:  [  
    {  
      name:  "Premium Rice (5kg)" ,  
      quantity:  1 ,  
      unitPrice:  9500 ,  
      totalPrice:  9500 ,  
    },  
  ],  
  totalAmount:  9500 ,  
  currency:  "NGN" ,  
  paymentMethod:  "card" ,  
  location:  "Lagos Branch" ,  
  category:  "Groceries" ,  
});  
 
Returns:  
{  
  receiptId :  'rcpt_abc123_def456' ,  
  token :  'rcpt_abc123_def456' ,  
  shortCode :  'ABC123' ,  
  receiptUrl :  'https://receeco.com/app/receipt/rcpt_abc123_def456' ,  
  qrCodeUrl :  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...' ,  
  qrCodeSvg :  '<svg>...</svg>' ,  
  status :  'success' ,  
  timestamp :  '2024-01-15T14:30:00Z'  
}  
 
getReceipt(token)  
Retrieves receipt data by token or short code. 
const  receipt  =  await  receeco . getReceipt ( "rcpt_abc123_def456" );  
// or  
const  receipt  =  await  receeco . getReceipt ( "ABC123" );  
 
Updates customer contact information for a receipt. 
await  receeco . updateReceiptContact ( "ABC123" , {  
  email:  "customer@example.com" ,  
  phone:  "+2348012345678" ,  
});  
 
Error Handling  
The SDK provides structured error handling: 
const  {  ReceecoPOS ,  ReceecoPOSError  }  =  require ( "@receeco/node-sdk" );  
 
try  {  
  const  receipt  =  await  receeco . createReceipt ( transactionData );  
}  catch  ( error ) {  
  if  ( error  instanceof  ReceecoPOSError ) {  
    console . error ( "Receeco API Error:" , {  
      code:  error . code ,  
      message:  error . message ,  
      httpStatus:  error . httpStatus ,  
      details:  error . details ,  
    });  
  }  else  {  
    console . error ( "Unexpected error:" ,  error );  
  }  
}  
 
Error Types  
Error Code Description Action  
INVALID_INPUTRequest validation failed Check input data NOT_FOUNDReceipt not found Verify token/code NETWORK_ERRORConnection failed Check internet connection TIMEOUTRequest timed out Retry request RATE_LIMITEDToo many requests Implement backoff  
 
Offline Support  
The SDK includes built-in offline support for unreliable network conditions: 
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "your-merchant-id" ,  
  offline:  {  
    enabled:  true ,  
    queueSize:  1000 ,  
    retryInterval:  30000 ,  
    maxRetries:  5 ,  
  },  
});  
 
// Transactions are automatically queued when offline  
const  receipt  =  await  receeco . createReceipt ( transactionData );  
// Returns immediately with local receipt data  
// Syncs to server when connection is restored  
 
Queue Management  
// Check queue status  
const  queueStatus  =  receeco . getQueueStatus ();  
console . log ( "Pending transactions:" ,  queueStatus . pending );  
console . log ( "Failed transactions:" ,  queueStatus . failed );  
 
// Manually process queue  
await  receeco . processQueue ();  
 
// Clear failed transactions  
receeco . clearFailedTransactions ();  
 
TypeScript Support  
The SDK is written in TypeScript and includes full type definitions: 
import  {  ReceecoPOS ,  TransactionData ,  Receipt  }  from  "@receeco/node-sdk" ;  
 
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "your-merchant-id" ,  
});  
 
const  transactionData :  TransactionData  =  {  
  items:  [  
    {  
      name:  "Premium Rice (5kg)" ,  
      quantity:  1 ,  
      unitPrice:  9500 ,  
      totalPrice:  9500 ,  
    },  
  ],  
  totalAmount:  9500 ,  
  currency:  "NGN" ,  
};  
 
const  receipt :  Receipt  =  await  receeco . createReceipt ( transactionData );  
 
Express.js Integration  
Example integration with Express.js: 
const  express  =  require ( "express" );  
const  {  ReceecoPOS  }  =  require ( "@receeco/node-sdk" );  
 
const  app  =  express ();  
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  process . env . MERCHANT_ID ,  
  apiKey:  process . env . RECEECO_API_KEY ,  
});  
 
app . use ( express . json ());  
 
app . post ( "/process-sale" ,  async  ( req ,  res )  =>  {  
  try  {  
    const  {  items ,  total ,  paymentMethod  }  =  req . body ;  
 
    const  receipt  =  await  receeco . createReceipt ({  
      items ,  
      totalAmount:  total ,  
      paymentMethod ,  
      currency:  "NGN" ,  
    });  
 
    res . json ({  
      success:  true ,  
      receiptUrl:  receipt . receiptUrl ,  
      shortCode:  receipt . shortCode ,  
      qrCode:  receipt . qrCodeUrl ,  
    });  
  }  catch  ( error ) {  
    res . status ( 500 ). json ({  
      success:  false ,  
      error:  error . message ,  
    });  
  }  
});  
 
app . listen ( 3000 , ()  =>  {  
  console . log ( "POS server running on port 3000" );  
});  
 
Testing  
The SDK includes utilities for testing: 
const  {  ReceecoPOS  }  =  require ( "@receeco/node-sdk" );  
 
// Use test mode  
const  receeco  =  new  ReceecoPOS ({  
  merchantId:  "test-merchant" ,  
  testMode:  true ,  // Uses test endpoints  
});  
 
// Mock mode for unit tests  
const  mockReceeco  =  new  ReceecoPOS ({  
  merchantId:  "test-merchant" ,  
  mockMode:  true ,  // Returns mock data without API calls  
});  
 
Examples  
Basic POS Integration  
const  {  ReceecoPOS  }  =  require ( "@receeco/node-sdk" );  
 
class  POSSystem  {  
  constructor () {  
    this . receeco  =  new  ReceecoPOS ({  
      merchantId:  "grocery-store-001" ,  
      merchantName:  "Fresh Foods Market" ,  
    });  
  }  
 
  async  completeSale ( cart ,  paymentMethod ) {  
    // Calculate totals  
    const  items  =  cart . map (( item )  =>  ({  
      name:  item . name ,  
      quantity:  item . quantity ,  
      unitPrice:  item . price ,  
      totalPrice:  item . price  *  item . quantity ,  
    }));  
 
    const  totalAmount  =  items . reduce (( sum ,  item )  =>  sum  +  item . totalPrice ,  0 );  
 
    // Create digital receipt  
    const  receipt  =  await  this . receeco . createReceipt ({  
      items ,  
      totalAmount ,  
      paymentMethod ,  
      currency:  "NGN" ,  
      category:  this . categorizeItems ( items ),  
    });  
 
    // Display QR code to customer  
    this . displayQRCode ( receipt . qrCodeUrl );  
 
    // Print receipt with short code  
    this . printReceipt ( receipt );  
 
    return  receipt ;  
  }  
 
  categorizeItems ( items ) {  
    // Simple categorization logic  
    const  foodItems  =  [ "rice" ,  "bread" ,  "milk" ,  "meat" ];  
    const  hasFood  =  items . some (( item )  =>  
      foodItems . some (( food )  =>  item . name . toLowerCase (). includes ( food ))  
    );  
    return  hasFood  ?  "Groceries"  :  "Other" ;  
  }  
 
  displayQRCode ( qrCodeUrl ) {  
    // Display QR code on POS screen  
    console . log ( "Display QR code:" ,  qrCodeUrl );  
  }  
 
  printReceipt ( receipt ) {  
    // Print receipt with short code  
    console . log ( `Receipt Code:  ${ receipt . shortCode } ` );  
    console . log ( `Access at: receeco.com/app/scan` );  
  }  
}  
 
// Usage  
const  pos  =  new  POSSystem ();  
const  cart  =  [  
  {  name:  "Premium Rice (5kg)" ,  quantity:  1 ,  price:  9500  },  
  {  name:  "Fresh Milk (1L)" ,  quantity:  2 ,  price:  1575  },  
];  
 
pos . completeSale ( cart ,  "card" );  
 
Best Practices  
Environment Variables Store API keys in environment variables, never in code 
Error Handling Always wrap API calls in try-catch blocks 
Offline Support Enable offline mode for unreliable connections 
Logging Log important events for debugging and monitoring 
 
Use the SDK’s built-in retry and offline capabilities to ensure reliable
operation in challenging network conditions common in Nigerian retail
environments.