asciisd/knet
Laravel KNET Payment Integration
A robust Laravel package for integrating KNET payment gateway services in your applications. This package provides a clean and elegant way to handle payment processing, refunds, and transaction management with KNET.
Features
- 🔒 Secure payment processing
- 💳 Transaction management
- 🔄 Payment status inquiries
- ↩️ Refund processing
- 🎯 Event-driven architecture
- 📝 Detailed transaction logging
- 🛡️ Error handling
- 🔍 Transaction tracking
Installation
You can install the package via composer:
composer require asciisd/knet
After installation, publish the configuration file:
php artisan knet:publish"
Configuration
Configure your KNET credentials in your .env file:
KNET_TRANSPORT_ID=your_transport_id
KNET_TRANSPORT_PASSWORD=your_transport_password
KNET_RESOURCE_KEY=your_resource_key
# URLs Optional
KNET_RESPONSE_URL=/knet/response
KNET_REDIRECT_URL=/dashboard
KNET_DEBUG=false
Basic Usage
Creating a Payment
use Asciisd\Knet\Services\KnetPaymentService;
class PaymentController extends Controller
{
public function createPayment(
Request $request,
KnetPaymentService $paymentService
) {
$transaction = $paymentService->createPayment(
user: $request->user(),
amount: 10.000,
options: [
'udf1' => 'custom_data_1',
'udf2' => 'custom_data_2',
]
);
return redirect($transaction->url);
}
}
Manual Handling Payment Response
public function handleResponse(
Request $request,
KnetPaymentService $paymentService
) {
$transaction = $paymentService->handlePaymentResponse($request->all());
if ($transaction->paid) {
return redirect()->route('payment.success');
}
return redirect()->route('payment.failed');
}
Processing Refunds
public function refund(
KnetTransaction $transaction,
KnetPaymentService $paymentService
) {
// Full refund
$result = $paymentService->refundPayment($transaction);
// Partial refund
$result = $paymentService->refundPayment($transaction, 5.000);
return $result;
}
Checking Transaction Status
public function checkStatus(
KnetTransaction $transaction,
KnetPaymentService $paymentService
) {
$updatedTransaction = $paymentService->inquireAndUpdateTransaction($transaction);
return $updatedTransaction;
}
Events
The package dispatches several events that you can listen to:
KnetResponseReceived: Fired when a payment response is receivedKnetResponsehandled: Fired when a payment response is handled
Event Listeners Example
use Asciisd\Knet\Events\KnetResponseReceived;
class PaymentReceivedListener
{
public function handle(KnetResponseReceived $event)
{
$transactionArray = $event->payload;
// Handle payload
}
}
Transaction Model
The KnetTransaction model provides several helpful methods:
$transaction->rawAmount(); // Get the raw amount
$transaction->isPaid(); // Check if transaction is paid
$transaction->isRefunded(); // Check if transaction is refunded
$transaction->isRefundable(); // Check if transaction can be refunded
Error Handling
The package includes comprehensive error handling:
try {
$result = $paymentService->refundPayment($transaction);
} catch (\Exception $e) {
Log::error('Refund failed', [
'message' => $e->getMessage(),
'transaction_id' => $transaction->id
]);
}
Database Schema
The package includes migrations for the knet_transactions table with the following fields:
id: Primary keyuser_id: Foreign key to users tabletrackid: KNET tracking IDamt: Transaction amountpaymentid: KNET payment IDtranid: KNET transaction IDref: Reference numberresult: Transaction resultauth: Authorization codeavr: AVR valuepostdate: Posting datepaid: Payment statuserror_text: Error message if anyurl: Payment URLlivemode: Production/Test mode flag- Various UDF fields (udf1 to udf5)
- Refund-related fields
- Timestamps
Testing
composer test
Security
If you discover any security-related issues, please email security@asciisd.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
Laravel Cashier provides an expressive, fluent interface to Stripe's subscriptio...
Cashier Paddle provides an expressive, fluent interface to Paddle's subscription...
A package to easily integrate your Laravel application with Lemon Squeezy.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v8.2.0 | ^8.3 | ^11.0| | MIT | |
| v8.1.0 | ^8.3 | ^11.0| | MIT | |
| v8.0.2 | ^8.3 | ^11.0| | MIT | |
| v8.0.1 | ^8.3 | ^11.0| | MIT | |
| v8.0.0 | ^8.3 | ^11.0| | MIT | |
| v7.2.0 | ^8.3 | ^10.0| | MIT | |
| v7.1.0 | ^8.3 | ^10.0| | MIT | |
| v7.0.0 | ^8.3 | ^10.0| | MIT | |
| v6.0.1 | ^8.3 | ^10.0| | MIT | |
| v6.0.0 | ^8.3 | ^10.0| | MIT | |
| v5.0.0 | ^8.3 | MIT | ||
| v4.0.0 | ^8.3 | MIT | ||
| v3.2.0 | ^8.1| | ^9.0| | MIT | |
| v3.1.1 | ^8.1| | ^9.0| | MIT | |
| v3.1.0 | ^8.1| | ^9.0| | MIT | |
| v3.0.0 | ^8.1| | ^9.0| | MIT | |
| v2.6.0 | ^7.1| | ^8.37| | MIT | |
| v2.5.1 | ^7.0| | ^8.37| | MIT | |
| v2.5.0 | ^7.0| | ^8.0| | MIT | |
| v2.4.2 | ^7.2.5| | ^7.0| | MIT | |
| v2.4.1 | ^7.2.5| | ^7.0| | MIT | |
| v2.4.0 | ^7.2.5| | ^7.0| | MIT | |
| v2.3.1 | ^7.3 | ^7.0| | MIT | |
| v2.2.2 | ^7.3 | ^7.0| | MIT | |
| v2.2.1 | ^7.3 | ^7.0| | MIT | |
| v2.2.0 | ^7.3 | ^7.0| | MIT | |
| v2.1.0 | ^7.3 | ^7.0| | MIT | |
| v2.0.0 | ^7.2 | ^6.0| | MIT | |
| v1.1.17 | ^7.1.3 | ~5.8.0| | MIT | |
| v1.1.16 | ^7.1.3 | ~5.8.0| | MIT |
Showing the latest 30 of 47. See every release on Packagist