Search by

msitxpress / gateway

msitxpress

Laravel client for the Ms IT Xpress API: SMS, OTP, AI, Social and wallet.

v1.0.1 2026-12-03 10:46 UTC

This package is not auto-updated.

Last update: 2026-12-04 09:05:15 UTC


README

The official Laravel client for the Ms IT Xpress API: SMS, OTP, AI, Social (Facebook, Instagram, WhatsApp) and your wallet, paid from one balance in BDT.

use MsITXpress\Gateway\Facades\XpressGateway;

XpressGateway::sms()->send('01711000000', 'আপনার অর্ডার কনফার্ম হয়েছে');
XpressGateway::otp()->send('01711000000', brand: 'MyShop');
XpressGateway::otp()->check('01711000000', $request->code);   // true or false
XpressGateway::ai()->ask('Write a caption for a red saree');
XpressGateway::wallet()->balance();                             // ['balance' => 1520.5, ...]

Install

Requires PHP 8.2+ and Laravel 11, 12 or 13.

composer require msitxpress/gateway

Create an API key at portal.msitxpress.com and add it to .env:

MSITXPRESS_API_KEY=msitx_live_...
# Optional
MSITXPRESS_SMS_SENDER_ID=MYSHOP
MSITXPRESS_AI_MODEL=gpt-4.1-mini

A msitx_test_... key costs nothing and returns canned replies (an OTP test key also returns the code), so you can build against it safely.

To change the defaults: php artisan vendor:publish --tag=msitxpress-config.

SMS

$batch = XpressGateway::sms()->send(['01711000000', '01811000000'], 'Sale starts today!');
// ['batch_id' => ..., 'cost' => 0.5, 'invalid' => [], 'messages' => [['id' => ..., 'to' => ...]]]

XpressGateway::sms()->status($batch['messages'][0]['id']);   // queued, sent, delivered or failed

Each call sends an Idempotency-Key, so a retry never sends the message twice. Pass your own key (for example the order id) to keep it stable across jobs:

XpressGateway::sms()->send($order->phone, $text, idempotencyKey: "order-{$order->id}-shipped");

As a notification

use MsITXpress\Gateway\Notifications\SmsMessage;

class OrderShipped extends Notification
{
    public function via($notifiable): array
    {
        return ['msitxpress'];
    }

    public function toMsitxpress($notifiable): SmsMessage|string
    {
        return SmsMessage::create("Order #{$this->order->id} is on the way.");
    }
}

The number comes from routeNotificationForMsitxpress() on the notifiable, otherwise its phone attribute.

OTP

We make, send and check the code; you never store it.

$otp = XpressGateway::otp()->send('01711000000', brand: 'MyShop');

if (XpressGateway::otp()->check('01711000000', $request->code, $otp['otp_id'])) {
    // verified
}

AI

Requests and replies follow OpenAI's shape, so existing code ports easily.

XpressGateway::ai()->ask('Summarise this review', system: 'Answer in Bangla');

XpressGateway::ai()->chat([
    ['role' => 'system', 'content' => 'You are a helpful shop assistant.'],
    ['role' => 'user', 'content' => 'Do you deliver to Sylhet?'],
], ['max_tokens' => 300]);

XpressGateway::ai()->responses('Hello', ['instructions' => 'Be brief']);

// Ready-made writing: caption, description, product_copy, seo_meta, rewrite
XpressGateway::ai()->content('product_copy', 'Cotton saree, red, 6 yards', ['language' => 'bn', 'variants' => 3]);

// Images run in the background
$job = XpressGateway::ai()->generateImage('A red saree on a white background', ['size' => '1024x1024']);
XpressGateway::ai()->image($job['id']);   // poll until status is completed

// Realtime voice from the browser's WebRTC offer
$call = XpressGateway::ai()->startVoice($sdpOffer, ['voice' => 'alloy'], maxSeconds: 120);
XpressGateway::ai()->endVoice($call['id'], usedSeconds: 47);

Social

Connect Facebook pages, Instagram and WhatsApp through our Meta app. Page tokens stay with us; you call the Graph API through the connection.

// 1. Once: where we send events, and where the owner lands after connecting.
$endpoint = XpressGateway::social()->endpoint('My shop', route('meta.webhook'), route('social.connected'));
// Save $endpoint['secret'] as MSITXPRESS_WEBHOOK_SECRET (shown only on create or rotate).

// 2. Send the page owner to this link.
$link = XpressGateway::social()->connect($endpoint['id'], posting: true);
return redirect($link['url']);

// 3. Use the connected pages.
foreach (XpressGateway::social()->connections() as $page) { /* ... */ }

XpressGateway::social()->graph($connectionId, 'POST', 'me/messages', [
    'recipient' => ['id' => $psid],
    'message' => ['text' => 'Thanks for your message!'],
], bot: true);

XpressGateway::social()->media($connectionId, $mediaId)->body();   // a photo or voice note a customer sent

Billing: plans() (no key needed), billing(), quote(), subscribe(), startTrial(), autoRenew(), payAsYouGo().

Webhooks

Events are signed like Meta's (X-Hub-Signature-256). Protect the route with the bundled middleware:

Route::post('/meta/webhook', MetaWebhookController::class)->middleware('msitxpress.webhook');

X-Msx-Event carries the event id, so you can ignore a redelivery.

Wallet

XpressGateway::wallet()->balance();
XpressGateway::wallet()->usage(from: '2026-12-01', to: '2026-12-31', service: 'sms');
XpressGateway::wallet()->transactions(page: 1);
XpressGateway::wallet()->rechargeMethods();
XpressGateway::wallet()->recharge('bkash', 500, '01711000000', 'TRX8A7B6C5');

Errors

Every API error is a MsITXpress\Gateway\Exceptions\GatewayException with $status, $type, $context and $requestId, or one of its subclasses:

Exception Status When
AuthenticationException 401 Wrong or missing key
InsufficientBalanceException 402 Recharge needed; balance(), required()
PermissionDeniedException 403 Account suspended or service not active
NotFoundException 404 Not on this account
ConflictException 409 Conflicts with the current state
ValidationException 422 Bad input; errors()
RateLimitException 429 Too fast, or the daily limit is reached
ServerException 5xx Our side or the provider; nothing is charged on a 503

ConnectionException means we could not be reached, and ConfigurationException that the key is missing. All of them extend MsITXpressException.

try {
    XpressGateway::sms()->send($phone, $text);
} catch (InsufficientBalanceException $e) {
    report("Recharge needed: {$e->balance()} BDT left");
}

Testing your app

XpressGateway::fake();                                           // nothing leaves your app
XpressGateway::fake(['otp/verify' => ['verified' => false]]);    // or choose the reply

// ...run your code...

XpressGateway::assertSmsSent(fn (array $sms) => $sms['to'] === '01711000000');
XpressGateway::assertSmsSentTimes(1);
XpressGateway::assertOtpSent('01711000000');
XpressGateway::assertNotSent('chat/completions');
XpressGateway::assertNothingSent();

Local development

Point every service at one host, for example a local gateway:

MSITXPRESS_URL=http://gateway.test/api/v1

Security

Report vulnerabilities to info@msitxpress.com, not in a public issue.

License

MIT. See LICENSE.