mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Check currency support for status report
This commit is contained in:
parent
9ba675d1f5
commit
195474ad6e
3 changed files with 85 additions and 0 deletions
|
@ -39,6 +39,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||
|
@ -301,4 +302,7 @@ return array(
|
|||
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
|
||||
return new DccApplies();
|
||||
},
|
||||
'api.helpers.currency-support' => static function ( ContainerInterface $container ) : CurrencySupport {
|
||||
return new CurrencySupport();
|
||||
},
|
||||
);
|
||||
|
|
70
modules/ppcp-api-client/src/Helper/CurrencySupport.php
Normal file
70
modules/ppcp-api-client/src/Helper/CurrencySupport.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Checks if the current installation uses supported currency.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Helper
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
|
||||
|
||||
/**
|
||||
* Class CurrencySupport
|
||||
*/
|
||||
class CurrencySupport {
|
||||
|
||||
/**
|
||||
* Currencies supported by PayPal.
|
||||
*
|
||||
* From https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $supported_currencies = array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CNY',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MYR',
|
||||
'MXN',
|
||||
'TWD',
|
||||
'NZD',
|
||||
'NOK',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'GBP',
|
||||
'RUB',
|
||||
'SGD',
|
||||
'SEK',
|
||||
'CHF',
|
||||
'THB',
|
||||
'USD',
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns whether the given currency is supported.
|
||||
*
|
||||
* @param string $currency 3-letter currency code.
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_currency( string $currency ): bool {
|
||||
return in_array( $currency, $this->supported_currencies, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current WC currency is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_wc_currency(): bool {
|
||||
return $this->supports_currency( get_woocommerce_currency() );
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue