diff --git a/src/Traits/PayPalRequest.php b/src/Traits/PayPalRequest.php index 09aecb50..bb1ce3f5 100644 --- a/src/Traits/PayPalRequest.php +++ b/src/Traits/PayPalRequest.php @@ -103,10 +103,8 @@ public function setApiCredentials(array $credentials): void */ public function setCurrency(string $currency = 'USD'): \Srmklive\PayPal\Services\PayPal { - $allowedCurrencies = ['AUD', 'BRL', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'INR', 'JPY', 'MYR', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'TWD', 'THB', 'USD', 'RUB', 'CNY']; - // Check if provided currency is valid. - if (!in_array($currency, $allowedCurrencies, true)) { + if (!in_array($currency, $this->allowedCurrencies(), true)) { throw new RuntimeException('Currency is not supported by PayPal.'); } @@ -115,6 +113,43 @@ public function setCurrency(string $currency = 'USD'): \Srmklive\PayPal\Services return $this; } + /** + * Return list of allowed currencies by PayPal. + * + * @return array + */ + public function allowedCurrencies(): array + { + return [ + 'AUD', + 'BRL', + 'CAD', + 'CNY', + 'CZK', + 'DKK', + 'EUR', + 'HKD', + 'HUF', + 'ILS', + 'INR', + 'JPY', + 'MYR', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'GBP', + 'SGD', + 'SEK', + 'CHF', + 'TWD', + 'THB', + 'USD', + 'RUB', + ]; + } + /** * Return the set currency. */