How to connect Lekhya to production GST APIs through a GSP gateway for e-invoicing, GSTIN validation, GSTR filing, and more.
Lekhya NEVER calls GST APIs directly. All calls go through a GstGateway interface. This lets you swap between the mock gateway (for testing) and a real GSP gateway (for production) by changing one line in config. You are never locked to a specific GSP provider.
Mandatory intermediary to access NIC/GSTN APIs. Examples: Karvy, Masters India, ClearTax, IRIS, Mastercard, E2I. Your company must register with one.
Free API via GST portal. Validates GSTIN format + returns legal name, trade name, status, registration date.
Available through GSP. Required if annual turnover > ₹5 crore (threshold configurable in Lekhya settings).
Available through GSP. For movement of goods > ₹50,000. Auto-generated when e-invoice is created.
File monthly/quarterly outward supply return via GSP or GST portal APIs.
Pull auto-drafted ITC statement from GSTN via GSP. Used for GSTR-2B reconciliation.
Register your business with a GSP. Popular options:
| GSP | Website | Best For | Pricing |
|---|---|---|---|
| Masters India | mastersindia.co | SME & Enterprise | ₹1-3/IRN |
| ClearTax | cleartax.in | CA Firms, Mid-Market | ₹2-4/IRN |
| IRIS Business | irisgst.com | Enterprise | Volume pricing |
| Karvy Computershare | karvy.com | Large Enterprise | Custom |
| E2I Technologies | e2i.in | SME | ₹1-2/IRN |
# In lekhya-app/.env
GST_DRIVER=masters_india # or: cleartax | iris | karvy | mock
GST_CLIENT_ID=your-client-id
GST_CLIENT_SECRET=your-client-secret
GST_USERNAME=your-gstn-username
GST_PASSWORD=your-gstn-password
# E-invoice threshold (turnover in crores)
GST_EINVOICE_THRESHOLD_CRORE=5
# GSP base URLs (example: Masters India)
GST_API_BASE=https://api.mastersindia.co/mastersindia
GST_AUTH_URL=https://api.mastersindia.co/oauth/token
Create a new class implementing the GstGateway interface for your GSP:
// app/Services/GST/MastersIndiaGateway.php
class MastersIndiaGateway implements GstGateway {
private string $accessToken;
public function generateIrn(array $payload): array {
$token = $this->getAccessToken();
$response = Http::withToken($token)
->post(config('services.gst.base') . '/einvoice/generate', [
'gstin' => config('services.gst.gstin'),
'payload' => $payload,
]);
return $response->json();
}
// ... implement all GstGateway methods
}
Then register in AppServiceProvider::register():
$this->app->singleton(GstGateway::class, function () {
return match(config('services.gst.driver')) {
'masters_india' => new MastersIndiaGateway(),
'cleartax' => new CleartaxGateway(),
default => new MockGstGateway(),
};
});
/gst/validate-gstin?gstin=29ABCDE1234F1Z5
Validates format + checksum + live status from GSTN
/gst/e-invoice/{invoice}/generate
Builds e-invoice JSON, calls GSP, stores IRN + QR
/gst/eway-bill/{invoice}/generate
Auto-creates EWB from invoice data
/gst/gstr1/generate
Aggregates posted invoices into GSTR-1 JSON format
/gst/gstr1/file
Pushes GSTR-1 JSON to GSTN via GSP. Returns ARN.
/gst/gstr2b/import
Upload 2B JSON from GST portal → stored for reconciliation
/gst/gstr2b/reconcile
Match purchase invoices vs 2B. Flag mismatches.
# Use mock gateway (default in development)
GST_DRIVER=mock
# For GSP sandbox (if your GSP provides one)
GST_DRIVER=masters_india
GST_API_BASE=https://sandbox-api.mastersindia.co
# Run e-invoice generation test
php artisan gst:test-irn --invoice=1