From de609be21b40cda90192e1642f96e46f357b52fb Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 18 Oct 2024 08:14:50 +0200 Subject: [PATCH 1/5] Add paypal & ratepay default icons to classic checkout --- modules/ppcp-wc-gateway/assets/images/paypal.svg | 3 +++ modules/ppcp-wc-gateway/assets/images/ratepay.svg | 3 +++ modules/ppcp-wc-gateway/services.php | 6 ++++-- .../ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 13 ++++++++++++- .../PayUponInvoice/PayUponInvoiceGateway.php | 14 +++++++++++++- 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 modules/ppcp-wc-gateway/assets/images/paypal.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/ratepay.svg diff --git a/modules/ppcp-wc-gateway/assets/images/paypal.svg b/modules/ppcp-wc-gateway/assets/images/paypal.svg new file mode 100644 index 000000000..0d82f0b74 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/paypal.svg @@ -0,0 +1,3 @@ + + + diff --git a/modules/ppcp-wc-gateway/assets/images/ratepay.svg b/modules/ppcp-wc-gateway/assets/images/ratepay.svg new file mode 100644 index 000000000..1e8030e33 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/ratepay.svg @@ -0,0 +1,3 @@ + + + diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 9ed1a83a8..8d2c8e051 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -118,7 +118,8 @@ return array( $container->get( 'wcgateway.place-order-button-text' ), $container->get( 'api.endpoint.payment-tokens' ), $container->get( 'vaulting.vault-v3-enabled' ), - $container->get( 'vaulting.wc-payment-tokens' ) + $container->get( 'vaulting.wc-payment-tokens' ), + $container->get( 'wcgateway.url' ) ); }, 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway { @@ -1376,7 +1377,8 @@ return array( $container->get( 'wcgateway.pay-upon-invoice-helper' ), $container->get( 'wcgateway.checkout-helper' ), $container->get( 'onboarding.state' ), - $container->get( 'wcgateway.processor.refunds' ) + $container->get( 'wcgateway.processor.refunds' ), + $container->get( 'wcgateway.url' ) ); }, 'wcgateway.fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId { diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index 4a00b8d5e..3012d5885 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -202,6 +202,13 @@ class PayPalGateway extends \WC_Payment_Gateway { */ private $wc_payment_tokens; + /** + * The module URL + * + * @var string + */ + private $module_url; + /** * PayPalGateway constructor. * @@ -225,6 +232,7 @@ class PayPalGateway extends \WC_Payment_Gateway { * @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint. * @param bool $vault_v3_enabled Whether Vault v3 module is enabled. * @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payment tokens. + * @param string $module_url The module URL */ public function __construct( SettingsRenderer $settings_renderer, @@ -246,7 +254,8 @@ class PayPalGateway extends \WC_Payment_Gateway { string $place_order_button_text, PaymentTokensEndpoint $payment_tokens_endpoint, bool $vault_v3_enabled, - WooCommercePaymentTokens $wc_payment_tokens + WooCommercePaymentTokens $wc_payment_tokens, + string $module_url ) { $this->id = self::ID; $this->settings_renderer = $settings_renderer; @@ -270,6 +279,8 @@ class PayPalGateway extends \WC_Payment_Gateway { $this->payment_tokens_endpoint = $payment_tokens_endpoint; $this->vault_v3_enabled = $vault_v3_enabled; $this->wc_payment_tokens = $wc_payment_tokens; + $this->module_url = $module_url; + $this->icon = apply_filters('woocommerce_paypal_payments_paypal_gateway_icon', esc_url( $this->module_url ) . 'assets/images/paypal.svg'); $default_support = array( 'products', diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index d4ca29121..a1a4e4113 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -103,6 +103,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { */ protected $refund_processor; + /** + * The module URL + * + * @var string + */ + private $module_url; + /** * PayUponInvoiceGateway constructor. * @@ -116,6 +123,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { * @param CheckoutHelper $checkout_helper The checkout helper. * @param State $state The onboarding state. * @param RefundProcessor $refund_processor The refund processor. + * @param string $module_url The module URL */ public function __construct( PayUponInvoiceOrderEndpoint $order_endpoint, @@ -127,7 +135,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { PayUponInvoiceHelper $pui_helper, CheckoutHelper $checkout_helper, State $state, - RefundProcessor $refund_processor + RefundProcessor $refund_processor, + string $module_url ) { $this->id = self::ID; @@ -157,6 +166,9 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $this->transaction_url_provider = $transaction_url_provider; $this->pui_helper = $pui_helper; $this->checkout_helper = $checkout_helper; + $this->module_url = $module_url; + $this->icon = apply_filters('woocommerce_paypal_payments_pay_upon_invoice_gateway_icon', esc_url( $this->module_url ) . 'assets/images/ratepay.svg'); + $this->state = $state; if ( $state->current_state() === State::STATE_ONBOARDED ) { From 82faf9370b5148045ad5d9920ed5e946ac865ae7 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 18 Oct 2024 09:47:42 +0200 Subject: [PATCH 2/5] Add paypal icon to the block checkout --- .../ppcp-blocks/resources/js/checkout-block.js | 17 ++++++++++++++++- modules/ppcp-blocks/src/PayPalPaymentMethod.php | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-blocks/resources/js/checkout-block.js b/modules/ppcp-blocks/resources/js/checkout-block.js index 97590838e..fb012dbde 100644 --- a/modules/ppcp-blocks/resources/js/checkout-block.js +++ b/modules/ppcp-blocks/resources/js/checkout-block.js @@ -768,9 +768,24 @@ if ( block_enabled && config.enabled ) { ); } + const PaypalLabel = ( { components, config } ) => { + const { PaymentMethodIcons } = components; + + return ( + <> + + + + ); + }; + registerPaymentMethod( { name: config.id, - label:
, + label: , content: descriptionElement, edit: descriptionElement, placeOrderButtonLabel: config.placeOrderButtonText, diff --git a/modules/ppcp-blocks/src/PayPalPaymentMethod.php b/modules/ppcp-blocks/src/PayPalPaymentMethod.php index 50340b574..d6a617af0 100644 --- a/modules/ppcp-blocks/src/PayPalPaymentMethod.php +++ b/modules/ppcp-blocks/src/PayPalPaymentMethod.php @@ -248,6 +248,13 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType { return array( 'id' => $this->gateway->id, 'title' => $this->gateway->title, + 'icon' => [ + [ + 'id' => 'paypal', + 'alt' => 'PayPal', + 'src' => $this->gateway->icon + ] + ], 'description' => $this->gateway->description, 'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ?? 'checkout' ), 'fundingSource' => $this->session_handler->funding_source(), From 6f354828476769d87e4bb212d4833b7413c6fd98 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 18 Oct 2024 11:29:07 +0200 Subject: [PATCH 3/5] Update icons, fix errors --- modules/ppcp-blocks/src/PayPalPaymentMethod.php | 12 ++++++------ modules/ppcp-wc-gateway/assets/images/paypal.png | Bin modules/ppcp-wc-gateway/assets/images/paypal.svg | 2 +- .../ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 6 +++--- .../PayUponInvoice/PayUponInvoiceGateway.php | 7 +++---- 5 files changed, 13 insertions(+), 14 deletions(-) mode change 100755 => 100644 modules/ppcp-wc-gateway/assets/images/paypal.png diff --git a/modules/ppcp-blocks/src/PayPalPaymentMethod.php b/modules/ppcp-blocks/src/PayPalPaymentMethod.php index d6a617af0..3cb122cbc 100644 --- a/modules/ppcp-blocks/src/PayPalPaymentMethod.php +++ b/modules/ppcp-blocks/src/PayPalPaymentMethod.php @@ -248,13 +248,13 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType { return array( 'id' => $this->gateway->id, 'title' => $this->gateway->title, - 'icon' => [ - [ - 'id' => 'paypal', + 'icon' => array( + array( + 'id' => 'paypal', 'alt' => 'PayPal', - 'src' => $this->gateway->icon - ] - ], + 'src' => $this->gateway->icon, + ), + ), 'description' => $this->gateway->description, 'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ?? 'checkout' ), 'fundingSource' => $this->session_handler->funding_source(), diff --git a/modules/ppcp-wc-gateway/assets/images/paypal.png b/modules/ppcp-wc-gateway/assets/images/paypal.png old mode 100755 new mode 100644 diff --git a/modules/ppcp-wc-gateway/assets/images/paypal.svg b/modules/ppcp-wc-gateway/assets/images/paypal.svg index 0d82f0b74..9aa54566c 100644 --- a/modules/ppcp-wc-gateway/assets/images/paypal.svg +++ b/modules/ppcp-wc-gateway/assets/images/paypal.svg @@ -1,3 +1,3 @@ - + diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index 3012d5885..aafb50cb2 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -232,7 +232,7 @@ class PayPalGateway extends \WC_Payment_Gateway { * @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint. * @param bool $vault_v3_enabled Whether Vault v3 module is enabled. * @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payment tokens. - * @param string $module_url The module URL + * @param string $module_url The module URL. */ public function __construct( SettingsRenderer $settings_renderer, @@ -279,8 +279,8 @@ class PayPalGateway extends \WC_Payment_Gateway { $this->payment_tokens_endpoint = $payment_tokens_endpoint; $this->vault_v3_enabled = $vault_v3_enabled; $this->wc_payment_tokens = $wc_payment_tokens; - $this->module_url = $module_url; - $this->icon = apply_filters('woocommerce_paypal_payments_paypal_gateway_icon', esc_url( $this->module_url ) . 'assets/images/paypal.svg'); + $this->module_url = $module_url; + $this->icon = apply_filters( 'woocommerce_paypal_payments_paypal_gateway_icon', esc_url( $this->module_url ) . 'assets/images/paypal.svg' ); $default_support = array( 'products', diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index a1a4e4113..69ae3b522 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -123,7 +123,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { * @param CheckoutHelper $checkout_helper The checkout helper. * @param State $state The onboarding state. * @param RefundProcessor $refund_processor The refund processor. - * @param string $module_url The module URL + * @param string $module_url The module URL */ public function __construct( PayUponInvoiceOrderEndpoint $order_endpoint, @@ -166,9 +166,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $this->transaction_url_provider = $transaction_url_provider; $this->pui_helper = $pui_helper; $this->checkout_helper = $checkout_helper; - $this->module_url = $module_url; - $this->icon = apply_filters('woocommerce_paypal_payments_pay_upon_invoice_gateway_icon', esc_url( $this->module_url ) . 'assets/images/ratepay.svg'); - + $this->module_url = $module_url; + $this->icon = apply_filters( 'woocommerce_paypal_payments_pay_upon_invoice_gateway_icon', esc_url( $this->module_url ) . 'assets/images/ratepay.svg' ); $this->state = $state; if ( $state->current_state() === State::STATE_ONBOARDED ) { From 2a9d028308118014547c04190eb185621755f618 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 18 Oct 2024 11:36:33 +0200 Subject: [PATCH 4/5] Fix tests --- .../Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php | 3 ++- tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php index 0161f8c71..82c88449f 100644 --- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php @@ -64,7 +64,8 @@ class PayUponInvoiceGatewayTest extends TestCase $this->pui_helper, $this->checkout_helper, $this->state, - $this->refund_processor + $this->refund_processor, + '' ); } diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php index 041141492..5884572e7 100644 --- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php @@ -123,7 +123,8 @@ class WcGatewayTest extends TestCase 'Pay via PayPal', $this->paymentTokensEndpoint, $this->vaultV3Enabled, - $this->wcPaymentTokens + $this->wcPaymentTokens, + '' ); } From 89a87c2f37d3f144b0f06b9c0a7ed09721526b67 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 18 Oct 2024 11:46:23 +0200 Subject: [PATCH 5/5] Add a dot to the param comment --- .../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index 69ae3b522..dbd6629bd 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -123,7 +123,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { * @param CheckoutHelper $checkout_helper The checkout helper. * @param State $state The onboarding state. * @param RefundProcessor $refund_processor The refund processor. - * @param string $module_url The module URL + * @param string $module_url The module URL. */ public function __construct( PayUponInvoiceOrderEndpoint $order_endpoint,