PHP code example of jkbroot / thawani

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

    

jkbroot / thawani example snippets



'providers' => [
    // Other Service Providers

    Jkbroot\Thawani\ThawaniServiceProvider::class,
],


use Jkbroot\Thawani\ThawaniPay;

$thawani = new ThawaniPay();

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);


[
    "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);

[
  "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);

[
  "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);


[
  "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": "
bash
php artisan vendor:publish --tag=config