/** * Rental flow: check availability, rent a number for extended use, extend it, * then cancel within the refund window if you no longer need it. * * Two tiers, same refund terms (full refund within 20 min, before first SMS): * - "full_access": local SIM inventory, usable for any service. * - "platform": sourced via the global supplier network, one service * per number, 24/72/168h durations only. * * Run with: npx tsx examples/rental.ts */ import { VirtualSMS } from '../src'; async function main() { const apiKey = process.env.VIRTUALSMS_API_KEY; if (!apiKey) throw new Error('Set VIRTUALSMS_API_KEY — get one at https://virtualsms.io'); const client = new VirtualSMS(apiKey); // 1. See what's available. const availability = await client.rentalsAvailable({ country: 'US', tier: 'full_access' }); console.log(`${availability.total_available} countries available for full_access rentals`); // 2. Create a 24h full-access rental for WhatsApp in the US. const rental = await client.createRental({ tier: 'full_access', country: 'US', duration_hours: 24, service: 'whatsapp', }); console.log(`Rented ${rental.phone_number} (rental ${rental.rental_id}), expires ${rental.expires_at}`); // 3. Check on it later. const status = await client.getRental(rental.rental_id); console.log('Current status:', status?.status); // 4. Extend it if you need more time (charged at current catalog price). // const extended = await client.extendRental(rental.rental_id, 24); // 5. Cancel for a full refund — only within 20 minutes of purchase and // before the first SMS arrives. // const cancelled = await client.cancelRental(rental.rental_id); } main().catch((err) => { console.error(err.message); process.exit(1); });