diff --git a/docs/en.md b/docs/en.md index 7d12a36..5b20a31 100644 --- a/docs/en.md +++ b/docs/en.md @@ -143,11 +143,11 @@ $balance = Payment::balance(); Payment::configure($config); // Switch to MTN for a specific transaction -Payment::withProvider('ci', Payment::MTN); +Payment::useProvider('ci', Payment::MTN); Payment::payment($data); // Switch back to default provider -Payment::withProvider('ci', Payment::ORANGE); +Payment::useProvider('ci', Payment::ORANGE); ``` ## Advanced Features diff --git a/docs/fr.md b/docs/fr.md index 421a79a..97a2d53 100644 --- a/docs/fr.md +++ b/docs/fr.md @@ -143,11 +143,11 @@ $balance = Payment::balance(); Payment::configure($config); // Basculer vers MTN pour une transaction spécifique -Payment::withProvider('ci', Payment::MTN); +Payment::useProvider('ci', Payment::MTN); Payment::payment($data); // Revenir au fournisseur par défaut -Payment::withProvider('ci', Payment::ORANGE); +Payment::useProvider('ci', Payment::ORANGE); ``` ## Fonctionnalités Avancées diff --git a/readme.md b/readme.md index 10f7af0..857263b 100644 --- a/readme.md +++ b/readme.md @@ -274,7 +274,7 @@ $balance = Payment::balance(); Payment::configure($config); // Switch to MTN for a specific transaction -Payment::withProvider('ci', Payment::MTN); +Payment::useProvider('ci', Payment::MTN); Payment::payment($data); ``` diff --git a/src/Common/PaymentStatus.php b/src/Common/PaymentStatus.php new file mode 100644 index 0000000..daecdce --- /dev/null +++ b/src/Common/PaymentStatus.php @@ -0,0 +1,13 @@ +status, ['FAILED', 'REJECTED']); } @@ -89,17 +90,19 @@ public function isPending(): bool */ public function getStatus(): string { - return $this->status; - } + if ($this->isSuccess()) { + return PaymentStatus::COMPLETED; + } - /** - * Get transaction data - * - * @return array - */ - public function getData(): array - { - return $this->data; + if ($this->isPending()) { + return PaymentStatus::PENDING; + } + + if ($this->isFailed()) { + return PaymentStatus::FAILED; + } + + return PaymentStatus::UNKNOWN; } } diff --git a/src/Gateway/IvoryCost/Orange/OrangeTransaction.php b/src/Gateway/IvoryCost/Orange/OrangeTransaction.php index d245c62..ea0c511 100644 --- a/src/Gateway/IvoryCost/Orange/OrangeTransaction.php +++ b/src/Gateway/IvoryCost/Orange/OrangeTransaction.php @@ -90,7 +90,7 @@ public function checkIfHasFail($amount, string $order_id, string $pay_token) { $status = $this->check($amount, $order_id, $pay_token); - return $status->isFail(); + return $status->isFailed(); } /** diff --git a/src/Gateway/IvoryCost/Orange/OrangeTransactionStatus.php b/src/Gateway/IvoryCost/Orange/OrangeTransactionStatus.php index 8be2f7d..887cfaa 100644 --- a/src/Gateway/IvoryCost/Orange/OrangeTransactionStatus.php +++ b/src/Gateway/IvoryCost/Orange/OrangeTransactionStatus.php @@ -2,6 +2,7 @@ namespace Bow\Payment\Gateway\IvoryCost\Orange; +use Bow\Payment\Common\PaymentStatus; use Bow\Payment\Common\ProcessorStatusInterface; class OrangeTransactionStatus implements ProcessorStatusInterface @@ -29,7 +30,7 @@ public function __construct(string $status) * * @return bool */ - public function isFail() + public function isFailed() { return $this->status == 'FAIL'; } @@ -73,4 +74,26 @@ public function isPending() { return $this->status == 'PENDING'; } + + /** + * Get payment status string + * + * @return string + */ + public function getStatus(): string + { + if ($this->isSuccess()) { + return PaymentStatus::COMPLETED; + } + + if ($this->isPending()) { + return PaymentStatus::PENDING; + } + + if ($this->isFailed()) { + return PaymentStatus::FAILED; + } + + return PaymentStatus::UNKNOWN; + } } diff --git a/src/Gateway/IvoryCost/Wave/WaveGateway.php b/src/Gateway/IvoryCost/Wave/WaveGateway.php index 93a16b9..e4ab452 100644 --- a/src/Gateway/IvoryCost/Wave/WaveGateway.php +++ b/src/Gateway/IvoryCost/Wave/WaveGateway.php @@ -2,313 +2,14 @@ namespace Bow\Payment\Gateway\IvoryCost\Wave; -use Bow\Payment\Common\ProcessorGatewayInterface; -use Bow\Payment\Exceptions\PaymentRequestException; -use Bow\Payment\Exceptions\ConfigurationException; -use Bow\Payment\Exceptions\InputValidationException; +use Bow\Payment\Shared\Wave\WaveGateway as SharedWaveGateway; /** * Wave Gateway * Implementation of Wave Checkout API * @link https://docs.wave.com/checkout */ -class WaveGateway implements ProcessorGatewayInterface +class WaveGateway extends SharedWaveGateway { - /** - * Configuration array - * - * @var array - */ - private array $config; - - /** - * Wave API client - * - * @var WaveClient - */ - private WaveClient $client; - - /** - * Create a new Wave gateway - * - * @param array $config - * @throws ConfigurationException - */ - public function __construct(array $config) - { - $this->config = $config; - $this->validateConfig(); - $this->client = new WaveClient($this->config['api_key']); - } - - /** - * Make payment - Create a Wave checkout session - * - * @param array $params - * @return array - * @throws PaymentRequestException - * - * Expected parameters: - * - amount: (required) Amount to collect - * - reference: (optional) Your unique reference - * - currency: (optional) Currency code (default: XOF) - * - optoons: (optional) Additional payment options - * - notify_url: (required) Redirect URL on notification - * - success_url: (required) Redirect URL on success - * - error_url: (required) Redirect URL on error - * - restrict_payer_mobile: (optional) Phone number (E.164 format) - * - aggregated_merchant_id: (optional) For aggregators only - * - idempotency_key: (optional) Unique key to prevent duplicate payments (auto-generated if not provided) - */ - public function payment(array $params): array - { - if (!isset($params['options']) || !is_array($params['options'])) { - $params['options'] = []; - } - - // Merge default options from config - $params['options'] = array_merge( - $this->config['options'] ?? [], - $params['options'] - ); - - // Validate required fields - $this->validatePaymentData($params); - - // Generate idempotency key if not provided (prevents duplicate payments) - $idempotencyKey = $params['options']['idempotency_key'] ?? $this->generateIdempotencyKey(); - - // Create checkout session - $session = $this->client->createCheckoutSession( - [ - 'amount' => $params['amount'], - 'currency' => $params['currency'] ?? 'XOF', - 'client_reference' => $params['reference'] ?? null, - 'notify_url' => $params['options']['notify_url'] ?? null, - 'success_url' => $params['options']['success_url'] ?? null, - 'error_url' => $params['options']['error_url'] ?? null, - 'restrict_payer_mobile' => $params['options']['restrict_payer_mobile'] ?? false, - 'aggregated_merchant_id' => $params['options']['aggregated_merchant_id'] ?? null, - ], - $idempotencyKey - ); - - return [ - 'status' => 'success', - 'reference' => $params['reference'], - 'payment_url' => $session->getWaveLaunchUrl(), - 'provider' => 'wave', - 'provider_transaction_id' => $session->getTransactionId(), - 'provider_status' => $session->getPaymentStatus(), - 'provider_data' => [ - 'success' => true, - 'session_id' => $session->getId(), - 'wave_launch_url' => $session->getWaveLaunchUrl(), - 'amount' => $session->getAmount(), - 'currency' => $args['currency'] ?? 'XOF', - 'checkout_status' => $session->getCheckoutStatus(), - 'payment_status' => $session->getPaymentStatus(), - 'transaction_id' => $session->getTransactionId(), - 'client_reference' => $session->getClientReference(), - 'when_expires' => $session->toArray()['when_expires'], - 'idempotency_key' => $idempotencyKey, - 'session' => $session, - ], - ]; - } - - /** - * Verify payment - Retrieve checkout session status - * - * @param mixed ...$args - * @return WavePaymentStatus - * @throws PaymentRequestException - * - * Expected parameters: - * - session_id: (optional) Checkout session ID - * - transaction_id: (optional) Transaction ID - * - reference: (optional) Your unique reference - * - * Note: Provide at least one of the above identifiers - */ - public function verify(array $params) - { - $session = null; - - // Try to retrieve by session ID - if (isset($params['session_id'])) { - $session = $this->client->retrieveCheckoutSession($params['session_id']); - } - // Try to retrieve by transaction ID - elseif (isset($params['transaction_id'])) { - $session = $this->client->retrieveCheckoutByTransactionId($params['transaction_id']); - } - // Try to search by client reference - elseif (isset($params['client_reference'])) { - $sessions = $this->client->searchCheckoutSessions($params['client_reference']); - if (empty($sessions)) { - throw new PaymentRequestException('No checkout session found with the provided client reference'); - } - $session = $sessions[0]; // Get the first matching session - } else { - throw new PaymentRequestException( - 'Please provide one of: session_id, transaction_id, or client_reference' - ); - } - - return new WavePaymentStatus($session); - } - - /** - * Make transfer - Not supported by Wave Checkout API - * - * @param mixed ...$args - * @return mixed - * @throws PaymentRequestException - */ - public function transfer(...$args) - { - throw new PaymentRequestException( - 'Wave transfer is not supported by the Checkout API. Use Wave Business API instead.' - ); - } - - /** - * Get balance - Not supported by Wave Checkout API - * - * @param mixed ...$args - * @return mixed - * @throws PaymentRequestException - */ - public function balance(...$args) - { - throw new PaymentRequestException( - 'Wave balance inquiry is not supported by the Checkout API. Use Wave Business API instead.' - ); - } - - /** - * Refund a checkout session - * - * @param string $sessionId - * @return bool - * @throws PaymentRequestException - */ - public function refund(string $sessionId): bool - { - return $this->client->refundCheckoutSession($sessionId); - } - - /** - * Expire a checkout session - * - * @param string $sessionId - * @return bool - * @throws PaymentRequestException - */ - public function expire(string $sessionId): bool - { - return $this->client->expireCheckoutSession($sessionId); - } - - /** - * Search for checkout sessions by client reference - * - * @param string $clientReference - * @return array - * @throws PaymentRequestException - */ - public function search(string $clientReference): array - { - return $this->client->searchCheckoutSessions($clientReference); - } - - /** - * Generate a unique idempotency key - * Uses UUID v4 format to ensure uniqueness and prevent duplicate payments - * - * @return string - */ - private function generateIdempotencyKey(): string - { - // Generate UUID v4 format - $data = random_bytes(16); - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100 - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10 - - return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); - } - - /** - * Validate configuration - * - * @throws ConfigurationException - */ - private function validateConfig(): void - { - if (empty($this->config['api_key'])) { - throw new ConfigurationException( - 'Wave API key is required. Please set "api_key" in your Wave configuration.' - ); - } - - // Validate API key format - if (!str_starts_with($this->config['api_key'], 'wave_')) { - throw new ConfigurationException( - 'Invalid Wave API key format. API key should start with "wave_".' - ); - } - } - - /** - * Validate payment data - * - * @param array $data - * @throws InputValidationException - */ - public function validatePaymentData(array $data): void - { - if (!isset($data['amount']) || empty($data['amount'])) { - throw new InputValidationException('Amount is required for Wave payment'); - } - - if (!isset($data['reference']) || empty($data['reference'])) { - throw new InputValidationException('Reference is required for Wave payment'); - } - - if (!isset($data['currency']) || empty($data['currency'])) { - throw new InputValidationException('Currency is required for Wave payment'); - } - - // Validate URLs are HTTPS - if (isset($data['options']['success_url']) && !str_starts_with($data['options']['success_url'], 'https://')) { - throw new InputValidationException('Success URL must use HTTPS protocol'); - } - - if (isset($data['options']['error_url']) && !str_starts_with($data['options']['error_url'], 'https://')) { - throw new InputValidationException('Error URL must use HTTPS protocol'); - } - - if (isset($data['options']['cancel_url']) && !str_starts_with($data['options']['cancel_url'], 'https://')) { - throw new InputValidationException('Cancel URL must use HTTPS protocol'); - } - - // Validate amount is positive - if (floatval($data['amount']) <= 0) { - throw new InputValidationException('Amount must be greater than zero'); - } - - // Validate currency if provided - if (isset($data['currency'])) { - $currency = strtoupper($data['currency']); - if ($currency === 'XOF') { - // XOF doesn't allow decimals - if (strpos((string) $data['amount'], '.') !== false) { - throw new InputValidationException( - 'XOF currency does not allow decimal places. Amount must be a whole number.' - ); - } - } - } - } + // Inherits all functionality from the shared Wave gateway } diff --git a/src/Gateway/Senegal/Wave/WaveGateway.php b/src/Gateway/Senegal/Wave/WaveGateway.php index 81a76e7..f83d14f 100644 --- a/src/Gateway/Senegal/Wave/WaveGateway.php +++ b/src/Gateway/Senegal/Wave/WaveGateway.php @@ -2,7 +2,7 @@ namespace Bow\Payment\Gateway\Senegal\Wave; -use Bow\Payment\Gateway\IvoryCost\Wave\WaveGateway as BaseWaveGateway; +use Bow\Payment\Shared\Wave\WaveGateway as SharedWaveGateway; /** * Wave Gateway for Senegal @@ -11,7 +11,7 @@ * * @link https://docs.wave.com/checkout */ -class WaveGateway extends BaseWaveGateway +class WaveGateway extends SharedWaveGateway { // Inherits all functionality from the base Wave gateway // Wave API is the same for Senegal and Ivory Coast diff --git a/src/Payment.php b/src/Payment.php index a446fe5..5c3857f 100644 --- a/src/Payment.php +++ b/src/Payment.php @@ -4,9 +4,23 @@ trait Payment { - public function withPaymentProvider(string $country, string $provider): self + /** + * Get customer phone number + * + * @return string + */ + abstract public function usingCustomerPhoneNumber(): string; + + /** + * Set payment provider + * + * @param string $country + * @param string $provider + * @return self + */ + public function usePaymentProvider(string $country, string $provider): self { - Processor::withProvider($country, $provider); + Processor::useProvider($country, $provider); return $this; } @@ -21,6 +35,7 @@ public function payment(float $amount, string $reference, array $options = []) return Processor::payment([ 'amount' => $amount, 'reference' => $reference, + 'phone_number' => $this->usingCustomerPhoneNumber(), 'options' => $options, ]); } @@ -35,6 +50,7 @@ public function transfer($amount, $reference, array $options = []) return Processor::transfer([ 'amount' => $amount, 'reference' => $reference, + 'phone_number' => $this->usingCustomerPhoneNumber(), 'options' => $options, ]); } diff --git a/src/Processor.php b/src/Processor.php index 8eedad1..27076ff 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -172,7 +172,7 @@ public static function configure(array $configuration) * @param string $provider * @return void */ - public function withProvider(string $country, string $provider): void + public function useProvider(string $country, string $provider): void { $this->resolveGateway($country, $provider); } diff --git a/src/Gateway/IvoryCost/Wave/WaveCheckoutSession.php b/src/Shared/Wave/WaveCheckoutSession.php similarity index 99% rename from src/Gateway/IvoryCost/Wave/WaveCheckoutSession.php rename to src/Shared/Wave/WaveCheckoutSession.php index c475afd..74a29a9 100644 --- a/src/Gateway/IvoryCost/Wave/WaveCheckoutSession.php +++ b/src/Shared/Wave/WaveCheckoutSession.php @@ -1,6 +1,6 @@ config = $config; + $this->validateConfig(); + $this->client = new WaveClient($this->config['api_key']); + } + + /** + * Make payment - Create a Wave checkout session + * + * @param array $params + * @return array + * @throws PaymentRequestException + * + * Expected parameters: + * - amount: (required) Amount to collect + * - reference: (optional) Your unique reference + * - currency: (optional) Currency code (default: XOF) + * - optoons: (optional) Additional payment options + * - notify_url: (required) Redirect URL on notification + * - success_url: (required) Redirect URL on success + * - error_url: (required) Redirect URL on error + * - restrict_payer_mobile: (optional) Phone number (E.164 format) + * - aggregated_merchant_id: (optional) For aggregators only + * - idempotency_key: (optional) Unique key to prevent duplicate payments (auto-generated if not provided) + */ + public function payment(array $params): array + { + if (!isset($params['options']) || !is_array($params['options'])) { + $params['options'] = []; + } + + // Merge default options from config + $params['options'] = array_merge( + $this->config['options'] ?? [], + $params['options'] + ); + + // Validate required fields + $this->validatePaymentData($params); + + // Generate idempotency key if not provided (prevents duplicate payments) + $idempotencyKey = $params['options']['idempotency_key'] ?? $this->generateIdempotencyKey(); + + // Create checkout session + $session = $this->client->createCheckoutSession( + [ + 'amount' => $params['amount'], + 'currency' => $params['currency'] ?? 'XOF', + 'client_reference' => $params['reference'] ?? null, + 'notify_url' => $params['options']['notify_url'] ?? null, + 'success_url' => $params['options']['success_url'] ?? null, + 'error_url' => $params['options']['error_url'] ?? null, + 'restrict_payer_mobile' => $params['options']['restrict_payer_mobile'] ?? false, + 'aggregated_merchant_id' => $params['options']['aggregated_merchant_id'] ?? null, + ], + $idempotencyKey + ); + + return [ + 'status' => 'success', + 'reference' => $params['reference'], + 'payment_url' => $session->getWaveLaunchUrl(), + 'provider' => 'wave', + 'provider_transaction_id' => $session->getTransactionId(), + 'provider_status' => $session->getPaymentStatus(), + 'provider_data' => [ + 'success' => true, + 'session_id' => $session->getId(), + 'wave_launch_url' => $session->getWaveLaunchUrl(), + 'amount' => $session->getAmount(), + 'currency' => $args['currency'] ?? 'XOF', + 'checkout_status' => $session->getCheckoutStatus(), + 'payment_status' => $session->getPaymentStatus(), + 'transaction_id' => $session->getTransactionId(), + 'client_reference' => $session->getClientReference(), + 'when_expires' => $session->toArray()['when_expires'], + 'idempotency_key' => $idempotencyKey, + 'session' => $session, + ], + ]; + } + + /** + * Verify payment - Retrieve checkout session status + * + * @param mixed ...$args + * @return WavePaymentStatus + * @throws PaymentRequestException + * + * Expected parameters: + * - session_id: (optional) Checkout session ID + * - transaction_id: (optional) Transaction ID + * - reference: (optional) Your unique reference + * + * Note: Provide at least one of the above identifiers + */ + public function verify(array $params) + { + $session = null; + + // Try to retrieve by session ID + if (isset($params['session_id'])) { + $session = $this->client->retrieveCheckoutSession($params['session_id']); + } + // Try to retrieve by transaction ID + elseif (isset($params['transaction_id'])) { + $session = $this->client->retrieveCheckoutByTransactionId($params['transaction_id']); + } + // Try to search by client reference + elseif (isset($params['client_reference'])) { + $sessions = $this->client->searchCheckoutSessions($params['client_reference']); + if (empty($sessions)) { + throw new PaymentRequestException('No checkout session found with the provided client reference'); + } + $session = $sessions[0]; // Get the first matching session + } else { + throw new PaymentRequestException( + 'Please provide one of: session_id, transaction_id, or client_reference' + ); + } + + return new WavePaymentStatus($session); + } + + /** + * Make transfer - Not supported by Wave Checkout API + * + * @param mixed ...$args + * @return mixed + * @throws PaymentRequestException + */ + public function transfer(...$args) + { + throw new PaymentRequestException( + 'Wave transfer is not supported by the Checkout API. Use Wave Business API instead.' + ); + } + + /** + * Get balance - Not supported by Wave Checkout API + * + * @param mixed ...$args + * @return mixed + * @throws PaymentRequestException + */ + public function balance(...$args) + { + throw new PaymentRequestException( + 'Wave balance inquiry is not supported by the Checkout API. Use Wave Business API instead.' + ); + } + + /** + * Refund a checkout session + * + * @param string $sessionId + * @return bool + * @throws PaymentRequestException + */ + public function refund(string $sessionId): bool + { + return $this->client->refundCheckoutSession($sessionId); + } + + /** + * Expire a checkout session + * + * @param string $sessionId + * @return bool + * @throws PaymentRequestException + */ + public function expire(string $sessionId): bool + { + return $this->client->expireCheckoutSession($sessionId); + } + + /** + * Search for checkout sessions by client reference + * + * @param string $clientReference + * @return array + * @throws PaymentRequestException + */ + public function search(string $clientReference): array + { + return $this->client->searchCheckoutSessions($clientReference); + } + + /** + * Generate a unique idempotency key + * Uses UUID v4 format to ensure uniqueness and prevent duplicate payments + * + * @return string + */ + private function generateIdempotencyKey(): string + { + // Generate UUID v4 format + $data = random_bytes(16); + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10 + + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + } + + /** + * Validate configuration + * + * @throws ConfigurationException + */ + private function validateConfig(): void + { + if (empty($this->config['api_key'])) { + throw new ConfigurationException( + 'Wave API key is required. Please set "api_key" in your Wave configuration.' + ); + } + + // Validate API key format + if (!str_starts_with($this->config['api_key'], 'wave_')) { + throw new ConfigurationException( + 'Invalid Wave API key format. API key should start with "wave_".' + ); + } + } + + /** + * Validate payment data + * + * @param array $data + * @throws InputValidationException + */ + public function validatePaymentData(array $data): void + { + if (!isset($data['amount']) || empty($data['amount'])) { + throw new InputValidationException('Amount is required for Wave payment'); + } + + if (!isset($data['reference']) || empty($data['reference'])) { + throw new InputValidationException('Reference is required for Wave payment'); + } + + if (!isset($data['currency']) || empty($data['currency'])) { + throw new InputValidationException('Currency is required for Wave payment'); + } + + // Validate URLs are HTTPS + if (isset($data['options']['success_url']) && !str_starts_with($data['options']['success_url'], 'https://')) { + throw new InputValidationException('Success URL must use HTTPS protocol'); + } + + if (isset($data['options']['error_url']) && !str_starts_with($data['options']['error_url'], 'https://')) { + throw new InputValidationException('Error URL must use HTTPS protocol'); + } + + if (isset($data['options']['cancel_url']) && !str_starts_with($data['options']['cancel_url'], 'https://')) { + throw new InputValidationException('Cancel URL must use HTTPS protocol'); + } + + // Validate amount is positive + if (floatval($data['amount']) <= 0) { + throw new InputValidationException('Amount must be greater than zero'); + } + + // Validate currency if provided + if (isset($data['currency'])) { + $currency = strtoupper($data['currency']); + if ($currency === 'XOF') { + // XOF doesn't allow decimals + if (strpos((string) $data['amount'], '.') !== false) { + throw new InputValidationException( + 'XOF currency does not allow decimal places. Amount must be a whole number.' + ); + } + } + } + } +} diff --git a/src/Gateway/IvoryCost/Wave/WavePaymentStatus.php b/src/Shared/Wave/WavePaymentStatus.php similarity index 91% rename from src/Gateway/IvoryCost/Wave/WavePaymentStatus.php rename to src/Shared/Wave/WavePaymentStatus.php index b9caed9..70c34a9 100644 --- a/src/Gateway/IvoryCost/Wave/WavePaymentStatus.php +++ b/src/Shared/Wave/WavePaymentStatus.php @@ -1,7 +1,8 @@ session->isPaymentCancelled() || ($this->session->isExpired() && !$this->session->isPaymentSucceeded()); } /** - * Check if payment failed (alias for isFail) + * Check if payment failed (alias for isFailed) * * @return bool */ - public function isFailed(): bool + public function isFaileded(): bool { - return $this->isFail(); + return $this->isFailed(); } /** @@ -96,18 +97,18 @@ public function isExpired(): bool public function getStatus(): string { if ($this->isSuccess()) { - return 'success'; + return PaymentStatus::COMPLETED; } if ($this->isPending()) { - return 'pending'; + return PaymentStatus::PENDING; } - if ($this->isFail()) { - return 'failed'; + if ($this->isFailed()) { + return PaymentStatus::FAILED; } - return 'unknown'; + return PaymentStatus::UNKNOWN; } /** @@ -223,7 +224,7 @@ public function toArray(): array 'status' => $this->getStatus(), 'is_success' => $this->isSuccess(), 'is_pending' => $this->isPending(), - 'is_failed' => $this->isFail(), + 'is_failed' => $this->isFailed(), 'is_expired' => $this->isExpired(), 'is_initiated' => $this->isInitiated(), 'session_id' => $this->getSessionId(),