feat(enum): 增加订单相关的枚举类型

This commit is contained in:
李东云
2023-09-19 17:16:13 +08:00
parent bda7e57f39
commit 98dbe19a5a
3 changed files with 130 additions and 0 deletions

23
src/Enum/CurrencyEnum.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
/**
* Currencies.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/17
*/
namespace Singularity\HDK\Pay\Enum;
use Money\Currency;
enum CurrencyEnum
{
case CNY;
case USD;
public function getInstance(): Currency
{
return new Currency($this->name);
}
}

54
src/Enum/OrderStatus.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
/**
* OrderStatus.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/19
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Enum;
/**
* App\Enum\OrderStatus@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/19
*/
enum OrderStatus: string
{
case Created = "Created";
case Paid = 'Paid';
case Cancelled = 'Cancelled';
case Closed = 'Closed';
/**
* @return string[]
*/
public static function all(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->name;
}
return $list;
}
// public static function from(string $value): ?OrderStatus
// {
// var_dump($value, __METHOD__);
// return match ($value) {
// 'Created' => OrderStatus::Created,
// 'Paid' => OrderStatus::Paid,
// 'Cancelled' => OrderStatus::Cancelled,
// 'Closed' => OrderStatus::Closed,
// default => null
// };
// }
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* PaymentMethod.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/19
*/
namespace Singularity\HDK\Pay\Enum;
enum PaymentMethod: string
{
case Stripe = 'stripe';
case WechatPay = 'wechat';
/**
* @return array<string, string>
*/
public static function all(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[$key->name] = $key->value;
}
return $list;
}
/**
* @return string[]
*/
public function values(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->value;
}
return $list;
}
/**
* @return string[]
*/
public function keys(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->name;
}
return $list;
}
}