🇮🇷 Comprehensive Guide to Iran-Specific Features
The Next-Strapi-Medusa project provides native, production-grade support for Iranian e-commerce infrastructure. By enabling the ENABLE_IRAN_FEATURES=true flag, mobile number login and SMS OTP, Shetab/Shaparak bank gateways (Zarinpal), live Iran Post shipping rate calculation, and Toman pricing conversions are activated without modifying the Medusa core.
Native Support Without Modifying Medusa Core
1. Global ENABLE_IRAN_FEATURES Flag
To activate all Iran-specific features across the entire stack (Medusa backend, Strapi CMS, and Next.js Storefront), set the following variables in your .env and docker-compose.yml files:
ENABLE_IRAN_FEATURES=trueNEXT_PUBLIC_ENABLE_IRAN_FEATURES=trueDEFAULT_REGION=IRDEFAULT_LOCALE=fa-IR2. Mobile Number & SMS OTP Login (Phone Auth & OTP)
The dedicated phone authentication module is implemented under store-admin/src/modules/auth/providers/otp. It normalizes Iranian phone numbers, generates secure 4-6 digit temporary verification codes, and incorporates rate limiting.
- Multiple format support: Automatically accepts
0912xxxxxxxand+98912xxxxxxx. - Countdown timer & rate limiting: Prevents repeated SMS requests with a 120-second cooldown.
- Auto Registration: Automatically creates a customer account for newly verified phone numbers.
{ resolve: "./src/modules/auth/providers/otp", id: "phone-auth", options: { jwtSecret: process.env.JWT_SECRET, },}3. Iranian SMS Gateways (Kavenegar & SMS.ir)
The SMS dispatch service supports fast pattern webhooks (service lines) to deliver verification codes in under 5 seconds, even to advertising-blocked numbers:
# Provider: sms-ir or kavenegarSMS_PROVIDER=sms-irSMS_API_KEY=your_sms_ir_api_keySMS_OTP_TEMPLATE_ID=100000 # Verification pattern template IDSMS_ORDER_PLACED_TEMPLATE_ID=200000 # Order confirmation pattern template ID4. Zarinpal Online Payment Gateway
The Zarinpal module integrates directly into Medusa's Payment Sessions system, enabling transactions via Shetab debit cards with test mode (Sandbox) support:
ZARINPAL_MERCHANT_ID=your-merchant-id-xxxx-xxxxZARINPAL_SANDBOX=false # Set to true in development5. Live Iran Post Rate Calculation (Iran Post Fulfillment)
The medusa-fulfillment-iran-post plugin dynamically calculates express (Pishtaz) and standard (Sefareshi) postal rates during checkout based on origin, destination province, and parcel weight, supporting 24-digit tracking codes in the order dashboard.
{ resolve: "./src/modules/fulfillment/providers/iran-post", id: "iran-post", options: { originProvince: "تهران", originCity: "تهران", defaultPackagingWeight: 150, // گرم },}6. Automatic Currency Conversion to Toman (convertToToman)
Prices are stored in Rials inside Medusa database for Shaparak compliance. In Strapi, enabling the convertToToman option in Storefront Settings removes a zero and formats numbers with thousand separators in Toman on the frontend.
export function formatPrice(amount: number, currencyCode: string, convertToToman = false) { if (currencyCode.toLowerCase() === 'irr' && convertToToman) { const tomanAmount = Math.round(amount / 10); return `${new Intl.NumberFormat('fa-IR').format(tomanAmount)} تومان`; } return new Intl.NumberFormat('fa-IR', { style: 'currency', currency: currencyCode }).format(amount);}