Bill Queue Pro per active branch like Enterprise.
Deploy Ladill Queue / deploy (push) Successful in 33s
Deploy Ladill Queue / deploy (push) Successful in 33s
Show /branch/mo pricing with live branch totals on the plans page, charge subscribe/prepaid/renewals by branch count, and store pro_billed_branches.
This commit is contained in:
@@ -27,7 +27,11 @@ class ProController extends Controller
|
||||
: null;
|
||||
$planKey = $plans->planKey($organization);
|
||||
$branchCount = $plans->activeBranchCount($organization);
|
||||
$proPrice = $plans->proPriceMinor($organization);
|
||||
$enterprisePrice = $plans->enterprisePriceMinor($organization);
|
||||
$billedBranches = (int) ($settings['pro_billed_branches']
|
||||
?? $settings['enterprise_billed_branches']
|
||||
?? $branchCount);
|
||||
|
||||
return view('qms.pro.index', [
|
||||
'organization' => $organization,
|
||||
@@ -36,7 +40,8 @@ class ProController extends Controller
|
||||
'isEnterprise' => $planKey === 'enterprise',
|
||||
'hasPaidPlan' => $plans->hasPaidPlan($organization),
|
||||
'canManage' => $canManage,
|
||||
'proPriceMinor' => $plans->proPriceMinor(),
|
||||
'proPricePerBranchMinor' => $plans->proPricePerBranchMinor(),
|
||||
'proPriceMinor' => $proPrice,
|
||||
'enterprisePricePerBranchMinor' => $plans->enterprisePricePerBranchMinor(),
|
||||
'enterprisePriceMinor' => $enterprisePrice,
|
||||
'branchCount' => $branchCount,
|
||||
@@ -45,7 +50,9 @@ class ProController extends Controller
|
||||
'prepaidMonths' => (array) config('qms.prepaid_months', [6, 12, 24]),
|
||||
'currency' => (string) config('billing.currency', 'GHS'),
|
||||
'planExpiresAt' => $expiresAt,
|
||||
'proBilledBranches' => (int) ($settings['pro_billed_branches'] ?? $branchCount),
|
||||
'enterpriseBilledBranches' => (int) ($settings['enterprise_billed_branches'] ?? $branchCount),
|
||||
'billedBranches' => $billedBranches,
|
||||
'salesUrl' => ladill_platform_url('contact-sales'),
|
||||
]);
|
||||
}
|
||||
@@ -63,12 +70,13 @@ class ProController extends Controller
|
||||
return $this->chargeMonthlyWallet(
|
||||
$organization,
|
||||
$billing,
|
||||
$plans->proPriceMinor(),
|
||||
$plans->proPriceMinor($organization),
|
||||
'pro',
|
||||
'queue_pro',
|
||||
'queue-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Queue Pro — monthly subscription',
|
||||
'Welcome to Queue Pro — active for one month.',
|
||||
$plans->activeBranchCount($organization),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,9 +136,19 @@ class ProController extends Controller
|
||||
|
||||
$monthlyMinor = $plan === 'enterprise'
|
||||
? $plans->enterprisePriceMinor($organization)
|
||||
: $plans->proPriceMinor();
|
||||
: $plans->proPriceMinor($organization);
|
||||
$amountMinor = $monthlyMinor * $months;
|
||||
$branches = $plan === 'enterprise' ? $plans->activeBranchCount($organization) : null;
|
||||
$branches = $plans->activeBranchCount($organization);
|
||||
|
||||
$metadata = [
|
||||
'organization_id' => $organization->id,
|
||||
'billed_branches' => $branches,
|
||||
];
|
||||
if ($plan === 'enterprise') {
|
||||
$metadata['enterprise_billed_branches'] = $branches;
|
||||
} else {
|
||||
$metadata['pro_billed_branches'] = $branches;
|
||||
}
|
||||
|
||||
try {
|
||||
$checkout = $billing->initiatePlanCheckout(
|
||||
@@ -139,10 +157,7 @@ class ProController extends Controller
|
||||
$months,
|
||||
$amountMinor,
|
||||
route('qms.pro.paystack.callback'),
|
||||
array_filter([
|
||||
'organization_id' => $organization->id,
|
||||
'enterprise_billed_branches' => $branches,
|
||||
], static fn ($v) => $v !== null),
|
||||
$metadata,
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('qms.pro.index')
|
||||
@@ -191,9 +206,13 @@ class ProController extends Controller
|
||||
|
||||
$plan = (string) ($result['plan'] ?? 'pro');
|
||||
$months = (int) ($result['months'] ?? 0);
|
||||
$branches = isset($metadata['enterprise_billed_branches'])
|
||||
? (int) $metadata['enterprise_billed_branches']
|
||||
: null;
|
||||
$branches = isset($metadata['billed_branches'])
|
||||
? (int) $metadata['billed_branches']
|
||||
: (isset($metadata['pro_billed_branches'])
|
||||
? (int) $metadata['pro_billed_branches']
|
||||
: (isset($metadata['enterprise_billed_branches'])
|
||||
? (int) $metadata['enterprise_billed_branches']
|
||||
: null));
|
||||
|
||||
$this->activatePrepaidPlan($organization, $plan, $months, $branches);
|
||||
|
||||
@@ -212,7 +231,7 @@ class ProController extends Controller
|
||||
string $reference,
|
||||
string $description,
|
||||
string $successMessage,
|
||||
?int $enterpriseBranches = null,
|
||||
?int $billedBranches = null,
|
||||
): RedirectResponse {
|
||||
try {
|
||||
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
|
||||
@@ -244,9 +263,7 @@ class ProController extends Controller
|
||||
$settings['plan_expires_at'] = now()
|
||||
->addDays((int) config('qms.pro.period_days', 30))
|
||||
->toIso8601String();
|
||||
if ($enterpriseBranches !== null) {
|
||||
$settings['enterprise_billed_branches'] = $enterpriseBranches;
|
||||
}
|
||||
$this->applyBilledBranches($settings, $plan, $billedBranches);
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
|
||||
@@ -257,17 +274,33 @@ class ProController extends Controller
|
||||
Organization $organization,
|
||||
string $plan,
|
||||
int $months,
|
||||
?int $enterpriseBranches = null,
|
||||
?int $billedBranches = null,
|
||||
): void {
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = false;
|
||||
$settings['billing_method'] = 'paystack_prepaid';
|
||||
$settings['plan_expires_at'] = now()->addMonths($months)->toIso8601String();
|
||||
if ($enterpriseBranches !== null) {
|
||||
$settings['enterprise_billed_branches'] = $enterpriseBranches;
|
||||
}
|
||||
$this->applyBilledBranches($settings, $plan, $billedBranches);
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
private function applyBilledBranches(array &$settings, string $plan, ?int $billedBranches): void
|
||||
{
|
||||
if ($billedBranches === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($plan === 'enterprise') {
|
||||
$settings['enterprise_billed_branches'] = $billedBranches;
|
||||
unset($settings['pro_billed_branches']);
|
||||
} else {
|
||||
$settings['pro_billed_branches'] = $billedBranches;
|
||||
unset($settings['enterprise_billed_branches']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user