Merhaba arkadaşlar, bugün sizlere Laravel'de ödeme sistemi entegrasyonu konusunu detaylı şekilde anlatacağım. Modern web uygulamalarında ödeme sistemleri kritik bir rol oynar ve Laravel, Stripe ve PayPal gibi popüler ödeme sistemleriyle kolay entegrasyon sunar.
Online ödeme sistemleri, e-ticaret uygulamalarının temel taşıdır. Kullanıcılarınıza güvenli ve sorunsuz ödeme deneyimi sunmak için doğru entegrasyon yöntemlerini bilmek çok önemli.
Stripe Entegrasyonu
Stripe entegrasyonu için Laravel Cashier paketini kullanacağız:
composer require laravel/cashier
php artisan migrate
.env
dosyanıza Stripe anahtarlarını ekleyin:
STRIPE_KEY=your-stripe-key STRIPE_SECRET=your-stripe-secret
<form action="{{ route('payment.process') }}" method="POST" id="payment-form"> @csrf <div class="form-group"> <label for="card-element">Kredi/Banka Kartı</label> <div id="card-element"></div> </div> <button class="btn btn-primary">Ödeme Yap</button> </form>
use Illuminate\Http\Request; use Stripe\Stripe; use Stripe\Charge; class PaymentController extends Controller { public function process(Request $request) { Stripe::setApiKey(env('STRIPE_SECRET')); try { $charge = Charge::create([ 'amount' => 1000, // 10.00 TL 'currency' => 'try', 'source' => $request->stripeToken, 'description' => 'Örnek Ödeme', ]); return back()->with('success', 'Ödeme başarılı!'); } catch (\Exception $e) { return back()->with('error', $e->getMessage()); } } }
1. Paket Kurulumu:
PayPal için srmklive/paypal
paketini kullanacağız:
composer require srmklive/paypal
php artisan vendor:publish --provider="Srmklive\PayPal\Providers\PayPalServiceProvider"
3. API Anahtarlarını Ayarlama:
config/paypal.php
dosyasını düzenleyin veya .env
dosyanıza ekleyin:
PAYPAL_MODE=sandbox PAYPAL_SANDBOX_CLIENT_ID=your-client-id PAYPAL_SANDBOX_CLIENT_SECRET=your-secret
4. Ödeme İşlemi:
use Srmklive\PayPal\Services\PayPal as PayPalClient; class PayPalController extends Controller { public function process() { $provider = new PayPalClient; $provider->setApiCredentials(config('paypal')); $token = $provider->getAccessToken(); $response = $provider->createOrder([ "intent" => "CAPTURE", "purchase_units" => [ [ "amount" => [ "currency_code" => "USD", "value" => "10.00" ] ] ] ]); if (isset($response['id']) && $response['id'] != null) { foreach ($response['links'] as $link) { if ($link['rel'] === 'approve') { return redirect()->away($link['href']); } } } return redirect()->back()->with('error', 'Bir hata oluştu.'); } }
Stripe Avantajları:
PayPal Avantajları:
Laravel'de Stripe ve PayPal entegrasyonu, e-ticaret uygulamaları geliştirirken kritik öneme sahiptir. Bu rehberde temel entegrasyon adımlarını öğrendiniz. Bir sonraki yazımda, Laravel'de Task Scheduling: Zamanlanmış Görevler konusunu ele alacağım. Görüşmek üzere!