Gate payment gateway behind Pro and Business plans.
Deploy Ladill Events / deploy (push) Successful in 46s
Deploy Ladill Events / deploy (push) Successful in 46s
Free accounts can no longer connect or use Paystack/Flutterwave/Hubtel; settings show an upgrade path and checkout requires a paid subscription.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Payments;
|
||||
|
||||
use App\Models\PaymentGatewaySetting;
|
||||
use App\Models\User;
|
||||
use App\Services\Events\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}
|
||||
|
||||
Reference in New Issue
Block a user