This package used to integrate with the new Knet payment portal
Here are a few short examples of what you can do:
Caution
Please note that this package is updated to work with the new Knet payment portal, and it's not compatible with the old
one, we removed the receipt system from the package that because it may conflict with your own system, so you can use
the KnetTransaction
model details to show your own receipt.
Note
The package now is under updating process, so please don't use it in production until we release the stable version.
add HasKnet
trait to the User model
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Asciisd\Knet\HasKnet;
class User extends Authenticatable {
use HasKnet;
}
user pay()
method
// $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');
After finished the payment you will redirect to /knet/response you can change that from config file to make your own handler
you can use pay()
method inside controller like this
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();
}
you can change your environment from local to production in case you want to make sure that everything is working fine,
to do that change .env
file like this
APP_ENV=local #or production
KENT_TRANSPORT_ID=
KENT_TRANSPORT_PASSWORD=
KENT_RESOURCE_KEY=
KNET_DEBUG=true #or false in production
You can install the bindings via Composer. Run the following command:
$ composer require asciisd/knet
this command will install ServiceProvider
, Configs
and views
php artisan knet:install
this command will knet assets
php artisan knet:publish
After the migration has been published you can create the knet_transactions
table by running the migrations:
php artisan migrate
This package provides a receipt system, but you should fill your identity details inside KnetServiceProvider
=>
$details
array
also you need to update your logo inside vendor
=> knet
public assets
Card Number | Expiry Date | PIN | Status |
---|---|---|---|
8888880000000001 | 09/25 | 1234 | CAPTURED |
8888880000000002 | 05/25 | 1234 | NOT CAPTURED |
You can add this code to EventServiceProvider
KnetTransactionCreated::class => [
// this event hold the new transaction instance
// you can get this transaction inside the listner by $event->transaction
];
KnetTransactionUpdated::class => [
// this event hold the updated transaction instance
// you can get this transaction inside the listner by $event->transaction
];
KnetResponseReceived::class => [
// this event hold the knet response array()
// you can get this payload inside the listner by $event->payload
];
KnetResponseHandled::class => [
// this event hold the knet response array()
// you can get this payload inside the listner by $event->payload
];
KnetReceiptSeen::class => [
// this event hold the knet Payment as $payment
];