stadem /
viva-payments
| 1 | <?php |
||
| 2 | namespace Stadem\VivaPayments\Enums; |
||
| 3 | enum OrderStatus : int |
||
| 4 | { |
||
| 5 | case PENDING = 0; |
||
| 6 | case EXPIRED = 1; |
||
| 7 | case CANCELED = 2; |
||
| 8 | case PAID = 3; |
||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | public function type(): int |
||
| 13 | { |
||
| 14 | return match($this) |
||
| 15 | { |
||
| 16 | OrderStatus::PENDING => 'Pending', |
||
| 17 | OrderStatus::EXPIRED => 'Expired', |
||
| 18 | OrderStatus::CANCELED => 'Canceled', |
||
| 19 | OrderStatus::PAID => 'Paid', |
||
| 20 | }; |
||
| 21 | } |
||
| 22 | |||
| 23 | public static function fromValue(int $value): string |
||
| 24 | { |
||
| 25 | foreach (self::cases() as $status) { |
||
| 26 | if( $value === $status->value ){ |
||
| 27 | return $status->name; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 28 | } |
||
| 29 | } |
||
| 30 | throw new \ValueError("$value is not a valid backing value for enum " . self::class ); |
||
| 31 | } |
||
| 32 | |||
| 33 | } |
||
| 34 | |||
| 35 | // https://developer.viva.com/apis-for-payments/payment-api/#tag/Payments/paths/~1api~1orders~1{orderCode}/get |
||
| 36 |