117 lines
2.9 KiB
PHP
117 lines
2.9 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.
|
|
* @property-read string $endpoint The host endpoint for the payment mode.
|
|
*/
|
|
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,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Enum payment modes endpoints
|
|
*
|
|
* This is to allow in cors in App Service Provider
|
|
*
|
|
* @return array<\App\Lib\Payments\PaymentAdapter>
|
|
*/
|
|
protected static function endpoints(): array
|
|
{
|
|
return [
|
|
'inShop' => \parse_url(\config('app.url'), \PHP_URL_HOST),
|
|
'stripe' => 'stripe.fr',
|
|
'systemPay' => 'systempay.fr'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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()];
|
|
}
|
|
if ($attribute === 'endpoint') {
|
|
return $this->endpoints()[$this->getDefinition()];
|
|
}
|
|
return parent::__get($attribute);
|
|
}
|
|
}
|