1. Go to this page and download the library: Download phpawcom/thawani_laravel 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/ */
// To generate payment URL and redirect to Thawani
Route::get('pay', [\App\Http\Controllers\TestThawaniController::class, 'pay'])->name('thawani.pay');
// To check payment and update the status
Route::get('check/{session_id?}', [\App\Http\Controllers\TestThawaniController::class, 'check'])->name('thawani.check');
// To show cancellation message
Route::get('cancel/{session_id?}', [\App\Http\Controllers\TestThawaniController::class, 'cancel'])->name('thawani.cancel');
namespace App\Http\Controllers;
use S4D\Laravel\Thawani\Thawani;
class TestThawaniController extends Controller
{
public function pay(){
// Note that we use Routes names in setReturnUrls() method
Thawani::setClientReference(1)->setReturnUrls('thawani.check', 'thawani.cancel')->setProducts([
['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],
])->setMetadata([
'customer_name' => 'Fulan Al Fulani',
'customer_phone' => '90000000',
'customer_email' => '[email protected]',
])->redirectToPayment();
}
public function check($session_id){
return Response('Payment is '.(Thawani::paymentStatus($session_id) == 1? 'successful' : 'failed'));
}
public function cancel($session_id){
Thawani::cancelPayment($session_id);
return Response('has been cancelled');
}
}
$url = Thawani::setClientReference(1)->setReturnUrls('thawani.check', 'thawani.cancel')->setProducts([
['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],
])->setMetadata([
'customer_name' => 'Fulan Al Fulani',
'customer_phone' => '90000000',
'customer_email' => '[email protected]',
])->getPaymentUrl();