Check currency support for status report

This commit is contained in:
Alex P 2021-11-22 18:20:00 +02:00
parent 9ba675d1f5
commit 195474ad6e
3 changed files with 85 additions and 0 deletions

View file

@ -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();
},
);

View 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() );
}
}

View file

@ -16,6 +16,7 @@ use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\State;
@ -53,6 +54,9 @@ class StatusReportModule implements ModuleInterface {
/* @var Bearer $bearer The bearer. */
$bearer = $c->get( 'api.bearer' );
$currency_support = $c->get( 'api.helpers.currency-support' );
assert( $currency_support instanceof CurrencySupport );
/* @var DccApplies $dcc_applies The ddc applies. */
$dcc_applies = $c->get( 'api.helpers.dccapplies' );
@ -75,6 +79,13 @@ class StatusReportModule implements ModuleInterface {
'description' => esc_html__( 'Country / State value on Settings / General / Store Address.', 'woocommerce-paypal-payments' ),
'value' => wc_get_base_location()['country'],
),
array(
'label' => esc_html__( 'WooCommerce currency supported', 'woocommerce-paypal-payments' ),
'description' => esc_html__( 'Whether PayPal supports the default store currency or not.', 'woocommerce-paypal-payments' ),
'value' => $this->bool_to_text(
$currency_support->supports_wc_currency()
),
),
array(
'label' => esc_html__( 'PayPal card processing available in country', 'woocommerce-paypal-payments' ),
'description' => esc_html__( 'Whether PayPal card processing is available in country or not.', 'woocommerce-paypal-payments' ),