Add 3-tier plans, Paystack prepaid Pro, and Enterprise contact-sales card.
Deploy Ladill Frontdesk / deploy (push) Successful in 2m46s
Deploy Ladill Frontdesk / deploy (push) Successful in 2m46s
Sidebar settings and upgrade share one footer with consistent spacing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Frontdesk;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
||||
use App\Models\Organization;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use App\Services\Frontdesk\FrontdeskPermissions;
|
||||
use App\Services\Frontdesk\PlanService;
|
||||
@@ -24,21 +25,20 @@ class ProController extends Controller
|
||||
$expiresAt = ! empty($settings['plan_expires_at'])
|
||||
? Carbon::parse($settings['plan_expires_at'])
|
||||
: null;
|
||||
$planKey = $plans->planKey($organization);
|
||||
|
||||
return view('frontdesk.pro.index', [
|
||||
'organization' => $organization,
|
||||
'isPro' => $plans->isPro($organization),
|
||||
'planKey' => $planKey,
|
||||
'isPro' => $planKey === 'pro',
|
||||
'isEnterprise' => $planKey === 'enterprise',
|
||||
'hasPaidPlan' => $plans->hasPaidPlan($organization),
|
||||
'canManage' => $canManage,
|
||||
'priceMinor' => $plans->proPriceMinor(),
|
||||
'proPriceMinor' => $plans->proPriceMinor(),
|
||||
'prepaidMonths' => (array) config('frontdesk.prepaid_months', [6, 12, 24]),
|
||||
'currency' => (string) config('billing.currency', 'GHS'),
|
||||
'planExpiresAt' => $expiresAt,
|
||||
'proFeatures' => [
|
||||
'Unlimited branches & kiosk devices',
|
||||
'Unlimited host email alerts',
|
||||
'Webhooks & calendar (iCal) feeds',
|
||||
'Scheduled report exports',
|
||||
'Custom badge templates',
|
||||
],
|
||||
'salesUrl' => ladill_platform_url('contact-sales'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -47,26 +47,128 @@ class ProController extends Controller
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$organization = $this->organization($request);
|
||||
|
||||
if ($plans->isPro($organization)) {
|
||||
if ($plans->hasPaidPlan($organization)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('success', 'Your organization is already on Frontdesk Pro.');
|
||||
->with('success', 'Your organization already has an active paid plan.');
|
||||
}
|
||||
|
||||
$priceMinor = $plans->proPriceMinor();
|
||||
$ownerRef = $organization->owner_ref;
|
||||
if ($plans->isEnterprise($organization)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('success', 'Your organization is on Frontdesk Enterprise.');
|
||||
}
|
||||
|
||||
return $this->chargeMonthlyWallet(
|
||||
$organization,
|
||||
$billing,
|
||||
$plans->proPriceMinor(),
|
||||
'pro',
|
||||
'frontdesk_pro',
|
||||
'frontdesk-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Frontdesk Pro — monthly subscription',
|
||||
'Welcome to Frontdesk Pro — active for one month.',
|
||||
);
|
||||
}
|
||||
|
||||
public function subscribePrepaid(Request $request, PlanService $plans, BillingClient $billing): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$validated = $request->validate([
|
||||
'plan' => ['required', 'in:pro'],
|
||||
'months' => ['required', 'integer', 'in:6,12,24'],
|
||||
]);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
if ($plans->hasPaidPlan($organization) || $plans->isEnterprise($organization)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('success', 'Your organization already has an active plan.');
|
||||
}
|
||||
|
||||
$months = (int) $validated['months'];
|
||||
$amountMinor = $plans->proPriceMinor() * $months;
|
||||
|
||||
try {
|
||||
if (! $billing->canAfford($ownerRef, $priceMinor)) {
|
||||
$checkout = $billing->initiatePlanCheckout(
|
||||
$organization->owner_ref,
|
||||
'pro',
|
||||
$months,
|
||||
$amountMinor,
|
||||
route('frontdesk.pro.paystack.callback'),
|
||||
['organization_id' => $organization->id],
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Could not start Paystack checkout. Please try again.');
|
||||
}
|
||||
|
||||
$url = trim((string) ($checkout['checkout_url'] ?? ''));
|
||||
if ($url === '') {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Paystack did not return a checkout URL.');
|
||||
}
|
||||
|
||||
return redirect()->away($url);
|
||||
}
|
||||
|
||||
public function paystackCallback(Request $request, BillingClient $billing, PlanService $plans): RedirectResponse
|
||||
{
|
||||
$reference = (string) $request->query('reference', '');
|
||||
if ($reference === '') {
|
||||
return redirect()->route('frontdesk.pro.index')->with('error', 'Missing payment reference.');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $billing->verifyPlanCheckout($reference);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Could not verify payment. Contact support with reference: '.$reference);
|
||||
}
|
||||
|
||||
if (! ($result['paid'] ?? false)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Payment was not completed.');
|
||||
}
|
||||
|
||||
$metadata = (array) ($result['metadata'] ?? []);
|
||||
$organization = Organization::query()->find((int) ($metadata['organization_id'] ?? 0));
|
||||
if (! $organization) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Organization not found for this payment.');
|
||||
}
|
||||
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
if ($this->organization($request)->id !== $organization->id) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$months = (int) ($result['months'] ?? 0);
|
||||
$this->activatePrepaidPlan($organization, 'pro', $months);
|
||||
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('success', "Frontdesk Pro is active for {$months} months.");
|
||||
}
|
||||
|
||||
private function chargeMonthlyWallet(
|
||||
Organization $organization,
|
||||
BillingClient $billing,
|
||||
int $priceMinor,
|
||||
string $plan,
|
||||
string $billingSource,
|
||||
string $reference,
|
||||
string $description,
|
||||
string $successMessage,
|
||||
): RedirectResponse {
|
||||
try {
|
||||
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade.');
|
||||
}
|
||||
|
||||
$charged = $billing->debit(
|
||||
$ownerRef,
|
||||
$organization->owner_ref,
|
||||
$priceMinor,
|
||||
'frontdesk_pro',
|
||||
'frontdesk-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Frontdesk Pro — monthly subscription',
|
||||
$billingSource,
|
||||
$reference,
|
||||
$description,
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
@@ -75,19 +177,30 @@ class ProController extends Controller
|
||||
|
||||
if (! $charged) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade.');
|
||||
}
|
||||
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = 'pro';
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = true;
|
||||
$settings['billing_method'] = 'wallet_monthly';
|
||||
$settings['plan_expires_at'] = now()
|
||||
->addDays((int) config('frontdesk.pro.period_days', 30))
|
||||
->toIso8601String();
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('success', 'Welcome to Frontdesk Pro — active for one month.');
|
||||
return redirect()->route('frontdesk.pro.index')->with('success', $successMessage);
|
||||
}
|
||||
|
||||
private function activatePrepaidPlan(Organization $organization, string $plan, int $months): void
|
||||
{
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = false;
|
||||
$settings['billing_method'] = 'paystack_prepaid';
|
||||
$settings['plan_expires_at'] = now()->addMonths($months)->toIso8601String();
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user