From 98dbe19a5a5091ae6549c32d91b58f6c94a507c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Tue, 19 Sep 2023 17:16:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(enum):=20=E5=A2=9E=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9B=B8=E5=85=B3=E7=9A=84=E6=9E=9A=E4=B8=BE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Enum/CurrencyEnum.php | 23 ++++++++++++++++ src/Enum/OrderStatus.php | 54 ++++++++++++++++++++++++++++++++++++++ src/Enum/PaymentMethod.php | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 src/Enum/CurrencyEnum.php create mode 100644 src/Enum/OrderStatus.php create mode 100644 src/Enum/PaymentMethod.php diff --git a/src/Enum/CurrencyEnum.php b/src/Enum/CurrencyEnum.php new file mode 100644 index 0000000..7cdad5a --- /dev/null +++ b/src/Enum/CurrencyEnum.php @@ -0,0 +1,23 @@ + + * 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); + } +} diff --git a/src/Enum/OrderStatus.php b/src/Enum/OrderStatus.php new file mode 100644 index 0000000..6c97972 --- /dev/null +++ b/src/Enum/OrderStatus.php @@ -0,0 +1,54 @@ + + * Powered by PhpStorm + * Created on 2023/5/19 + */ + +declare(strict_types=1); + +namespace Singularity\HDK\Pay\Enum; + +/** + * App\Enum\OrderStatus@LuxPay + * + * @author 李东云 + * 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 + // }; + // } +} diff --git a/src/Enum/PaymentMethod.php b/src/Enum/PaymentMethod.php new file mode 100644 index 0000000..eedd265 --- /dev/null +++ b/src/Enum/PaymentMethod.php @@ -0,0 +1,53 @@ + + * Powered by PhpStorm + * Created on 2023/9/19 + */ + +namespace Singularity\HDK\Pay\Enum; + +enum PaymentMethod: string +{ + case Stripe = 'stripe'; + + case WechatPay = 'wechat'; + + /** + * @return array + */ + 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; + } +}