Add Business tier and Paystack prepaid billing for POS.
Deploy Ladill POS / deploy (push) Successful in 35s
Deploy Ladill POS / deploy (push) Successful in 35s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers\Pos;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Pos\ProSubscription;
|
||||
use App\Models\User;
|
||||
use App\Services\Pos\BillingClient;
|
||||
use App\Services\Pos\SubscriptionService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,12 +18,18 @@ class ProController extends Controller
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$user = ladill_account() ?? $request->user();
|
||||
$planKey = $this->subscriptions->planKey($user);
|
||||
|
||||
return view('pos.pro.index', [
|
||||
'subscription' => $this->subscriptions->subscriptionFor($user),
|
||||
'isPro' => $this->subscriptions->isPro($user),
|
||||
'planKey' => $planKey,
|
||||
'isPro' => $planKey === ProSubscription::PLAN_PRO,
|
||||
'isEnterprise' => $planKey === ProSubscription::PLAN_ENTERPRISE,
|
||||
'hasPaidPlan' => $this->subscriptions->hasPaidPlan($user),
|
||||
'gatingActive' => $this->subscriptions->gatingActive(),
|
||||
'priceMinor' => $this->subscriptions->priceMinor(),
|
||||
'proPriceMinor' => $this->subscriptions->priceMinor(),
|
||||
'enterprisePriceMinor' => $this->subscriptions->enterprisePriceMinor(),
|
||||
'prepaidMonths' => (array) config('pos.prepaid_months', [6, 12, 24]),
|
||||
'currency' => (string) config('pos.pro.currency', 'GHS'),
|
||||
]);
|
||||
}
|
||||
@@ -32,6 +41,92 @@ class ProController extends Controller
|
||||
return redirect()->route('pos.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('pos.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('pos.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('pos.pro.paystack.callback'),
|
||||
['user_id' => $user->id],
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('pos.pro.index')
|
||||
->with('error', 'Could not start Paystack checkout. Please try again.');
|
||||
}
|
||||
|
||||
$url = trim((string) ($checkout['checkout_url'] ?? ''));
|
||||
if ($url === '') {
|
||||
return redirect()->route('pos.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('pos.pro.index')->with('error', 'Missing payment reference.');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $billing->verifyPlanCheckout($reference);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('pos.pro.index')
|
||||
->with('error', 'Could not verify payment. Contact support with reference: '.$reference);
|
||||
}
|
||||
|
||||
if (! ($result['paid'] ?? false)) {
|
||||
return redirect()->route('pos.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('pos.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' ? 'POS Business' : 'POS Pro';
|
||||
|
||||
return redirect()->route('pos.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());
|
||||
|
||||
@@ -14,10 +14,14 @@ class ProSubscription extends Model
|
||||
|
||||
public const STATUS_PAST_DUE = 'past_due';
|
||||
|
||||
public const PLAN_PRO = 'pro';
|
||||
|
||||
public const PLAN_ENTERPRISE = 'enterprise';
|
||||
|
||||
protected $table = 'pos_pro_subscriptions';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'status', 'price_minor', 'currency', 'auto_renew',
|
||||
'user_id', 'status', 'plan', 'price_minor', 'currency', 'auto_renew',
|
||||
'started_at', 'current_period_end', 'last_charged_at', 'canceled_at',
|
||||
'last_reference', 'last_error',
|
||||
];
|
||||
|
||||
@@ -30,9 +30,14 @@ class AppServiceProvider extends ServiceProvider
|
||||
$restaurant = PosLocation::owned((string) $account->public_id)
|
||||
->where('service_style', PosLocation::STYLE_RESTAURANT)
|
||||
->exists();
|
||||
$view->with('isPro', app(SubscriptionService::class)->isPro($account));
|
||||
$svc = app(SubscriptionService::class);
|
||||
$view->with('isPro', $svc->isPro($account));
|
||||
$view->with('hasPaidPlan', $svc->hasPaidPlan($account));
|
||||
$view->with('isEnterprise', $svc->isEnterprise($account));
|
||||
} else {
|
||||
$view->with('isPro', false);
|
||||
$view->with('hasPaidPlan', false);
|
||||
$view->with('isEnterprise', false);
|
||||
}
|
||||
$view->with('posRestaurant', $restaurant);
|
||||
});
|
||||
|
||||
@@ -49,4 +49,52 @@ class BillingClient
|
||||
|
||||
return ['ok' => true, 'insufficient' => false, 'balance_minor' => null, 'error' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $metadata
|
||||
* @return array{checkout_url: string, reference: string}
|
||||
*/
|
||||
public function initiatePlanCheckout(
|
||||
User $user,
|
||||
string $plan,
|
||||
int $months,
|
||||
int $amountMinor,
|
||||
string $returnUrl,
|
||||
array $metadata = [],
|
||||
): array {
|
||||
$res = Http::withToken((string) config('billing.api_key'))
|
||||
->acceptJson()->timeout(15)
|
||||
->post(rtrim((string) config('billing.api_url'), '/').'/plan-checkout', [
|
||||
'user' => $user->public_id,
|
||||
'app' => (string) config('billing.service', 'pos'),
|
||||
'plan' => $plan,
|
||||
'months' => $months,
|
||||
'amount_minor' => $amountMinor,
|
||||
'return_url' => $returnUrl,
|
||||
'metadata' => $metadata,
|
||||
]);
|
||||
$res->throw();
|
||||
|
||||
return [
|
||||
'checkout_url' => (string) $res->json('checkout_url'),
|
||||
'reference' => (string) $res->json('reference'),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function verifyPlanCheckout(string $reference): array
|
||||
{
|
||||
$res = Http::withToken((string) config('billing.api_key'))
|
||||
->acceptJson()->timeout(15)
|
||||
->post(rtrim((string) config('billing.api_url'), '/').'/plan-checkout/verify', [
|
||||
'reference' => $reference,
|
||||
]);
|
||||
|
||||
if ($res->status() === 422) {
|
||||
return ['paid' => false, 'error' => $res->json('error')];
|
||||
}
|
||||
$res->throw();
|
||||
|
||||
return $res->json();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,12 @@ class SubscriptionService
|
||||
|
||||
public function priceMinor(): int
|
||||
{
|
||||
return (int) config('pos.pro.price_minor', 7900);
|
||||
return (int) config('pos.plans.pro.price_minor', config('pos.pro.price_minor', 7900));
|
||||
}
|
||||
|
||||
public function enterprisePriceMinor(): int
|
||||
{
|
||||
return (int) config('pos.plans.enterprise.price_minor', 24900);
|
||||
}
|
||||
|
||||
public function subscriptionFor(User $user): ?ProSubscription
|
||||
@@ -29,7 +34,23 @@ class SubscriptionService
|
||||
return ProSubscription::where('user_id', $user->id)->first();
|
||||
}
|
||||
|
||||
public function isPro(User $user): bool
|
||||
public function planKey(User $user): string
|
||||
{
|
||||
if (! $this->gatingActive()) {
|
||||
return ProSubscription::PLAN_PRO;
|
||||
}
|
||||
|
||||
$sub = $this->subscriptionFor($user);
|
||||
if (! $sub || ! $sub->entitled()) {
|
||||
return 'free';
|
||||
}
|
||||
|
||||
return $sub->plan === ProSubscription::PLAN_ENTERPRISE
|
||||
? ProSubscription::PLAN_ENTERPRISE
|
||||
: ProSubscription::PLAN_PRO;
|
||||
}
|
||||
|
||||
public function hasPaidPlan(User $user): bool
|
||||
{
|
||||
if (! $this->gatingActive()) {
|
||||
return true;
|
||||
@@ -38,6 +59,16 @@ class SubscriptionService
|
||||
return (bool) $this->subscriptionFor($user)?->entitled();
|
||||
}
|
||||
|
||||
public function isEnterprise(User $user): bool
|
||||
{
|
||||
return $this->planKey($user) === ProSubscription::PLAN_ENTERPRISE;
|
||||
}
|
||||
|
||||
public function isPro(User $user): bool
|
||||
{
|
||||
return $this->hasPaidPlan($user);
|
||||
}
|
||||
|
||||
public function productCount(string $ownerRef, bool $restaurant): int
|
||||
{
|
||||
if ($restaurant) {
|
||||
@@ -84,41 +115,56 @@ class SubscriptionService
|
||||
{
|
||||
$existing = $this->subscriptionFor($user);
|
||||
if ($existing && $existing->entitled() && $existing->status === ProSubscription::STATUS_ACTIVE) {
|
||||
return [true, 'You are already on Ladill POS Pro.'];
|
||||
return [true, 'You already have an active subscription.'];
|
||||
}
|
||||
|
||||
$price = $this->priceMinor();
|
||||
$reference = 'pos-pro-'.$user->id.'-'.now()->format('YmdHis').'-'.Str::random(6);
|
||||
$result = $this->billing->charge($user, $price, $reference, 'Ladill POS Pro — monthly subscription');
|
||||
|
||||
if (! $result['ok']) {
|
||||
if ($result['insufficient']) {
|
||||
$bal = number_format(((int) $result['balance_minor']) / 100, 2);
|
||||
|
||||
return [false, "Your wallet balance (GHS {$bal}) is too low. Top up, then subscribe."];
|
||||
if ($existing?->plan === ProSubscription::PLAN_ENTERPRISE) {
|
||||
return $this->subscribeEnterprise($user);
|
||||
}
|
||||
|
||||
return [false, $result['error'] ?? 'Could not start your subscription. Please try again.'];
|
||||
return $this->activateWalletPlan($user, ProSubscription::PLAN_PRO, $this->priceMinor(), 'Ladill POS Pro — monthly subscription', 'Welcome to Ladill POS Pro!');
|
||||
}
|
||||
|
||||
$periodEnd = Carbon::now()->addDays((int) config('pos.pro.period_days', 30));
|
||||
/** @return array{0:bool,1:string} */
|
||||
public function subscribeEnterprise(User $user): array
|
||||
{
|
||||
$existing = $this->subscriptionFor($user);
|
||||
if ($existing && $existing->entitled() && $existing->status === ProSubscription::STATUS_ACTIVE) {
|
||||
return [true, 'You already have an active subscription.'];
|
||||
}
|
||||
|
||||
return $this->activateWalletPlan(
|
||||
$user,
|
||||
ProSubscription::PLAN_ENTERPRISE,
|
||||
$this->enterprisePriceMinor(),
|
||||
'Ladill POS Business — monthly subscription',
|
||||
'Welcome to Ladill POS Business!',
|
||||
);
|
||||
}
|
||||
|
||||
public function activatePrepaid(User $user, string $plan, int $months): void
|
||||
{
|
||||
$existing = $this->subscriptionFor($user);
|
||||
$price = $plan === ProSubscription::PLAN_ENTERPRISE
|
||||
? $this->enterprisePriceMinor()
|
||||
: $this->priceMinor();
|
||||
|
||||
ProSubscription::updateOrCreate(
|
||||
['user_id' => $user->id],
|
||||
[
|
||||
'plan' => $plan,
|
||||
'status' => ProSubscription::STATUS_ACTIVE,
|
||||
'price_minor' => $price,
|
||||
'currency' => (string) config('pos.pro.currency', 'GHS'),
|
||||
'auto_renew' => true,
|
||||
'auto_renew' => false,
|
||||
'started_at' => $existing?->started_at ?? now(),
|
||||
'current_period_end' => $periodEnd,
|
||||
'current_period_end' => Carbon::now()->addMonths($months),
|
||||
'last_charged_at' => now(),
|
||||
'canceled_at' => null,
|
||||
'last_reference' => $reference,
|
||||
'last_reference' => null,
|
||||
'last_error' => null,
|
||||
],
|
||||
);
|
||||
|
||||
return [true, 'Welcome to Ladill POS Pro! Your subscription is active.'];
|
||||
}
|
||||
|
||||
/** @return array{0:bool,1:string} */
|
||||
@@ -137,7 +183,7 @@ class SubscriptionService
|
||||
|
||||
$until = optional($sub->current_period_end)->format('d M Y');
|
||||
|
||||
return [true, "Auto-renew is off. You keep Pro until {$until}."];
|
||||
return [true, "Auto-renew is off. You keep access until {$until}."];
|
||||
}
|
||||
|
||||
public function renewIfDue(ProSubscription $sub): void
|
||||
@@ -154,8 +200,9 @@ class SubscriptionService
|
||||
return;
|
||||
}
|
||||
|
||||
$reference = 'pos-pro-'.$user->id.'-'.now()->format('YmdHis').'-'.Str::random(6);
|
||||
$result = $this->billing->charge($user, $sub->price_minor, $reference, 'Ladill POS Pro — renewal');
|
||||
$planLabel = $sub->plan === ProSubscription::PLAN_ENTERPRISE ? 'Business' : 'Pro';
|
||||
$reference = 'pos-'.$sub->plan.'-'.$user->id.'-'.now()->format('YmdHis').'-'.Str::random(6);
|
||||
$result = $this->billing->charge($user, $sub->price_minor, $reference, "Ladill POS {$planLabel} — renewal");
|
||||
|
||||
if ($result['ok']) {
|
||||
$sub->forceFill([
|
||||
@@ -175,4 +222,42 @@ class SubscriptionService
|
||||
$sub->forceFill(['last_error' => $result['error']])->save();
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array{0:bool,1:string} */
|
||||
private function activateWalletPlan(User $user, string $plan, int $price, string $description, string $successMessage): array
|
||||
{
|
||||
$existing = $this->subscriptionFor($user);
|
||||
$reference = 'pos-'.$plan.'-'.$user->id.'-'.now()->format('YmdHis').'-'.Str::random(6);
|
||||
$result = $this->billing->charge($user, $price, $reference, $description);
|
||||
|
||||
if (! $result['ok']) {
|
||||
if ($result['insufficient']) {
|
||||
$bal = number_format(((int) $result['balance_minor']) / 100, 2);
|
||||
|
||||
return [false, "Your wallet balance (GHS {$bal}) is too low. Top up, then subscribe."];
|
||||
}
|
||||
|
||||
return [false, $result['error'] ?? 'Could not start your subscription. Please try again.'];
|
||||
}
|
||||
|
||||
$periodEnd = Carbon::now()->addDays((int) config('pos.pro.period_days', 30));
|
||||
ProSubscription::updateOrCreate(
|
||||
['user_id' => $user->id],
|
||||
[
|
||||
'plan' => $plan,
|
||||
'status' => ProSubscription::STATUS_ACTIVE,
|
||||
'price_minor' => $price,
|
||||
'currency' => (string) config('pos.pro.currency', 'GHS'),
|
||||
'auto_renew' => true,
|
||||
'started_at' => $existing?->started_at ?? now(),
|
||||
'current_period_end' => $periodEnd,
|
||||
'last_charged_at' => now(),
|
||||
'canceled_at' => null,
|
||||
'last_reference' => $reference,
|
||||
'last_error' => null,
|
||||
],
|
||||
);
|
||||
|
||||
return [true, $successMessage.' Your subscription is active.'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,13 @@ return [
|
||||
'grace_days' => (int) env('POS_PRO_GRACE_DAYS', 3),
|
||||
],
|
||||
|
||||
'plans' => [
|
||||
'pro' => ['price_minor' => (int) env('POS_PRO_PRICE_MINOR', 7900)],
|
||||
'enterprise' => ['price_minor' => (int) env('POS_ENTERPRISE_PRICE_MINOR', 24900)],
|
||||
],
|
||||
|
||||
'prepaid_months' => [6, 12, 24],
|
||||
|
||||
'free' => [
|
||||
'max_locations' => (int) env('POS_FREE_MAX_LOCATIONS', 1),
|
||||
'max_products' => (int) env('POS_FREE_MAX_PRODUCTS', 50),
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('pos_pro_subscriptions', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('pos_pro_subscriptions', 'plan')) {
|
||||
$table->string('plan', 16)->default('pro')->after('status');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pos_pro_subscriptions', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('pos_pro_subscriptions', 'plan')) {
|
||||
$table->dropColumn('plan');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -47,10 +47,10 @@
|
||||
</a>
|
||||
|
||||
@php $proActive = request()->routeIs('pos.pro.*'); @endphp
|
||||
@if(!empty($isPro))
|
||||
@if (! empty($hasPaidPlan))
|
||||
<a href="{{ route('pos.pro.index') }}" class="group mt-0.5 flex items-center gap-3 rounded-lg px-3 py-2 text-[13px] transition {{ $proActive ? 'bg-indigo-50 text-indigo-700 font-semibold' : 'text-slate-600 hover:bg-slate-50 hover:text-slate-900' }}">
|
||||
<svg class="h-[18px] w-[18px] shrink-0 text-amber-500" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.25c.3 0 .58.18.7.46l2.36 5.5 5.96.5a.75.75 0 0 1 .43 1.31l-4.53 3.9 1.36 5.83a.75.75 0 0 1-1.12.81L12 17.77l-5.16 3a.75.75 0 0 1-1.12-.81l1.36-5.83-4.53-3.9a.75.75 0 0 1 .43-1.31l5.96-.5 2.36-5.5c.12-.28.4-.46.7-.46Z"/></svg>
|
||||
<span>POS Pro</span>
|
||||
<span>{{ ! empty($isEnterprise) ? 'POS Business' : 'POS Pro' }}</span>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{ route('pos.pro.index') }}" class="group mt-0.5 flex items-center gap-3 rounded-lg bg-gradient-to-r from-indigo-600 to-emerald-500 px-3 py-2 text-[13px] font-semibold text-white shadow-sm transition hover:opacity-95">
|
||||
|
||||
@@ -1,74 +1,97 @@
|
||||
<x-app-layout title="Pro" heading="Ladill POS Pro">
|
||||
<x-app-layout title="Plans" heading="POS plans">
|
||||
@php
|
||||
$price = number_format($priceMinor / 100, 2);
|
||||
$proPrice = number_format($proPriceMinor / 100, 0);
|
||||
$enterprisePrice = number_format($enterprisePriceMinor / 100, 0);
|
||||
$live = $subscription && $subscription->entitled();
|
||||
@endphp
|
||||
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="mx-auto max-w-5xl space-y-6" x-data="{ billing: 'monthly' }">
|
||||
@if (session('success'))
|
||||
<div class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">{{ session('success') }}</div>
|
||||
@endif
|
||||
@if (session('error'))
|
||||
<div class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800">{{ session('error') }}</div>
|
||||
@endif
|
||||
@if (session('upsell'))
|
||||
<div class="mb-4 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">{{ session('upsell') }}</div>
|
||||
<div class="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">{{ session('upsell') }}</div>
|
||||
@endif
|
||||
|
||||
<div class="overflow-hidden rounded-2xl border border-slate-200 bg-white">
|
||||
<div class="bg-gradient-to-r from-indigo-700 via-blue-600 to-emerald-500 px-6 py-7 text-white">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="rounded-md bg-white/20 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide">Pro</span>
|
||||
@if($live)<span class="rounded-md bg-emerald-400/90 px-2 py-0.5 text-[11px] font-semibold text-emerald-950">Active</span>@endif
|
||||
</div>
|
||||
<h1 class="mt-3 text-2xl font-bold">Ladill POS Pro</h1>
|
||||
<p class="mt-1 text-sm text-white/80">Scale your counter with unlimited products, restaurant mode, and ecosystem sync.</p>
|
||||
<p class="mt-4 text-3xl font-bold">{{ $currency }} {{ $price }}<span class="text-base font-medium text-white/70"> / month</span></p>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-6">
|
||||
<ul class="grid gap-3 sm:grid-cols-2">
|
||||
@foreach([
|
||||
'Unlimited products',
|
||||
'Restaurant mode & kitchen display',
|
||||
'CRM & Merchant catalog import',
|
||||
'Stock tracking',
|
||||
'Invoice, CRM & Accounting sync',
|
||||
'Multi-location ready',
|
||||
] as $feature)
|
||||
<li class="flex items-start gap-2 text-sm text-slate-700">
|
||||
<svg class="mt-0.5 h-4 w-4 shrink-0 text-emerald-500" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5"/></svg>
|
||||
<span>{{ $feature }}</span>
|
||||
</li>
|
||||
<div class="rounded-2xl border border-slate-200 bg-white px-6 py-5">
|
||||
<h1 class="text-2xl font-bold text-slate-900">Choose your POS plan</h1>
|
||||
<p class="mt-1 text-sm text-slate-600">Pay monthly from your Ladill wallet, or prepay 6/12/24 months via Paystack.</p>
|
||||
@if ($gatingActive && ! $live)
|
||||
<div class="mt-4 flex flex-wrap gap-2">
|
||||
<button type="button" @click="billing = 'monthly'" :class="billing === 'monthly' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-700 hover:bg-slate-200'" class="rounded-lg px-3 py-1.5 text-sm font-medium transition">Monthly · wallet</button>
|
||||
@foreach ($prepaidMonths as $months)
|
||||
<button type="button" @click="billing = '{{ $months }}'" :class="billing === '{{ $months }}' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-700 hover:bg-slate-200'" class="rounded-lg px-3 py-1.5 text-sm font-medium transition">{{ $months }} months · Paystack</button>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-6 border-t border-slate-100 pt-6">
|
||||
@if(! $gatingActive)
|
||||
<p class="rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500">Pro is currently included for all accounts.</p>
|
||||
@elseif($live)
|
||||
@if ($live)
|
||||
<div class="rounded-2xl border border-slate-200 bg-white px-6 py-5">
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div class="text-sm text-slate-600">
|
||||
@if($subscription->status === 'canceled')
|
||||
Auto-renew off — Pro stays active until <strong>{{ $subscription->current_period_end->format('d M Y') }}</strong>.
|
||||
@else
|
||||
Renews on <strong>{{ $subscription->current_period_end->format('d M Y') }}</strong> from your Ladill wallet.
|
||||
@endif
|
||||
<strong>{{ $isEnterprise ? 'Business' : 'Pro' }}</strong> active until <strong>{{ $subscription->current_period_end->format('d M Y') }}</strong>
|
||||
</div>
|
||||
@if ($subscription->auto_renew)
|
||||
<form method="post" action="{{ route('pos.pro.cancel') }}" onsubmit="return confirm('Turn off auto-renew? You keep Pro until the period ends.');">
|
||||
@csrf
|
||||
<button class="rounded-xl border border-slate-200 px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-50">Cancel auto-renew</button>
|
||||
</form>
|
||||
@else
|
||||
<form method="post" action="{{ route('pos.pro.subscribe') }}">
|
||||
@csrf
|
||||
<button class="btn-primary">Resume subscription</button>
|
||||
</form>
|
||||
<form method="post" action="{{ route('pos.pro.cancel') }}" onsubmit="return confirm('Turn off auto-renew?');">@csrf<button class="rounded-xl border border-slate-200 px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-50">Cancel auto-renew</button></form>
|
||||
@elseif ($subscription->status === 'canceled')
|
||||
<form method="post" action="{{ route($isEnterprise ? 'pos.pro.subscribe-enterprise' : 'pos.pro.subscribe') }}">@csrf<button class="btn-primary">Resume subscription</button></form>
|
||||
@endif
|
||||
</div>
|
||||
@else
|
||||
<form method="post" action="{{ route('pos.pro.subscribe') }}">
|
||||
@csrf
|
||||
<button class="btn-primary w-full sm:w-auto">
|
||||
Subscribe — {{ $currency }} {{ $price }}/mo from wallet
|
||||
</button>
|
||||
</form>
|
||||
<p class="mt-3 text-xs text-slate-400">Billed monthly from your Ladill wallet. Cancel anytime; you keep Pro until the period ends.</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-3">
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-white p-6 {{ $planKey === 'free' ? 'ring-2 ring-indigo-500' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Free</p>
|
||||
<p class="mt-2 text-3xl font-bold text-slate-900">GHS 0</p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
|
||||
<li>50 products</li>
|
||||
<li>1 location</li>
|
||||
<li>Core checkout</li>
|
||||
</ul>
|
||||
@if ($planKey === 'free')<p class="mt-6 text-sm font-medium text-indigo-700">Current plan</p>@endif
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-white p-6 {{ $planKey === 'pro' ? 'ring-2 ring-indigo-500' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-indigo-600">Pro</p>
|
||||
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $currency }} {{ $proPrice }}<span class="text-base font-medium text-slate-500">/mo</span></p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
|
||||
<li>Unlimited products</li>
|
||||
<li>Restaurant mode</li>
|
||||
<li>Catalog import</li>
|
||||
</ul>
|
||||
<div class="mt-6">
|
||||
@if ($planKey === 'pro')
|
||||
<p class="text-sm text-slate-600">Current plan</p>
|
||||
@elseif ($gatingActive && ! $hasPaidPlan)
|
||||
<form x-show="billing === 'monthly'" method="post" action="{{ route('pos.pro.subscribe') }}">@csrf<button class="btn-primary w-full">Upgrade — monthly wallet</button></form>
|
||||
@foreach ($prepaidMonths as $months)
|
||||
<form x-show="billing == {{ $months }}" method="post" action="{{ route('pos.pro.subscribe-prepaid') }}">@csrf<input type="hidden" name="plan" value="pro"><input type="hidden" name="months" value="{{ $months }}"><button type="submit" class="btn-primary w-full">Pay {{ $months }} months via Paystack</button></form>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-gradient-to-b from-slate-900 to-slate-800 p-6 text-white {{ $planKey === 'enterprise' ? 'ring-2 ring-amber-400' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-amber-300">Business</p>
|
||||
<p class="mt-2 text-3xl font-bold">{{ $currency }} {{ $enterprisePrice }}<span class="text-base font-medium text-slate-300">/mo</span></p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-200">
|
||||
<li>Everything in Pro</li>
|
||||
<li>Multi-location</li>
|
||||
<li>Advanced reporting</li>
|
||||
</ul>
|
||||
<div class="mt-6">
|
||||
@if ($planKey === 'enterprise')
|
||||
<p class="text-sm text-slate-200">Current plan</p>
|
||||
@elseif ($gatingActive && ! $hasPaidPlan)
|
||||
<form x-show="billing === 'monthly'" method="post" action="{{ route('pos.pro.subscribe-enterprise') }}">@csrf<button class="w-full rounded-xl bg-amber-400 px-4 py-2.5 text-sm font-semibold text-slate-900 hover:bg-amber-300">Upgrade — monthly wallet</button></form>
|
||||
@foreach ($prepaidMonths as $months)
|
||||
<form x-show="billing == {{ $months }}" method="post" action="{{ route('pos.pro.subscribe-prepaid') }}">@csrf<input type="hidden" name="plan" value="enterprise"><input type="hidden" name="months" value="{{ $months }}"><button type="submit" class="w-full rounded-xl bg-amber-400 px-4 py-2.5 text-sm font-semibold text-slate-900 hover:bg-amber-300">Pay {{ $months }} months via Paystack</button></form>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -107,5 +107,8 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
||||
|
||||
Route::get('/pro', [ProController::class, 'index'])->name('pos.pro.index');
|
||||
Route::post('/pro/subscribe', [ProController::class, 'subscribe'])->name('pos.pro.subscribe');
|
||||
Route::post('/pro/subscribe-enterprise', [ProController::class, 'subscribeEnterprise'])->name('pos.pro.subscribe-enterprise');
|
||||
Route::post('/pro/subscribe-prepaid', [ProController::class, 'subscribePrepaid'])->name('pos.pro.subscribe-prepaid');
|
||||
Route::get('/pro/paystack/callback', [ProController::class, 'paystackCallback'])->name('pos.pro.paystack.callback');
|
||||
Route::post('/pro/cancel', [ProController::class, 'cancel'])->name('pos.pro.cancel');
|
||||
});
|
||||
|
||||
@@ -21,6 +21,8 @@ class PosProTest extends TestCase
|
||||
'billing.api_key' => 'pos-billing-key',
|
||||
'pos.pro.enabled' => true,
|
||||
'pos.pro.price_minor' => 7900,
|
||||
'pos.plans.pro.price_minor' => 7900,
|
||||
'pos.plans.enterprise.price_minor' => 24900,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -47,6 +49,21 @@ class PosProTest extends TestCase
|
||||
$this->assertFalse(app(SubscriptionService::class)->canUseRestaurantMode($this->user()));
|
||||
}
|
||||
|
||||
public function test_subscribe_enterprise_charges_wallet_and_activates(): void
|
||||
{
|
||||
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
|
||||
$user = $this->user();
|
||||
$svc = app(SubscriptionService::class);
|
||||
|
||||
[$ok] = $svc->subscribeEnterprise($user);
|
||||
|
||||
$this->assertTrue($ok);
|
||||
$this->assertTrue($svc->isEnterprise($user));
|
||||
$sub = ProSubscription::where('user_id', $user->id)->first();
|
||||
$this->assertSame('enterprise', $sub->plan);
|
||||
$this->assertSame(24900, $sub->price_minor);
|
||||
}
|
||||
|
||||
public function test_renew_suspends_after_grace_when_unpaid(): void
|
||||
{
|
||||
Http::fake(['*/debit' => Http::response(['balance_minor' => 0], 402)]);
|
||||
|
||||
Reference in New Issue
Block a user