added marketing page and moved events&general landing page
This commit is contained in:
207
app/Http/Controllers/MarketingController.php
Normal file
207
app/Http/Controllers/MarketingController.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Checkout\Session;
|
||||
use Stripe\StripeClient;
|
||||
use Exception;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\EventPurchase;
|
||||
|
||||
class MarketingController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
\Stripe\Stripe::setApiKey(config('services.stripe.key'));
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$packages = [
|
||||
['id' => 'basic', 'name' => 'Basic', 'events' => 1, 'price' => 0, 'description' => '1 Event, 100 Fotos, Grundfunktionen'],
|
||||
['id' => 'standard', 'name' => 'Standard', 'events' => 10, 'price' => 99, 'description' => '10 Events, Unbegrenzt Fotos, Erweiterte Features'],
|
||||
['id' => 'premium', 'name' => 'Premium', 'events' => 50, 'price' => 199, 'description' => '50 Events, Support & Custom, Alle Features'],
|
||||
];
|
||||
|
||||
return view('marketing', compact('packages'));
|
||||
}
|
||||
|
||||
public function contact(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|max:255',
|
||||
'message' => 'required|string|max:1000',
|
||||
]);
|
||||
|
||||
Mail::raw("Kontakt-Anfrage von {$request->name} ({$request->email}): {$request->message}", function ($message) use ($request) {
|
||||
$message->to('admin@fotospiel.de')
|
||||
->subject('Neue Kontakt-Anfrage');
|
||||
});
|
||||
|
||||
return redirect()->back()->with('success', 'Nachricht gesendet!');
|
||||
}
|
||||
|
||||
public function checkout(Request $request, $package)
|
||||
{
|
||||
$packages = [
|
||||
'basic' => ['name' => 'Basic', 'price' => 0, 'events' => 1],
|
||||
'standard' => ['name' => 'Standard', 'price' => 9900, 'events' => 10], // cents
|
||||
'premium' => ['name' => 'Premium', 'price' => 19900, 'events' => 50],
|
||||
];
|
||||
|
||||
if (!isset($packages[$package])) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$pkg = $packages[$package];
|
||||
|
||||
if ($pkg['price'] == 0) {
|
||||
// Free package: create tenant and event
|
||||
$tenant = Tenant::create([
|
||||
'name' => $request->input('tenant_name', 'New Tenant'),
|
||||
'slug' => Str::slug('new-' . now()),
|
||||
'email' => $request->input('email'),
|
||||
'events_remaining' => $pkg['events'],
|
||||
]);
|
||||
|
||||
// Create initial event
|
||||
$event = $tenant->events()->create([
|
||||
'name' => $request->input('event_name', 'My Event'),
|
||||
'slug' => Str::slug($request->input('event_name', 'my-event')),
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$purchase = EventPurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'events_purchased' => $pkg['events'],
|
||||
'amount' => 0,
|
||||
'currency' => 'EUR',
|
||||
'provider' => 'free',
|
||||
'status' => 'completed',
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
return redirect("/admin/tenants/{$tenant->id}/edit")->with('success', 'Konto erstellt! Willkommen bei Fotospiel.');
|
||||
}
|
||||
|
||||
$stripe = new \Stripe\StripeClient(config('services.stripe.secret'));
|
||||
$session = $stripe->checkout->sessions->create([
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [[
|
||||
'price_data' => [
|
||||
'currency' => 'eur',
|
||||
'product_data' => [
|
||||
'name' => $pkg['name'] . ' Package',
|
||||
],
|
||||
'unit_amount' => $pkg['price'],
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
'mode' => 'payment',
|
||||
'success_url' => route('marketing.success', $package),
|
||||
'cancel_url' => route('marketing'),
|
||||
'metadata' => [
|
||||
'package' => $package,
|
||||
'events' => $pkg['events'],
|
||||
],
|
||||
]);
|
||||
|
||||
return redirect($session->url, 303);
|
||||
}
|
||||
|
||||
public function stripeCheckout($sessionId)
|
||||
{
|
||||
// Handle Stripe success
|
||||
return view('marketing.success', ['provider' => 'Stripe']);
|
||||
}
|
||||
|
||||
public function paypalCheckout(Request $request, $package)
|
||||
{
|
||||
$packages = [
|
||||
'basic' => ['name' => 'Basic', 'price' => 0, 'events' => 1],
|
||||
'standard' => ['name' => 'Standard', 'price' => 99, 'events' => 10],
|
||||
'premium' => ['name' => 'Premium', 'price' => 199, 'events' => 50],
|
||||
];
|
||||
|
||||
if (!isset($packages[$package])) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$pkg = $packages[$package];
|
||||
|
||||
if ($pkg['price'] == 0) {
|
||||
// Free package: create tenant and event
|
||||
$tenant = Tenant::create([
|
||||
'name' => $request->input('tenant_name', 'New Tenant'),
|
||||
'slug' => Str::slug('new-' . now()),
|
||||
'email' => $request->input('email'),
|
||||
'events_remaining' => $pkg['events'],
|
||||
]);
|
||||
|
||||
// Create initial event
|
||||
$event = $tenant->events()->create([
|
||||
'name' => $request->input('event_name', 'My Event'),
|
||||
'slug' => Str::slug($request->input('event_name', 'my-event')),
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$purchase = EventPurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'events_purchased' => $pkg['events'],
|
||||
'amount' => 0,
|
||||
'currency' => 'EUR',
|
||||
'provider' => 'free',
|
||||
'status' => 'completed',
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
return redirect("/admin/tenants/{$tenant->id}/edit")->with('success', 'Konto erstellt! Willkommen bei Fotospiel.');
|
||||
}
|
||||
|
||||
$apiContext = new ApiContext(
|
||||
new OAuthTokenCredential(
|
||||
config('services.paypal.client_id'),
|
||||
config('services.paypal.secret')
|
||||
)
|
||||
);
|
||||
|
||||
$payment = new Payment();
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod('paypal');
|
||||
|
||||
$amountObj = new Amount();
|
||||
$amountObj->setCurrency('EUR');
|
||||
$amountObj->setTotal($pkg['price']);
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amountObj);
|
||||
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturnUrl(route('marketing.success', $package));
|
||||
$redirectUrls->setCancelUrl(route('marketing'));
|
||||
|
||||
$payment->setIntent('sale')
|
||||
->setPayer($payer)
|
||||
->setTransactions([$transaction])
|
||||
->setRedirectUrls($redirectUrls);
|
||||
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
return redirect($payment->getApprovalLink());
|
||||
} catch (Exception $e) {
|
||||
return back()->with('error', 'Zahlung fehlgeschlagen');
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/Http/Controllers/PayPalWebhookController.php
Normal file
56
app/Http/Controllers/PayPalWebhookController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\EventPurchase;
|
||||
use App\Models\Tenant;
|
||||
|
||||
class PayPalWebhookController extends Controller
|
||||
{
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
$ipnMessage = $input['ipn_track_id'] ?? null;
|
||||
$payerEmail = $input['payer_email'] ?? null;
|
||||
$paymentStatus = $input['payment_status'] ?? null;
|
||||
$mcGross = $input['mc_gross'] ?? 0;
|
||||
$packageId = $input['custom'] ?? null;
|
||||
|
||||
if ($paymentStatus === 'Completed' && $mcGross > 0) {
|
||||
// Verify IPN with PayPal (simplified; use SDK for full verification)
|
||||
// $verified = $this->verifyIPN($input);
|
||||
|
||||
// Find or create tenant (for public checkout, perhaps create new or use session)
|
||||
// For now, assume tenant_id from custom or session
|
||||
$tenantId = $packageId ? Tenant::where('slug', $packageId)->first()->id ?? 1 : 1;
|
||||
|
||||
// Create purchase and increment credits
|
||||
$purchase = EventPurchase::create([
|
||||
'tenant_id' => $tenantId, // Implement tenant resolution
|
||||
'events_purchased' => $mcGross / 49, // Example: 49€ per event credit
|
||||
'amount' => $mcGross,
|
||||
'currency' => $input['mc_currency'] ?? 'EUR',
|
||||
'provider' => 'paypal',
|
||||
'external_receipt_id' => $ipnMessage,
|
||||
'status' => 'completed',
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
$tenant = Tenant::find($tenantId);
|
||||
$tenant->incrementCredits($purchase->events_purchased, 'paypal_purchase', 'PayPal IPN', $purchase->id);
|
||||
|
||||
Log::info('PayPal IPN processed', $input);
|
||||
}
|
||||
|
||||
return response('OK', 200);
|
||||
}
|
||||
|
||||
private function verifyIPN($input)
|
||||
{
|
||||
// Use PayPal SDK to verify
|
||||
// Return true/false
|
||||
return true; // Placeholder
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user