Deploy Ladill Mini / deploy (push) Successful in 23s
Staff-facing counter register at pos.ladill.com with catalog cart, cash and MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and Merchant catalog import. Co-authored-by: Cursor <cursoragent@cursor.com>
123 lines
3.6 KiB
PHP
123 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\DomainOrder;
|
|
use App\Models\RcServiceOrder;
|
|
use Illuminate\Support\Collection;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* ResellerClub is legacy-only for new sales. Renewals and management remain available
|
|
* for customers with existing ResellerClub services.
|
|
*/
|
|
final class ResellerClubLegacy
|
|
{
|
|
public static function integrationEnabled(): bool
|
|
{
|
|
return (bool) config('hosting.legacy.rc_enabled', true);
|
|
}
|
|
|
|
public static function newOrdersEnabled(): bool
|
|
{
|
|
return self::integrationEnabled()
|
|
&& (bool) config('hosting.legacy.rc_new_orders_enabled', false);
|
|
}
|
|
|
|
public static function renewalsEnabled(): bool
|
|
{
|
|
return self::integrationEnabled()
|
|
&& (bool) config('hosting.legacy.rc_renewals_enabled', true);
|
|
}
|
|
|
|
public static function isRenewalRcServiceOrder(RcServiceOrder $order): bool
|
|
{
|
|
if ($order->order_type === RcServiceOrder::TYPE_RENEWAL) {
|
|
return true;
|
|
}
|
|
|
|
return (bool) data_get($order->meta, 'is_renewal', false);
|
|
}
|
|
|
|
public static function isRenewalDomainOrder(DomainOrder $order): bool
|
|
{
|
|
return $order->order_type === DomainOrder::TYPE_RENEWAL;
|
|
}
|
|
|
|
public static function canAutomateFulfillment(RcServiceOrder $order): bool
|
|
{
|
|
if (! self::integrationEnabled()) {
|
|
return false;
|
|
}
|
|
|
|
if (self::newOrdersEnabled()) {
|
|
return true;
|
|
}
|
|
|
|
return self::renewalsEnabled() && self::isRenewalRcServiceOrder($order);
|
|
}
|
|
|
|
/**
|
|
* @param Collection<int, RcServiceOrder>|iterable<int, RcServiceOrder> $items
|
|
*/
|
|
public static function assertCartCheckoutAllowed(iterable $items): void
|
|
{
|
|
$items = $items instanceof Collection ? $items : collect($items);
|
|
|
|
if ($items->isEmpty()) {
|
|
throw new RuntimeException('Your cart is empty.');
|
|
}
|
|
|
|
if (self::newOrdersEnabled()) {
|
|
return;
|
|
}
|
|
|
|
if (! self::renewalsEnabled()) {
|
|
throw new RuntimeException(self::renewalsDisabledMessage());
|
|
}
|
|
|
|
if ($items->contains(fn (RcServiceOrder $item) => ! self::isRenewalRcServiceOrder($item))) {
|
|
throw new RuntimeException(
|
|
'ResellerClub checkout is limited to renewals for existing services. '
|
|
.'New product purchases use our current domain and hosting products instead.'
|
|
);
|
|
}
|
|
}
|
|
|
|
public static function assertNewSaleAllowed(): void
|
|
{
|
|
if (self::newOrdersEnabled()) {
|
|
return;
|
|
}
|
|
|
|
throw new RuntimeException(
|
|
'ResellerClub is no longer available for new product purchases. '
|
|
.'Use our domain and hosting products instead, or renew an existing ResellerClub service from your dashboard.'
|
|
);
|
|
}
|
|
|
|
public static function assertRenewalsAllowed(): void
|
|
{
|
|
if (! self::renewalsEnabled()) {
|
|
throw new RuntimeException(self::renewalsDisabledMessage());
|
|
}
|
|
}
|
|
|
|
/** @deprecated Use assertNewSaleAllowed() */
|
|
public static function assertNewOrdersAllowed(): void
|
|
{
|
|
self::assertNewSaleAllowed();
|
|
}
|
|
|
|
public static function renewalsDisabledMessage(): string
|
|
{
|
|
return 'ResellerClub renewals are not available at this time. Please contact support if you need assistance.';
|
|
}
|
|
|
|
public static function fulfillmentDisabledMessage(): string
|
|
{
|
|
return 'Automated ResellerClub fulfillment for new purchases is no longer available. '
|
|
.'Open a support ticket if you need help with a legacy order.';
|
|
}
|
|
}
|