Add Events Pro/Business and BYO ticket gateways.
Deploy Ladill Events / deploy (push) Successful in 42s

Cut ticket checkouts off Ladill Pay, settle to merchant gateways at 0% platform fee, and mirror Invoice freemium pricing (GHS 49 / 149).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-15 01:26:28 +00:00
co-authored by Cursor
parent dda52722ce
commit 4c87c786da
26 changed files with 1376 additions and 105 deletions
@@ -0,0 +1,136 @@
<?php
namespace App\Http\Controllers\Events;
use App\Http\Controllers\Controller;
use App\Models\Events\ProSubscription;
use App\Models\User;
use App\Services\Billing\BillingClient;
use App\Services\Events\SubscriptionService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class ProController extends Controller
{
public function __construct(private readonly SubscriptionService $subscriptions) {}
public function index(Request $request): View
{
$user = ladill_account() ?? $request->user();
$planKey = $this->subscriptions->planKey($user);
return view('events.pro.index', [
'subscription' => $this->subscriptions->subscriptionFor($user),
'planKey' => $planKey,
'isPro' => $planKey === ProSubscription::PLAN_PRO,
'isEnterprise' => $planKey === ProSubscription::PLAN_ENTERPRISE,
'hasPaidPlan' => $this->subscriptions->hasPaidPlan($user),
'gatingActive' => $this->subscriptions->gatingActive(),
'proPriceMinor' => $this->subscriptions->priceMinor(),
'enterprisePriceMinor' => $this->subscriptions->enterprisePriceMinor(),
'prepaidMonths' => (array) config('events.prepaid_months', [6, 12, 24]),
'currency' => (string) config('events.pro.currency', 'GHS'),
]);
}
public function subscribe(Request $request): RedirectResponse
{
[$ok, $message] = $this->subscriptions->subscribe(ladill_account() ?? $request->user());
return redirect()->route('events.pro.index')->with($ok ? 'success' : 'error', $message);
}
public function subscribeEnterprise(Request $request): RedirectResponse
{
[$ok, $message] = $this->subscriptions->subscribeEnterprise(ladill_account() ?? $request->user());
return redirect()->route('events.pro.index')->with($ok ? 'success' : 'error', $message);
}
public function subscribePrepaid(Request $request, BillingClient $billing): RedirectResponse
{
$validated = $request->validate([
'plan' => ['required', 'in:pro,enterprise'],
'months' => ['required', 'integer', 'in:6,12,24'],
]);
$user = ladill_account() ?? $request->user();
if ($this->subscriptions->hasPaidPlan($user)) {
return redirect()->route('events.pro.index')
->with('success', 'You already have an active subscription.');
}
$plan = $validated['plan'];
$months = (int) $validated['months'];
$monthlyMinor = $plan === 'enterprise'
? $this->subscriptions->enterprisePriceMinor()
: $this->subscriptions->priceMinor();
try {
$checkout = $billing->initiatePlanCheckout(
$user,
$plan,
$months,
$monthlyMinor * $months,
route('events.pro.paystack.callback'),
['user_id' => $user->id],
);
} catch (\Throwable) {
return redirect()->route('events.pro.index')
->with('error', 'Could not start Paystack checkout. Please try again.');
}
$url = trim((string) ($checkout['checkout_url'] ?? ''));
if ($url === '') {
return redirect()->route('events.pro.index')
->with('error', 'Paystack did not return a checkout URL.');
}
return redirect()->away($url);
}
public function paystackCallback(Request $request, BillingClient $billing): RedirectResponse
{
$reference = (string) $request->query('reference', '');
if ($reference === '') {
return redirect()->route('events.pro.index')->with('error', 'Missing payment reference.');
}
try {
$result = $billing->verifyPlanCheckout($reference);
} catch (\Throwable) {
return redirect()->route('events.pro.index')
->with('error', 'Could not verify payment. Contact support with reference: '.$reference);
}
if (! ($result['paid'] ?? false)) {
return redirect()->route('events.pro.index')
->with('error', 'Payment was not completed.');
}
$metadata = (array) ($result['metadata'] ?? []);
$user = User::query()->find((int) ($metadata['user_id'] ?? 0));
$account = ladill_account() ?? $request->user();
if (! $user || ! $account || $user->id !== $account->id) {
return redirect()->route('events.pro.index')
->with('error', 'Account not found for this payment.');
}
$plan = (string) ($result['plan'] ?? 'pro');
$months = (int) ($result['months'] ?? 0);
$this->subscriptions->activatePrepaid($user, $plan, $months);
$label = $plan === 'enterprise' ? 'Events Business' : 'Events Pro';
return redirect()->route('events.pro.index')
->with('success', "{$label} is active for {$months} months.");
}
public function cancel(Request $request): RedirectResponse
{
[$ok, $message] = $this->subscriptions->cancel(ladill_account() ?? $request->user());
return redirect()->route('events.pro.index')->with($ok ? 'success' : 'error', $message);
}
}