1. Go to this page and download the library: Download mustafataj/tabby-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mustafataj / tabby-laravel example snippets
use MustafaTaj\Tabby\Facades\Tabby;
use MustafaTaj\Tabby\Data\Buyer;
use MustafaTaj\Tabby\Data\SessionRequest;
$result = Tabby::checkout()->checkEligibility(new SessionRequest(
amount: '340.00',
currency: 'SAR',
buyer: new Buyer(email: '[email protected]', phone: '500000001'),
));
if ($result->isEligible()) {
// Show Tabby at checkout
}
use MustafaTaj\Tabby\Data\Buyer;
use MustafaTaj\Tabby\Data\BuyerHistory;
use MustafaTaj\Tabby\Data\MerchantUrls;
use MustafaTaj\Tabby\Data\Order;
use MustafaTaj\Tabby\Data\OrderHistory;
use MustafaTaj\Tabby\Data\OrderItem;
use MustafaTaj\Tabby\Data\SessionRequest;
use MustafaTaj\Tabby\Facades\Tabby;
$session = Tabby::checkout()->createSession(new SessionRequest(
amount: '340.00',
currency: 'SAR',
buyer: new Buyer(
email: '[email protected]',
phone: '500000001',
name: 'Jane Doe',
),
order: new Order(
referenceId: (string) $order->id,
items: [
new OrderItem(title: 'Product', quantity: 1, unitPrice: '340.00', category: 'general'),
],
),
merchantUrls: new MerchantUrls(
success: route('checkout.success'),
cancel: route('checkout.cancel'),
failure: route('checkout.failure'),
),
// Optional — improves approval rates when available
buyerHistory: new BuyerHistory(
registeredSince: $customer->created_at->toIso8601String(),
loyaltyLevel: 1,
isPhoneNumberVerified: true,
isEmailVerified: true,
),
orderHistory: [
new OrderHistory(
purchasedAt: '2025-01-15T10:00:00+03:00',
amount: '150.00',
status: 'complete',
paymentMethod: 'card',
buyer: new Buyer(email: '[email protected]', phone: '500000001', name: 'Jane Doe'),
items: [
new OrderItem(title: 'Previous item', quantity: 1, unitPrice: '150.00'),
],
),
],
));
// Persist $session->paymentId against your order, then redirect:
return redirect()->away($session->webUrl);
$payment = Tabby::payments()->verifyAndCapture($paymentId);
if ($payment->isClosed() || $payment->isAuthorized()) {
// Fulfill order
}
use MustafaTaj\Tabby\Events\PaymentAuthorized;
use MustafaTaj\Tabby\Events\PaymentClosed;
use MustafaTaj\Tabby\Events\PaymentRejected;
use MustafaTaj\Tabby\Events\PaymentExpired;
use MustafaTaj\Tabby\Events\PaymentRefunded;