PHP code example of azima / tamara

1. Go to this page and download the library: Download azima/tamara 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/ */

    

azima / tamara example snippets


use Azima\Tamara\Tamara;

        $order = ['phone' => '00966511111', 'total' => 600];
        $response = (new Tamara())->checkPaymentOptionsAvailability($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' => '[email protected]'];
        $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']);


    Route::get('tamara-response', 'PaymentController@tamaraResult')->name('tamara.result');



    public function tamaraResult(Request $request)
    {
        if ($request->paymentStatus == 'approved') {
        	//update order payment status
            return view('success_payment');
        } else {
            return view('fail_payment');
        }
    }


use Azima\Tamara\Tamara;

        //use id that you used in createCheckoutSession function $order['order_num']
        $response = (new Tamara())->getOrderDetails($orderId = '123');


use Azima\Tamara\Tamara;

        //get id from createCheckoutSession function response
        $order = ['id' => '9d7546e6-59e5-46ab-884c-9dbf95e2877c' ,'amount' => 100];
        $response = (new Tamara())->cancelOrder($order);

bash
php artisan vendor:publish --provider="Azima\Tamara\TamaraServiceProvider" --tag="tamara"