1. Go to this page and download the library: Download asciisd/knet 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/ */
asciisd / knet example snippets
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Asciisd\Knet\HasKnet;
class User extends Authenticatable {
use HasKnet;
}
// $transaction is the transaction instance from your own system, it could be anything
$payable = $transaction->user ?? auth()->user();
try {
$payment = $payable->pay($transaction->amount, [
'trackid' => $transaction->reference,
'udf1' => $payable->name,
'udf2' => $payable->email,
'udf3' => $payable->phone,
]);
} catch (\Asciisd\Knet\Exceptions\KnetException $e) {
logger()->error($e->getMessage());
} catch (\Asciisd\Knet\Exceptions\PaymentActionRequired $e) {
// Update transaction with knet transaction id
$transaction->forceFill([
'transactional_id' => $e->payment->id,
'transactional_type' => KnetTransaction::class,
])->save();
return $e->payment->actionUrl();
}
return view('transactions.create')->withErrors('message', 'Payment failed');
try{
$payment = request()->user()->pay(request()->amount, [
'udf1' => request()->user()->name,
'udf2' => request()->user()->email
]);
} catch(\Asciisd\Knet\Exceptions\PaymentActionRequired $exception) {
// do whatever you want with this
$payment = $exception->payment;
} finally {
// redirect user to payment url to complete the payment
return $payment->actionUrl();
}
bash
php artisan knet:install
bash
php artisan knet:publish
bash
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.