azima / tamara
The package acts as a Laravel integration for the Tamara API, allowing developers to easily create sessions, handle payments, and manage webhooks in their applications.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/azima/tamara
README
tamara is a Laravel package designed to simplify the integration of the tamara API into your Laravel applications. It provides an easy-to-use interface for creating checkout sessions, handling payments, managing webhooks, and more.
Installation
You can install the package via Composer.
composer require azima/tamara
Publish your tamara config file with
php artisan vendor:publish --provider="Azima\Tamara\TamaraServiceProvider" --tag="tamara"
In your .env file, add the following configurations:
TAMARA_TOKEN= TAMARA_MODE= TAMARA_COUNTRY_CODE= TAMARA_CURRENCY=
Usage
Check payment available options
use Azima\Tamara\Tamara; $order = ['phone' => '00966511111', 'total' => 600]; $response = (new Tamara())->checkPaymentOptionsAvailability($order);
Create checkout order
use Azima\Tamara\Tamara; $order = ['order_num' => '123', 'total' => 500,'notes' => 'notes ', 'discount_name' => 'discount coupon','discount_amount' => 50,'vat_amount' => 50,'shipping_amount' => 20]; $products[0] = ['id' => '123','type' => 'mobiles' ,'name' => 'iphone','sku' => 'SA-12436','image_url' => 'https://example.com/image.png','quantity' => 1,'unit_price'=>50,'discount_amount' => 5,'tax_amount'=>10,'total' => 70]; $products[1] = ['id' => '345','type' => 'labtops' ,'name' => 'macbook air','sku' => 'SA-789','image_url' => 'https://example.com/image.png','quantity' => 1,'unit_price'=>200,'discount_amount' => 50,'tax_amount'=>100,'total' => 300]; $consumer = ['first_name' => 'mahmoud','last_name' => 'abd alziem' ,'phone' => '00966511111','email' => 'mbdalzym376@gmail.com']; $billing_address = ['first_name' => 'mahmoud','last_name' => 'abd alziem','line1' => 'mohamed alziem' ,'city' => 'mohamed alziem','phone' => '00966511111']; $shipping_address = ['first_name' => 'mahmoud','last_name' => 'abd alziem','line1' => 'mohamed alziem' ,'city' => 'mohamed alziem','phone' => '00966511111']; $urls = ['success' => 'http://yoursite/success','failure' => 'http://yoursite/failure','cancel' => 'http://yoursite/cancel','notification' => 'http://yoursite/notification']; $response = (new Tamara())->createCheckoutSession($order,$products,$consumer,$billing_address,$shipping_address,$urls); return redirect()->to($response['checkout_url']);
- urls array contain the callback urls for each status ['success' ,'failure','cancel','notification'] so that create route for each status
- if you passed route('tamara.result') in urls array success key then reponse will return in 'PaymentController@tamaraResult' function
- in routes.php put
Route::get('tamara-response', 'PaymentController@tamaraResult')->name('tamara.result');
- in controllers/PaymentController create callback function to check response
public function tamaraResult(Request $request) { if ($request->paymentStatus == 'approved') { //update order payment status return view('success_payment'); } else { return view('fail_payment'); } }
Get order details
use Azima\Tamara\Tamara; //use id that you used in createCheckoutSession function $order['order_num'] $response = (new Tamara())->getOrderDetails($orderId = '123');
Cancel order
use Azima\Tamara\Tamara; //get id from createCheckoutSession function response $order = ['id' => '9d7546e6-59e5-46ab-884c-9dbf95e2877c' ,'amount' => 100]; $response = (new Tamara())->cancelOrder($order);
