diff --git a/modules/ppcp-api-client/src/Entity/Item.php b/modules/ppcp-api-client/src/Entity/Item.php index dd661301e..93576e86a 100644 --- a/modules/ppcp-api-client/src/Entity/Item.php +++ b/modules/ppcp-api-client/src/Entity/Item.php @@ -83,6 +83,7 @@ class Item { * @param Money|null $tax The tax. * @param string $sku The SKU. * @param string $category The category. + * @param float $tax_rate The tax rate. */ public function __construct( string $name, @@ -102,8 +103,8 @@ class Item { $this->tax = $tax; $this->sku = $sku; $this->category = ( self::DIGITAL_GOODS === $category ) ? self::DIGITAL_GOODS : self::PHYSICAL_GOODS; - $this->category = $category; - $this->tax_rate = $tax_rate; + $this->category = $category; + $this->tax_rate = $tax_rate; } /** @@ -174,9 +175,8 @@ class Item { * * @return float */ - public function tax_rate():float - { - return round((float) $this->tax_rate, 2); + public function tax_rate():float { + return round( (float) $this->tax_rate, 2 ); } /** @@ -198,7 +198,7 @@ class Item { $item['tax'] = $this->tax()->to_array(); } - if ($this->tax_rate()) { + if ( $this->tax_rate() ) { $item['tax_rate'] = (string) $this->tax_rate(); } diff --git a/modules/ppcp-api-client/src/Entity/OrderStatus.php b/modules/ppcp-api-client/src/Entity/OrderStatus.php index 397ae8b64..e2dec053b 100644 --- a/modules/ppcp-api-client/src/Entity/OrderStatus.php +++ b/modules/ppcp-api-client/src/Entity/OrderStatus.php @@ -15,14 +15,14 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; * Class OrderStatus */ class OrderStatus { - const INTERNAL = 'INTERNAL'; - const CREATED = 'CREATED'; - const SAVED = 'SAVED'; - const APPROVED = 'APPROVED'; - const VOIDED = 'VOIDED'; - const COMPLETED = 'COMPLETED'; - const PENDING_APPROVAL = 'PENDING_APPROVAL'; - const VALID_STATUS = array( + const INTERNAL = 'INTERNAL'; + const CREATED = 'CREATED'; + const SAVED = 'SAVED'; + const APPROVED = 'APPROVED'; + const VOIDED = 'VOIDED'; + const COMPLETED = 'COMPLETED'; + const PENDING_APPROVAL = 'PENDING_APPROVAL'; + const VALID_STATUS = array( self::INTERNAL, self::CREATED, self::SAVED, diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php index aa8be50c4..3bd277807 100644 --- a/modules/ppcp-api-client/src/Factory/ItemFactory.php +++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php @@ -58,7 +58,7 @@ class ItemFactory { $price_without_tax = (float) wc_get_price_excluding_tax( $product ); $price_without_tax_rounded = round( $price_without_tax, 2 ); $tax = round( $price - $price_without_tax_rounded, 2 ); - $tax_rates = WC_Tax::get_rates($product->get_tax_class()); + $tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); $tax = new Money( $tax + $shipping_tax, $this->currency ); $tax = new Money( $tax, $this->currency ); return new Item( @@ -69,7 +69,7 @@ class ItemFactory { $tax, $product->get_sku(), ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS, - reset($tax_rates)['rate'] ?? 0 + reset( $tax_rates )['rate'] ?? 0 ); }, $cart->get_cart_contents() @@ -141,7 +141,7 @@ class ItemFactory { $price_without_tax_rounded = round( $price_without_tax, 2 ); $tax = round( $price - $price_without_tax_rounded, 2 ); $tax = new Money( $tax, $currency ); - $tax_rates = WC_Tax::get_rates($product->get_tax_class()); + $tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); return new Item( mb_substr( $product->get_name(), 0, 127 ), @@ -151,7 +151,7 @@ class ItemFactory { $tax, $product->get_sku(), ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS, - reset($tax_rates)['rate'] ?? 0 + reset( $tax_rates )['rate'] ?? 0 ); } diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php index d8ada8567..7bf902dcb 100644 --- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php +++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php @@ -72,6 +72,9 @@ class PartnerReferralsData { * @return array */ public function data(): array { + /** + * Returns the partners referrals data. + */ return apply_filters( 'ppcp_partner_referrals_data', array( diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php index 29301c85e..d92446054 100644 --- a/modules/ppcp-onboarding/services.php +++ b/modules/ppcp-onboarding/services.php @@ -187,10 +187,11 @@ return array( $logger ); }, - 'onboarding.endpoint.pui' => static function(ContainerInterface $container) : PayUponInvoiceEndpoint { + 'onboarding.endpoint.pui' => static function( ContainerInterface $container ) : PayUponInvoiceEndpoint { return new PayUponInvoiceEndpoint( $container->get( 'wcgateway.settings' ), - $container->get( 'button.request-data' ) + $container->get( 'button.request-data' ), + $container->get( 'woocommerce.logger.woocommerce' ) ); }, 'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals { diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php index 8f669e9b4..8c65cc803 100644 --- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php +++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php @@ -145,8 +145,8 @@ class OnboardingAssets { 'error_messages' => array( 'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ), ), - 'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ), - 'pui_nonce' => wp_create_nonce( 'ppc-pui' ), + 'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ), + 'pui_nonce' => wp_create_nonce( 'ppc-pui' ), ); } diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php index 474840122..6700236df 100644 --- a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php +++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php @@ -9,47 +9,83 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint; +use Exception; +use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface; use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; +use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; +/** + * Class PayUponInvoiceEndpoint + */ class PayUponInvoiceEndpoint implements EndpointInterface { /** + * The settings. + * * @var Settings */ protected $settings; /** + * The request data. + * * @var RequestData */ protected $request_data; - public function __construct(Settings $settings, RequestData $request_data) - { - $this->settings = $settings; + /** + * The logger. + * + * @var LoggerInterface + */ + protected $logger; + + /** + * PayUponInvoiceEndpoint constructor. + * + * @param Settings $settings The settings. + * @param RequestData $request_data The request data. + * @param LoggerInterface $logger The logger. + */ + public function __construct( Settings $settings, RequestData $request_data, LoggerInterface $logger ) { + $this->settings = $settings; $this->request_data = $request_data; + $this->logger = $logger; } - public static function nonce(): string - { + /** + * The nonce. + * + * @return string + */ + public static function nonce(): string { return 'ppc-pui'; } - public function handle_request(): bool - { + /** + * * Handles the request. + * + * @return bool + * @throws NotFoundException When order not found or handling failed. + */ + public function handle_request(): bool { try { $data = $this->request_data->read_request( $this->nonce() ); - $this->settings->set('ppcp-onboarding-pui', $data['checked']); + $this->settings->set( 'ppcp-onboarding-pui', $data['checked'] ); $this->settings->persist(); - } catch (\Exception $exception) { - + } catch ( Exception $exception ) { + $this->logger->error( $exception->getMessage() ); } - wp_send_json_success([ - $this->settings->get('ppcp-onboarding-pui'), - ]); + wp_send_json_success( + array( + $this->settings->get( 'ppcp-onboarding-pui' ), + ) + ); + return true; } } diff --git a/modules/ppcp-onboarding/src/OnboardingModule.php b/modules/ppcp-onboarding/src/OnboardingModule.php index 3f35cfd9e..767d47839 100644 --- a/modules/ppcp-onboarding/src/OnboardingModule.php +++ b/modules/ppcp-onboarding/src/OnboardingModule.php @@ -97,7 +97,7 @@ class OnboardingModule implements ModuleInterface { ); add_action( - 'wc_ajax_' . 'ppc-pui', + 'wc_ajax_ppc-pui', static function () use ( $c ) { $endpoint = $c->get( 'onboarding.endpoint.pui' ); $endpoint->handle_request(); diff --git a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php index 24c1c2340..dc02c0d9d 100644 --- a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php +++ b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Onboarding\Render; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; +use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; /** * Class OnboardingRenderer @@ -30,6 +31,8 @@ class OnboardingOptionsRenderer { private $country; /** + * The settings. + * * @var Settings */ protected $settings; @@ -37,13 +40,14 @@ class OnboardingOptionsRenderer { /** * OnboardingOptionsRenderer constructor. * - * @param string $module_url The module url (for assets). - * @param string $country 2-letter country code of the shop. + * @param string $module_url The module url (for assets). + * @param string $country 2-letter country code of the shop. + * @param Settings $settings The settings. */ - public function __construct( string $module_url, string $country, Settings $settings) { + public function __construct( string $module_url, string $country, Settings $settings ) { $this->module_url = $module_url; $this->country = $country; - $this->settings = $settings; + $this->settings = $settings; } /** @@ -66,16 +70,22 @@ class OnboardingOptionsRenderer {
  • ' . $this->render_dcc( $is_shop_supports_dcc ) . '
  • ' . $this->render_pui_option() -. ''; + . ''; } + /** + * Renders pui option. + * + * @return string + * @throws NotFoundException When setting is not found. + */ private function render_pui_option(): string { - if($this->country === 'DE') { + if ( 'DE' === $this->country ) { $checked = 'checked'; - if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') { + if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) { $checked = ''; } - return '