PHP code example of behzadbabaei / omnipay-thawani

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

    

behzadbabaei / omnipay-thawani example snippets


    use Omnipay\Omnipay;


            $gateway = Omnipay::create('Thawani');
            $gateway->setPublishKey('publish-key');
            $gateway->setSecretKey('secret-key');
            $gateway->setTestMode(true-false);



            $purchase = $gateway->purchase();
            $purchase->setAmount(12000);
            $purchase->setQuantity(1);
            $purchase->setProductName("product name test1"); //Product name is uccess'); //The success url is  customer is => $data['customerName'] ?? null,// user full name
            ]);

            $result = $purchase->send();
            $response = $result->getData();
            $redirectUrl = $result->getRedirectUrl();


            $result = $gateway->purchase([
                'amount' => 12000,
                'quantity' => 1,
                'productName' => 'product name test2',
                'transactionId' => $data['transactionId'],
                'customerId' => '',
                'returnUrl' => 'https://www.example.com/thawani/success',
                'cancelUrl' => 'https://www.example.com/thawani/cancel',
                'saveCardOnSuccess' => false,
                'planId' => '',
                'metadata' => [
                    'orderId' => $data['transactionId'],
                    'customerId' => $data['customerId'] ?? null,
                    'customerEmail' => $data['customerEmail'] ?? null,
                    'customerName' => $data['customerName'] ?? null,// user full name
                ]
            ])->send();

            $response = $result->getData();
            $redirectUrl = $result->getRedirectUrl();



            $fetch = $gateway->fetchTransaction();
            $fetch->setOrderId($orderId);
            $result = $fetch->send()->getData();



            $fetch = $gateway->fetchTransaction(
                [
                    'orderId' => $orderId
                ]
            );
            $result = $fetch->send()->getData();