Skip to content

Commit

Permalink
Move available currencies to separate function.
Browse files Browse the repository at this point in the history
Signed-off-by: Raza Mehdi <[email protected]>
  • Loading branch information
srmklive committed Jun 23, 2024
1 parent 6b6efdd commit f3a7858
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/Traits/PayPalRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand All @@ -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.
*/
Expand Down

0 comments on commit f3a7858

Please sign in to comment.