Gate payment gateway behind Pro and Business plans.
Deploy Ladill POS / deploy (push) Successful in 1m9s

Free accounts keep cash sales only; connecting a gateway and card/MoMo
checkout require a paid plan, with settings upsell copy for free users.
This commit is contained in:
isaacclad
2026-07-15 21:04:09 +00:00
parent 689c9924df
commit 836aa83f41
6 changed files with 133 additions and 32 deletions
@@ -53,6 +53,7 @@ class SettingsController extends Controller
'tables' => $this->scopeToLocation($request, PosTable::owned($owner))
->orderBy('area')->orderBy('position')->orderBy('label')->get(),
'gateway' => $this->gateway->settingFor($account),
'canUsePaymentGateway' => $this->subscriptions->canUsePaymentGateway($account),
]);
}
@@ -144,6 +145,7 @@ class SettingsController extends Controller
/**
* Upsert merchant gateway credentials for the acting account.
* Blank secret fields keep the previously stored encrypted values.
* Free plan cannot connect or change gateway credentials.
*/
protected function persistGateway(Request $request, User $user): void
{
@@ -160,6 +162,11 @@ class SettingsController extends Controller
return;
}
if (! $this->subscriptions->canUsePaymentGateway($user)) {
// Ignore gateway fields on free plan (other settings may still save).
return;
}
$attributes = [
'provider' => $provider !== '' ? $provider : $existing->provider,
'is_active' => $request->boolean('gateway_is_active'),
@@ -4,6 +4,7 @@ namespace App\Services\Payments;
use App\Models\PaymentGatewaySetting;
use App\Models\User;
use App\Services\Pos\SubscriptionService;
use Illuminate\Support\Facades\Http;
use RuntimeException;
@@ -18,6 +19,10 @@ class MerchantGatewayService
public function isConfigured(User|string $owner): bool
{
if (! $this->ownerMayUseGateway($owner)) {
return false;
}
return (bool) $this->settingFor($owner)?->isConfigured();
}
@@ -62,6 +67,10 @@ class MerchantGatewayService
protected function requireConfigured(User|string $owner): PaymentGatewaySetting
{
if (! $this->ownerMayUseGateway($owner)) {
throw new RuntimeException('Connecting your own payment gateway requires a paid plan. Upgrade to Pro or Business.');
}
$setting = $this->settingFor($owner);
if (! $setting?->isConfigured()) {
throw new RuntimeException('Connect Paystack, Flutterwave, or Hubtel in Settings before accepting online payments.');
@@ -70,6 +79,19 @@ class MerchantGatewayService
return $setting;
}
protected function ownerMayUseGateway(User|string $owner): bool
{
$user = $owner instanceof User
? $owner
: User::query()->where('public_id', (string) $owner)->first();
if (! $user) {
return false;
}
return app(SubscriptionService::class)->canUsePaymentGateway($user);
}
/**
* @param array<string, mixed> $metadata
* @return array{checkout_url: string, reference: string, provider: string}
+6
View File
@@ -69,6 +69,12 @@ class SubscriptionService
return $this->hasPaidPlan($user);
}
/** Own payment gateway (Paystack / Flutterwave / Hubtel) requires Pro or Business. */
public function canUsePaymentGateway(User $user): bool
{
return $this->hasPaidPlan($user);
}
public function productCount(string $ownerRef, bool $restaurant): int
{
if ($restaurant) {
+1 -1
View File
@@ -46,7 +46,7 @@ return [
'upgrade_banner' => [
'title' => 'Unlock POS Pro or Business',
'description' => 'Unlimited registers & catalog, stock tracking & ecosystem sync — from GHS 790/mo.',
'description' => 'Your own payment gateway, unlimited catalog, multi-branch & team — from GHS 790/mo.',
'route' => 'pos.pro.index',
],
];
+9 -1
View File
@@ -123,8 +123,9 @@
<div class="border-t border-slate-100 pt-4">
<p class="text-sm font-semibold text-slate-900">Payment gateway</p>
<p class="mt-1 text-xs text-slate-400">Connect Paystack, Flutterwave, or Hubtel. Online checkouts go 100% to you 0% Ladill fee.</p>
<p class="mt-1 text-xs text-slate-400">Connect Paystack, Flutterwave, or Hubtel. Online checkouts go 100% to you 0% Ladill fee. Pro &amp; Business plans only.</p>
</div>
@if ($canUsePaymentGateway ?? false)
<div>
<label class="text-sm font-medium text-slate-700">Provider</label>
<select name="gateway_provider" class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@@ -161,6 +162,13 @@
@else
<p class="rounded-xl bg-amber-50 px-3 py-2 text-sm text-amber-800">Online checkouts stay disabled until a gateway is connected.</p>
@endif
@else
<div class="rounded-xl border border-indigo-100 bg-indigo-50 px-4 py-3 text-sm text-indigo-900">
<p class="font-medium">Your own payment gateway is a Pro feature</p>
<p class="mt-1 text-indigo-800/80">Upgrade to Pro or Business to connect Paystack, Flutterwave, or Hubtel and take card / MoMo payments with 0% Ladill fee. Cash sales stay free.</p>
<a href="{{ route('pos.pro.index') }}" class="mt-3 inline-flex text-sm font-semibold text-indigo-700 hover:text-indigo-900">View plans </a>
</div>
@endif
<div class="flex justify-end">
<button type="submit" class="btn-primary">Save settings</button>
+58
View File
@@ -2,6 +2,7 @@
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Pos\ProSubscription;
use App\Models\User;
use App\Services\Pos\SubscriptionService;
@@ -16,6 +17,7 @@ class PosProTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config([
'billing.api_url' => 'https://ladill.com/api/billing',
'billing.api_key' => 'pos-billing-key',
@@ -49,6 +51,62 @@ class PosProTest extends TestCase
$this->assertFalse(app(SubscriptionService::class)->canUseRestaurantMode($this->user()));
}
public function test_free_user_cannot_use_payment_gateway(): void
{
$user = $this->user();
$svc = app(SubscriptionService::class);
$this->assertFalse($svc->canUsePaymentGateway($user));
$this->assertFalse(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
public function test_pro_user_can_use_payment_gateway_when_configured(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
$svc->subscribe($user);
\App\Models\PaymentGatewaySetting::create([
'owner_ref' => $user->public_id,
'provider' => \App\Models\PaymentGatewaySetting::PROVIDER_PAYSTACK,
'public_key' => 'pk_test',
'secret_key' => 'sk_test',
'is_active' => true,
]);
$this->assertTrue($svc->canUsePaymentGateway($user));
$this->assertTrue(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
public function test_free_user_settings_ignores_gateway_credentials(): void
{
$user = $this->user();
\App\Models\PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main',
'currency' => 'GHS',
]);
$this->actingAs($user)
->put(route('pos.settings.update'), [
'name' => 'Main',
'currency' => 'GHS',
'service_style' => 'retail',
'printer_paper_mm' => 80,
'gateway_provider' => \App\Models\PaymentGatewaySetting::PROVIDER_PAYSTACK,
'gateway_public_key' => 'pk_free_blocked',
'gateway_secret_key' => 'sk_free_blocked',
'gateway_is_active' => '1',
])
->assertRedirect()
->assertSessionHas('success');
$this->assertNull(
\App\Models\PaymentGatewaySetting::query()->where('owner_ref', $user->public_id)->first()
);
}
public function test_subscribe_enterprise_charges_wallet_and_activates(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);