Installation
composer require spiderwebtr/payment-kit
php artisan vendor:publish --tag=payment-kit
php artisan migrate
Verify the payment-kit table exists in your database.
First Use Case: Creating a Payment
use Spiderwebtr\PaymentKit\Facades\PaymentKit;
$payment = PaymentKit::create([
'amount' => 1000, // in cents
'currency' => 'TRY',
'description' => 'Product Purchase',
'payment_method' => 'sipay', // or 'param', 'iyzico', etc.
'callback_url' => route('payment.callback'),
'success_url' => route('payment.success'),
'fail_url' => route('payment.fail'),
]);
// Redirect to payment gateway
return redirect()->to($payment->getRedirectUrl());
Testing Locally
/payment-kit (if APP_ENV=local).Dynamic Provider Selection
Use the payment_method parameter to switch between providers (e.g., sipay, iyzico).
Example:
$payment = PaymentKit::create([
'payment_method' => request('provider') ?? 'sipay',
// ...
]);
3D Secure Flow
For 3D Secure payments, the package handles the redirect and callback automatically. Ensure your callback_url is publicly accessible.
$payment = PaymentKit::create([
'is_3d_secure' => true,
// ...
]);
payment.callback).PaymentKit::handleCallback() method to process incoming webhooks:
public function handleCallback(Request $request)
{
$result = PaymentKit::handleCallback($request);
return response()->json($result);
}
PAYMENT_KIT_WEBHOOK_SECRET in your .env./payment-kit.
Customize it by extending the PaymentKitController or overriding views in resources/views/vendor/payment-kit.PaymentKit::getPayments() method to fetch payments for reporting:
$payments = PaymentKit::getPayments()->latest()->take(100)->get();
PAYMENT_KIT_TEST_MODE=true.4242 4242 4242 4242 for Sipay, 4111 1111 1111 1111 for Iyzico).PaymentKit:
use Spiderwebtr\PaymentKit\Facades\PaymentKit;
public function mount()
{
$this->payments = PaymentKit::getPayments()->latest()->paginate(10);
}
PaymentKitServiceProvider and configuring Horizon to listen for PaymentProcessed events.Spiderwebtr\PaymentKit\Contracts\PaymentGateway contract:
namespace App\Providers;
use Spiderwebtr\PaymentKit\Contracts\PaymentGateway;
class CustomGateway implements PaymentGateway
{
public function createPayment(array $data): array
{
// Custom logic for your payment provider
}
// Implement other required methods
}
config/payment-kit.php under the gateways key.PaymentKit::getPaymentForm() method to generate a payment form dynamically:
$form = PaymentKit::getPaymentForm($paymentId);
echo $form->render();
getRedirectUrl() method to handle redirects via JavaScript:
window.location.href = "{{ $payment->getRedirectUrl() }}";
Callback URL Mismatch
callback_url matches the URL used in the payment creation. Mismatches will cause webhook failures.https://yourdomain.com/payment/callback) and verify the domain in config/payment-kit.php.Test Mode vs. Live Mode
PAYMENT_KIT_TEST_MODE can lead to real transactions being processed.PAYMENT_KIT_TEST_MODE=true in .env during development.3D Secure Redirects
success_url and fail_url are accessible.callback_url is correctly configured to handle 3D Secure redirects.Livewire Dashboard Conflicts
php artisan view:clear) and check browser console logs.Payment Gateway Timeouts
PAYMENT_KIT_TIMEOUT in .env (default: 30 seconds).Enable Logging
Add this to config/payment-kit.php to log all payment requests/responses:
'log_enabled' => env('PAYMENT_KIT_LOG_ENABLED', true),
Logs are stored in storage/logs/payment-kit.log.
Webhook Debugging
Use Laravel’s tape package to inspect incoming webhook payloads:
composer require spatie/laravel-tape
php artisan tape:play storage/logs/laravel.log --grep="payment_callback"
SQL Queries Enable Laravel’s query logging to debug payment record issues:
DB::enableQueryLog();
$payment = PaymentKit::create([...]);
dd(DB::getQueryLog());
Gateway-Specific Settings
Each provider may require additional configuration. Check the config/payment-kit.php file for provider-specific keys (e.g., iyzico_api_key, sipay_store_id).
Example:
'gateways' => [
'iyzico' => [
'api_key' => env('IYZICO_API_KEY'),
'secret_key' => env('IYZICO_SECRET_KEY'),
],
],
Currency and Amount Validation
The package validates that amount is in cents (e.g., 1000 for 10.00 TRY). Ensure your input matches this format.
Fix: Use bcdiv() or number_format() to convert amounts:
$amount = (int) round(10.00 * 100); // 1000
Locale-Specific Issues
tr) may cause issues with number formatting (e.g., 1.000,00 vs. 1000.00).$payment = PaymentKit::create([
'amount' => 1000,
'currency' => 'TRY',
'locale' => 'en_US', // Force English locale
]);
Custom Payment Statuses
Extend the payment_status column by adding a status_details JSON column to the payment-kit table:
Schema::table('payment-kit', function (Blueprint $table) {
$table->json('status_details')->nullable();
});
Update the Payment model to handle this field.
Event Listeners
Listen for payment events (e.g., PaymentCreated, PaymentProcessed) to trigger custom logic:
use Spiderwebtr\PaymentKit\Events\PaymentProcess
How can I help you explore Laravel packages today?