Thawani: General PHP Class

This class is for developers who want to integrate with Thawani Gateway.

To get started, you need to clone the class:

git clone https://github.com/phpawcom/thawani-php-class.git

Or download it by clicking here.

Usage

Call the class:

<?php
include_once(__DIR__.'/thawani.php');
$thawani = new \s4d\payment\thawani([  
  'isTestMode' => 1, ## set it to 0 to use the class in production mode  
  'public_key' => 'HGvTMLDssJghr9tlN9gr4DVYt0qyBy',  
  'private_key' => 'rRQ26GcsZzoEhbrP2HZvLYDbn9C9et',  
]);

To get API keys for UAT environments, you can find them in developer documentation. For production keys, you can refer to Thawani: Getting API Keys.

Generate Payment URL:

$url = $thawani->generatePaymentUrl([  
  'client_reference_id' => rand(1000, 9999).$orderId, ## generating random 4 digits prefix to make sure there will be no duplicate ID error  
  'products' => [  
     ['name' => 'test test test test test test test test test test test test ', 'unit_amount' => 100, 'quantity' => 1],  
     ['name' => 'test', 'unit_amount' => 100, 'quantity' => 1],  
   ],
  'success_url' => $thawani->currentPageUrl().'?op=checkPayment', ## Put the link to next a page with the method checkPaymentStatus()
  'cancel_url' => $thawani->currentPageUrl().'?op=checkPayment',  
  'metadata' => [  
  'order_id' => $orderId  
  ]  
 ]);
 if(!empty($url)){  
  ## method will provide you with a payment id from Thawani, you should save it to your order. You can get it using this: $thawani->payment_id  
  ## header('location: '.$url); ## Redirect to payment page  
  $_SESSION['session_id'] = $thawani->payment_id; ## save session_id to use to check payment status later
  echo '<a href="'.$url.'">Click to Pay</a>';  
}

Check Payment Status:

$check = $thawani->checkPaymentStatus($_SESSION['session_id']);  
if($thawani->payment_status == 1){  
  ## successful payment  
  echo '<h2>successful payment</h2>';  
}else{  
  ## failed payment  
  echo '<h2>payment failed</h2>';  
}

You can view example.php for more examples.

  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

Downloads and Licenses

In this article, will show how to use the licenses and download purchased plugins. After a...

Thawani: Getting API Keys

Using your login credentials in Thawani Merchant portal, you will need to go to: Developers ->...

Thawani: OpenCart Extension

This article is to show how to install our OpenCart extension for Thawani Gateway. First you will...

Thawani: PMPRO (WordPress) Plugin

This article is to show how to install our WordPress Membership Plugin and Subscriptions Platform...

Thawani: WHMCS Module

This article is to show how to install our OpenCart extension for Thawani Gateway. First you will...