Official JavaScript SDK for Loyalty.lt Shop API - integrate loyalty program functionality into POS systems and partner applications.
npm install @loyaltylt/sdk ably
# or
yarn add @loyaltylt/sdk ablyFor React components:
npm install @loyaltylt/sdk ably qrcode.reactimport { LoyaltySDK } from '@loyaltylt/sdk';
const sdk = new LoyaltySDK({
apiKey: 'lty_xxxxxxxxxxxx',
apiSecret: 'xxxxxxxxxxxx',
environment: 'production',
locale: 'lt'
});
const session = await sdk.generateQrCardSession('POS Terminal 1');
console.log('QR:', session.qr_code);
const subscription = await sdk.subscribeToQrCardScan(session.session_id, (cardData) => {
console.log('Customer:', cardData.user.name);
console.log('Points:', cardData.points);
});import { QRLogin } from '@loyaltylt/sdk/react';
import '@loyaltylt/sdk/styles';
function LoginPage() {
return (
<QRLogin
config={{
apiKey: process.env.NEXT_PUBLIC_SHOP_API_KEY,
apiSecret: process.env.NEXT_PUBLIC_SHOP_API_SECRET,
shopId: 4,
deviceName: 'My Shop'
}}
callbacks={{
onAuthenticated: (data) => {
console.log('User:', data.user);
console.log('Token:', data.token);
},
onScanned: () => console.log('QR scanned!'),
onError: (error) => console.error(error)
}}
texts={{
title: 'Login with Loyalty.lt',
subtitle: 'Scan QR code to login'
}}
showSendLink={true}
autoRegenerate={true}
/>
);
}import { QRCardDisplay } from '@loyaltylt/sdk/react';
import '@loyaltylt/sdk/styles';
function MyCard() {
return (
<QRCardDisplay
userToken={userJwtToken}
size={200}
showUserInfo={true}
showPoints={true}
autoRefresh={true}
refreshInterval={30000}
texts={{
points: 'Points',
scanToIdentify: 'Scan to identify'
}}
/>
);
}const sdk = new LoyaltySDK({
apiKey: 'lty_xxxxxxxxxxxx',
apiSecret: 'xxxxxxxxxxxx',
environment: 'production', // 'production' | 'staging'
locale: 'lt',
timeout: 30000
});const session = await sdk.generateQrCardSession('POS Terminal');
const subscription = await sdk.subscribeToQrCardScan(session.session_id, (cardData) => {
console.log('Card:', cardData.card_number);
console.log('Points:', cardData.points);
if (cardData.redemption?.enabled) {
const discount = Math.floor(cardData.points / cardData.redemption.points_per_currency)
* cardData.redemption.currency_amount;
console.log('Discount:', discount, 'EUR');
}
});
subscription.unsubscribe();const session = await sdk.generateQrLogin('Desktop');
const subscription = await sdk.subscribeToQrLogin(session.session_id, (message) => {
if (message.data.status === 'authenticated') {
console.log('Logged in:', message.data.user);
console.log('Token:', message.data.token);
}
});await sdk.sendAppLink('+37061234567', 4, 'Customer Name', 'lt');const transaction = await sdk.createTransaction({
card_number: '123-456-789',
amount: 50.00,
points_earned: 50
});const cards = await sdk.getLoyaltyCards({ page: 1, per_page: 10 });
const card = await sdk.getLoyaltyCardInfo({ card_number: '123-456-789' });
const balance = await sdk.getPointsBalance({ card_number: '123-456-789' });const offers = await sdk.getOffers({ is_active: true });
const offer = await sdk.createOffer({
title: 'New Offer',
description: 'Description',
points_required: 100
});
await sdk.updateOffer(offer.id, { title: 'Updated' });
await sdk.deleteOffer(offer.id);const shops = await sdk.getShops({ is_active: true, is_virtual: false });| Feature | Channel | Event |
|---|---|---|
| QR Login | qr-login:{session_id} |
status_update |
| QR Card Scan | qr-card:{session_id} |
card_identified |
import { LoyaltySDKError } from '@loyaltylt/sdk';
try {
await sdk.createTransaction({ ... });
} catch (error) {
if (error instanceof LoyaltySDKError) {
console.error('Error:', error.message);
console.error('Code:', error.code);
console.error('Status:', error.statusCode);
}
}- Production:
https://api.loyalty.lt - Staging:
https://staging-api.loyalty.lt
See /examples folder for:
pos-full-example.html- Full POS system with customer displayqr-card-scan-example.html- Simple QR card scanningbasic-usage.js- Node.js usage examples