ldc-boutique-cnc/app/Enums/Order/PaymentModeEnum.php
2023-03-17 16:09:49 +01:00

97 lines
2.3 KiB
PHP

<?php
namespace App\Enums\Order;
use App\Lib\Payments\Adapters\InShopPaymentAdapter;
use App\Lib\Payments\Adapters\StripePaymentAdapter;
use App\Lib\Payments\Adapters\SystemPayPaymentAdapter;
use Kwaadpepper\Enum\BaseEnumRoutable;
/**
* @method static self inShop()
* Payment in the selected shop when retriving the order
* @method static self stripe()
* Payment using Stripe services
* @method static self systemPay()
* Payment using SystemPay services
*
* @property-read string $adapter The adpater (\App\Lib\Payments\PaymentAdapter) to use for the payment mode.
* @property-read integer $minAmount The minimal amount to use the payment mode in cents.
*/
final class PaymentModeEnum extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
'inShop' => 1,
'stripe' => 2,
'systemPay' => 3
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [
'inShop' => __('Au magasin'),
'stripe' => __('Stripe'),
'systemPay' => __('SystemPay')
];
}
/**
* Enum rates
*
* @return array<\App\Lib\Payments\PaymentAdapter>
*/
protected static function adapterClasses(): array
{
return [
'inShop' => InShopPaymentAdapter::class,
'stripe' => StripePaymentAdapter::class,
'systemPay' => SystemPayPaymentAdapter::class,
];
}
/**
* Enum minimal amounts in cents
*
* TODO: Set min amounts (and max) in settings.
*
* @return array<\App\Lib\Payments\PaymentAdapter>
*/
protected static function minAmount(): array
{
return [
'inShop' => 0,
// * 50 cents
'stripe' => 50,
// * 1 euro
'systemPay' => 100,
];
}
/**
* @param string $attribute
* @return integer|string
*/
public function __get(string $attribute)
{
if ($attribute === 'adapter') {
return $this->adapterClasses()[$this->getDefinition()];
}
if ($attribute === 'minAmount') {
return $this->minAmount()[$this->getDefinition()];
}
return parent::__get($attribute);
}
}