1. Go to this page and download the library: Download tabbyai/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/ */
tabbyai / laravel example snippets
use Tabby\Services\TabbyService;
$tabbyService = new TabbyService(
merchantCode: 'your_merchant_code',
publicKey: 'your_public_key',
secretKey: 'your_secret_key',
currency: 'SAR' // Optional, default is SAR
);
use Tabby\Models\Buyer;
use Tabby\Models\Order;
use Tabby\Models\ShippingAddress;
use Tabby\Models\OrderItem;
try {
// Sample buyer data
$buyer = new Buyer(
phone: '500000001',
email: '[email protected]',
name: 'John Doe',
dob: '1990-01-01',
);
// Sample order data
$order = new Order(
referenceId: 'order-001',
items: [
new OrderItem(
title: 'Product Name',
category: 'electronics',
unitPrice: 100,
quantity: 1,
referenceId: 'prod-001',
description: 'Product Description',
),
],
);
// Sample shipping address data
$shippingAddress = new ShippingAddress(
city: 'Al-Khobar',
address: 'Street Address',
zip: '12345',
);
// Create a checkout session
$checkoutSession = $tabbyService->createSession(
amount: 200,
buyer: $buyer,
order: $order,
shippingAddress: $shippingAddress,
description: 'order description',
successCallback: 'https://example.com/success',
cancelCallback: 'https://example.com/cancel',
failureCallback: 'https://example.com/failure',
// lang: 'ar', // optional
// buyerHistory: $buyerHistory, // optional
// orderHistory: $orderHistory, // optional
);
// Fetch the payment url from the checkout session
$paymentUrl = $checkoutSession->getPaymentUrl();
// Redirect to the payment page
return redirect($paymentUrl);
} catch (Exception $e) {
// Handle exceptions
return response()->json(['error' => $e->getMessage()], 500);
}