A Laravel package for Thawani payment gateway integration.
jkbroot/thawani is a Laravel package for a laravel package for thawani payment gateway integration..
It currently has 3 GitHub stars and 2.705 downloads on Packagist (latest version 1.1.1).
Install it with composer require jkbroot/thawani.
Discover more Laravel packages by jkbroot
or browse all Laravel packages to compare alternatives.
Last updated

This Laravel package facilitates easy integration with the Thawani payment gateway, offering a straightforward and intuitive set of functionalities for payment session creation, customer management, and transaction handling, all within your Laravel application.
Requirements
composer require jkbroot/thawani
This package supports Package Auto-Discovery, which was introduced in Laravel 5.5. Therefore, it doesn't require manual registration of the ServiceProvider in most cases.
If you're using a version of Laravel where auto-discovery is not supported or have specifically disabled it, you need to register the ServiceProvider manually.
Add the ServiceProvider to the providers array in config/app.php:
'providers' => [
// Other Service Providers
Jkbroot\Thawani\ThawaniServiceProvider::class,
],
Configuration:
Publish the configuration file by running the following Artisan command. This will publish the Thawani configuration file to config/thawani.php, where you can customize your settings.
php artisan vendor:publish --tag=config
Copy the Thawani Pay configuration snippet you provided and paste it into your .env file. However,The THAWANI_MODE should be set to live instead of test for a production environment :
#Thawani Pay Configuration for Production Environment
THAWANI_LIVE_SECRET_KEY=your_thawani_live_secret_key
THAWANI_LIVE_PUBLISHABLE_KEY=your_thawani_live_publishable_key
#Thawani mode change to (live) for production.
THAWANI_MODE=test
Replace your_thawani_live_secret_key and your_thawani_live_publishable_key with your actual Thawani live secret and publishable keys.
To begin using the Thawani payment functionality, you need to instantiate the ThawaniPay class. Follow these steps:
Before you can create an instance of the ThawaniPay class, ensure that you import it into your PHP file using the use statement:
use Jkbroot\Thawani\ThawaniPay;
Once the class is imported, you can instantiate it using the following code:
$thawani = new ThawaniPay();
This creates an instance of the ThawaniPay class, allowing you to utilize its methods and properties for handling Thawani payments within your Laravel application.
Additional Notes
use Jkbroot\Thawani\ThawaniPay;
$thawani = new ThawaniPay();
$data = [
"client_reference_id" => "123412",
"mode" => "payment",
"products" => [
[
"name" => "product 1",
"quantity" => 1,
"unit_amount" => 100,
],
],
"success_url" => "https://company.com/success",
"cancel_url" => "https://company.com/cancel",
"metadata" => [
"Customer name" => "somename",
"order id" => 0,
],
];
$session = $thawani->checkoutSessions->create($data);
Create session Response :
[
"success" => true
"code" => 2004
"description" => "Session generated successfully"
"data" => array:16 [
"mode" => "payment"
"session_id" => "checkout_0Cp4idrQaNFMws8YFJH020FJA3I4ITwkvmk2RxUc9Les5kY3ym"
"client_reference_id" => "123412"
"customer_id" => null
"products" => [
0 => [
"name" => "product 1"
"unit_amount" => 100
"quantity" => 1
]
]
"total_amount" => 100
"currency" => "OMR"
"success_url" => "https://company.com/success"
"cancel_url" => "https://company.com/cancel"
"return_url" => null
"payment_status" => "unpaid"
"invoice" => "20240228270008"
"save_card_on_success" => false
"metadata" => [
"Customer name" => "somename"
"order id" => "0"
]
"created_at" => "2024-02-28T15:19:35.2937785Z"
"expire_at" => "2024-02-29T15:19:35.2204113Z"
]
]
$session_id = "checkout_0Cp4idrQaNFMws8YFJH020FJA3I4ITwkvmk2RxUc9Les5kY3ym";
$session = $thawani->checkoutSessions->retrieve($session_id);
Retrieve session Response :
[
"success" => true
"code" => 2000
"description" => "session retrieved successfully"
"data" => [
"mode" => "payment"
"session_id" => "checkout_0Cp4idrQaNFMws8YFJH020FJA3I4ITwkvmk2RxUc9Les5kY3ym"
"client_reference_id" => "123412"
"customer_id" => null
"products" => [
0 => [
"name" => "product 1"
"unit_amount" => 100
"quantity" => 1
]
]
"total_amount" => 100
"currency" => "OMR"
"success_url" => "https://company.com/success"
"cancel_url" => "https://company.com/cancel"
"return_url" => null
"payment_status" => "unpaid"
"invoice" => "20240228270008"
"save_card_on_success" => false
"metadata" =>[
"Customer name" => "somename"
"order id" => "0"
]
"created_at" => "2024-02-28T15:19:35.2937785"
"expire_at" => "2024-02-29T15:19:35.2204113"
]
]
$session_id = "checkout_0Cp4idrQaNFMws8YFJH020FJA3I4ITwkvmk2RxUc9Les5kY3ym";
$session = $thawani->checkoutSessions->cancel($session_id);
Cancel session Response :
[
"success" => true
"code" => 2105
"description" => "Checkout session cancelled successfully"
]
$sessions = $thawani->checkoutSessions->list();
//for limit the lists and paginate between lists (limit,skip)
$sessions = $thawani->checkoutSessions->list(10,0);
list Sessions Response :
[
"success" => true
"code" => 2000
"description" => "sessions retrieved successfully"
"data" => [/*'array off Sessions'*/]
]
$data = [
"client_reference_id" => "123412",
"mode" => "payment",
"products" => [
[
"name" => "product 1",
"quantity" => 1,
"unit_amount" => 100,
],
],
"success_url" => "https://company.com/success",
"cancel_url" => "https://company.com/cancel",
"metadata" => [
"Customer name" => "somename",
"order id" => 0,
],
];
$checkoutUrl = $thawani->checkoutSessions->createCheckoutUrl($data);
[
"session_id" => "checkout_5Q3IPYhiWaOIDotTqHJMjtaklHoHeWTjT6iTPaT0kQSTSZF3Za"
"redirect_url" => "https://uatcheckout.thawani.om/pay/checkout_5Q3IPYhiWaOIDotTqHJMjtaklHoHeWTjT6iTPaT0kQSTSZF3Za?key=HGvTMLDssJghr9tlN9gr4DVYt0qyBy"
]
$data = [
"client_customer_id" => "[email protected]"
];
$customer = $thawani->customers->create($data);
[
"success" => true
"code" => 2001
"description" => "Customer added successfully"
"data" =>[
"id" => "cus_pbW3HE7eG81zRvJX"
"customer_client_id" => "[email protected]"
]
]
$customerId = 'cus_pbW3HE7eG81zRvJX';
$customer = $thawani->customers->retrieve($customerId);
[
"success" => true
"code" => 2000
"description" => "Customers retrieved successfully"
"data" => [
"id" => "cus_pbW3HE7eG81zRvJX"
"customer_client_id" => "[email protected]"
]
]
$customerId = 'cus_pbW3HE7eG81zRvJX';
$customer = $thawani->customers->delete($customerId);
$customers = $thawani->customers->list();
//for limit the lists and paginate between lists (limit,skip)
$customers = $thawani->customers->list(10,0);
$paymentIntents = $thawani->paymentIntents->list();
//for limit the lists and paginate between lists (limit,skip)
$paymentIntents = $thawani->paymentIntents->list(10,0);
[
"success" => true
"code" => 2000
"description" => "sessions retrieved successfully"
"data" => [/*'array off Payment intents'*/]
]
$data = [
"amount" => 100,
"payment_method" => "card_zK5a7sd98wdwe78TbiSUyLUjann6xFx",
"description" => "Payment for order 123412",
"client_reference_id" => "123412",
"return_url" => "https://thw.om/success",
"metadata" => [
"Customer name" => "somename",
],
];
$paymentIntent = $thawani->paymentIntents->create($data);
{
"success": true,
"code": 0,
"description": "string",
"data": {
"id": "string",
"client_reference_id": "string",
"amount": 0,
"currency": "string",
"payment_method": "string",
"next_action": {
"url": "string",
"return_url": "string"
},
"status": "requires_payment_method",
"metadata": {},
"created_at": "2019-08-24T14:15:22Z",
"expire_at": "2019-08-24T14:15:22Z"
}
}
create: Initializes a new payment session.retrieve: Fetches details of a specific session.cancel: Cancels an existing session.list: Lists all sessions with optional pagination.createCheckoutUrl: Generates a URL for the payment checkout page.retrieveByClientReference: Retrieves a session using a client-provided reference ID.retrieveByInvoice: Retrieves a session using an invoice number.create: Registers a new customer in the payment system.retrieve: Retrieves information about a specific customer.delete: Removes a customer from the system.list: Lists all customers with optional pagination.create: Creates a payment intent to initiate a transaction.retrieve: Fetches details of a specific payment intent.cancel: Cancels an unresolved payment intent.list: Lists payment intents with optional pagination.confirm: Confirms a payment intent, attempting to finalize the transaction.list: Lists all payment methods associated with a given customer ID.delete: Deletes a specified payment method from a customer's account.create: Initiates a refund for a specific transaction.retrieve: Retrieves details of a specific refund.list: Lists all refunds with optional pagination.This overview provides a quick guide to the functionalities available in your Laravel package for integrating Thawani payment services.