From 436fd77587ec02cb1d9df472a72c024059d4d101 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 23 Apr 2024 15:00:05 +0200 Subject: [PATCH 01/60] Fix the Apple Pay button in the editor --- .../ppcp-applepay/resources/css/styles.scss | 6 +++ .../js/ApplepayManagerBlockEditor.js | 36 +++++++++++++ .../ppcp-applepay/resources/js/boot-block.js | 15 ++++-- modules/ppcp-applepay/src/ApplepayModule.php | 24 +++++++++ .../src/Assets/ApplePayButton.php | 51 ++++++++++--------- .../src/Assets/BlocksPaymentMethod.php | 8 ++- 6 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 modules/ppcp-applepay/resources/js/ApplepayManagerBlockEditor.js diff --git a/modules/ppcp-applepay/resources/css/styles.scss b/modules/ppcp-applepay/resources/css/styles.scss index 858094433..da8fe0c22 100644 --- a/modules/ppcp-applepay/resources/css/styles.scss +++ b/modules/ppcp-applepay/resources/css/styles.scss @@ -46,4 +46,10 @@ } } } + + .ppcp-button-applepay { + apple-pay-button { + display: block; + } + } } diff --git a/modules/ppcp-applepay/resources/js/ApplepayManagerBlockEditor.js b/modules/ppcp-applepay/resources/js/ApplepayManagerBlockEditor.js new file mode 100644 index 000000000..75ff956b5 --- /dev/null +++ b/modules/ppcp-applepay/resources/js/ApplepayManagerBlockEditor.js @@ -0,0 +1,36 @@ +import ApplepayButton from "./ApplepayButton"; + +class ApplepayManagerBlockEditor { + + constructor(buttonConfig, ppcpConfig) { + this.buttonConfig = buttonConfig; + this.ppcpConfig = ppcpConfig; + this.applePayConfig = null; + } + + init() { + (async () => { + await this.config(); + })(); + } + + async config() { + try { + this.applePayConfig = await paypal.Applepay().config(); + + const button = new ApplepayButton( + this.ppcpConfig.context, + null, + this.buttonConfig, + this.ppcpConfig, + ); + + button.init(this.applePayConfig); + + } catch (error) { + console.error('Failed to initialize Apple Pay:', error); + } + } +} + +export default ApplepayManagerBlockEditor; diff --git a/modules/ppcp-applepay/resources/js/boot-block.js b/modules/ppcp-applepay/resources/js/boot-block.js index b1d29c9c9..d8e92ef24 100644 --- a/modules/ppcp-applepay/resources/js/boot-block.js +++ b/modules/ppcp-applepay/resources/js/boot-block.js @@ -2,9 +2,10 @@ import {useEffect, useState} from '@wordpress/element'; import {registerExpressPaymentMethod} from '@woocommerce/blocks-registry'; import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading' import {cartHasSubscriptionProducts} from '../../../ppcp-blocks/resources/js/Helper/Subscription' -import ApplepayManager from "./ApplepayManager"; import {loadCustomScript} from "@paypal/paypal-js"; import CheckoutHandler from "./Context/CheckoutHandler"; +import ApplepayManager from "./ApplepayManager"; +import ApplepayManagerBlockEditor from "./ApplepayManagerBlockEditor"; const ppcpData = wc.wcSettings.getSetting('ppcp-gateway_data'); const ppcpConfig = ppcpData.scriptData; @@ -16,13 +17,14 @@ if (typeof window.PayPalCommerceGateway === 'undefined') { window.PayPalCommerceGateway = ppcpConfig; } -const ApplePayComponent = () => { +const ApplePayComponent = ( props ) => { const [bootstrapped, setBootstrapped] = useState(false); const [paypalLoaded, setPaypalLoaded] = useState(false); const [applePayLoaded, setApplePayLoaded] = useState(false); const bootstrap = function () { - const manager = new ApplepayManager(buttonConfig, ppcpConfig); + const ManagerClass = props.isEditing ? ApplepayManagerBlockEditor : ApplepayManager; + const manager = new ManagerClass(buttonConfig, ppcpConfig); manager.init(); }; @@ -32,6 +34,8 @@ const ApplePayComponent = () => { setApplePayLoaded(true); }); + ppcpConfig.url_params.components += ',applepay'; + // Load PayPal loadPaypalScript(ppcpConfig, () => { setPaypalLoaded(true); @@ -46,7 +50,10 @@ const ApplePayComponent = () => { }, [paypalLoaded, applePayLoaded]); return ( -
+
+
); } diff --git a/modules/ppcp-applepay/src/ApplepayModule.php b/modules/ppcp-applepay/src/ApplepayModule.php index 86aaff278..b1d0177bc 100644 --- a/modules/ppcp-applepay/src/ApplepayModule.php +++ b/modules/ppcp-applepay/src/ApplepayModule.php @@ -92,6 +92,7 @@ class ApplepayModule implements ModuleInterface { } $module->load_admin_assets( $c, $apple_payment_method ); + $module->load_block_editor_assets( $c, $apple_payment_method ); }, 1 ); @@ -177,6 +178,13 @@ class ApplepayModule implements ModuleInterface { } } ); + add_action( + 'enqueue_block_editor_assets', + function () use ( $c, $button ) { + $button->enqueue_admin_styles(); + } + ); + add_action( 'woocommerce_blocks_payment_method_type_registration', function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void { @@ -207,6 +215,7 @@ class ApplepayModule implements ModuleInterface { * @psalm-suppress UndefinedInterfaceMethod */ $button->enqueue_admin(); + $button->enqueue_admin_styles(); } ); @@ -222,6 +231,21 @@ class ApplepayModule implements ModuleInterface { ); } + public function load_block_editor_assets( ContainerInterface $c, ApplePayButton $button ): void { + // Enqueue backend scripts. + add_action( + 'enqueue_block_editor_assets', + static function () use ( $c, $button ) { + /** + * Should add this to the ButtonInterface. + * + * @psalm-suppress UndefinedInterfaceMethod + */ + $button->enqueue_admin_styles(); + } + ); + } + /** * Renders the Apple Pay buttons in the enabled places. * diff --git a/modules/ppcp-applepay/src/Assets/ApplePayButton.php b/modules/ppcp-applepay/src/Assets/ApplePayButton.php index f8ce67bd6..16d28ad23 100644 --- a/modules/ppcp-applepay/src/Assets/ApplePayButton.php +++ b/modules/ppcp-applepay/src/Assets/ApplePayButton.php @@ -468,9 +468,9 @@ class ApplePayButton implements ButtonInterface { return false; } return wp_verify_nonce( - $nonce, - 'woocommerce-process_checkout' - ) === 1; + $nonce, + 'woocommerce-process_checkout' + ) === 1; } /** @@ -559,11 +559,11 @@ class ApplePayButton implements ButtonInterface { list( $shipping_methods_array, $selected_shipping_method ) = $this->cart_shipping_methods( - $cart, - $customer_address, - $shipping_method, - $shipping_method_id - ); + $cart, + $customer_address, + $shipping_method, + $shipping_method_id + ); } $cart->calculate_shipping(); $cart->calculate_fees(); @@ -717,7 +717,7 @@ class ApplePayButton implements ButtonInterface { */ protected function calculate_totals_cart_page( array $customer_address, - $shipping_method = null + $shipping_method = null ): array { $results = array(); @@ -742,11 +742,11 @@ class ApplePayButton implements ButtonInterface { list( $shipping_methods_array, $selected_shipping_method ) = $this->cart_shipping_methods( - $cart, - $customer_address, - $shipping_method, - $shipping_method_id - ); + $cart, + $customer_address, + $shipping_method, + $shipping_method_id + ); } $cart->calculate_shipping(); $cart->calculate_fees(); @@ -1044,17 +1044,9 @@ class ApplePayButton implements ButtonInterface { } /** - * Enqueues scripts/styles for admin. + * Enqueues scripts for admin. */ public function enqueue_admin(): void { - wp_register_style( - 'wc-ppcp-applepay-admin', - untrailingslashit( $this->module_url ) . '/assets/css/styles.css', - array(), - $this->version - ); - wp_enqueue_style( 'wc-ppcp-applepay-admin' ); - wp_register_script( 'wc-ppcp-applepay-admin', untrailingslashit( $this->module_url ) . '/assets/js/boot-admin.js', @@ -1071,6 +1063,19 @@ class ApplePayButton implements ButtonInterface { ); } + /** + * Enqueues styles for admin. + */ + public function enqueue_admin_styles(): void { + wp_register_style( + 'wc-ppcp-applepay-admin', + untrailingslashit( $this->module_url ) . '/assets/css/styles.css', + array(), + $this->version + ); + wp_enqueue_style( 'wc-ppcp-applepay-admin' ); + } + /** * Returns the script data. * diff --git a/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php b/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php index 432deaa21..2266f4c73 100644 --- a/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php +++ b/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php @@ -103,12 +103,18 @@ class BlocksPaymentMethod extends AbstractPaymentMethodType { public function get_payment_method_data() { $paypal_data = $this->paypal_payment_method->get_payment_method_data(); + if ( is_admin() ) { + $script_data = $this->button->script_data_for_admin(); + } else { + $script_data = $this->button->script_data(); + } + return array( 'id' => $this->name, 'title' => $paypal_data['title'], // TODO : see if we should use another. 'description' => $paypal_data['description'], // TODO : see if we should use another. 'enabled' => $paypal_data['enabled'], // This button is enabled when PayPal buttons are. - 'scriptData' => $this->button->script_data(), + 'scriptData' => $script_data, ); } } From 5aa00d89141cc5dd8f67a8f4f3e356444a52b34f Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 23 Apr 2024 15:18:04 +0200 Subject: [PATCH 02/60] Fix PHPCS and Psalm errors --- .../src/Exception/PayPalApiException.php | 10 +++---- modules/ppcp-applepay/src/ApplepayModule.php | 7 +++++ .../src/Assets/ApplePayButton.php | 28 +++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/modules/ppcp-api-client/src/Exception/PayPalApiException.php b/modules/ppcp-api-client/src/Exception/PayPalApiException.php index 9db633729..11405b22b 100644 --- a/modules/ppcp-api-client/src/Exception/PayPalApiException.php +++ b/modules/ppcp-api-client/src/Exception/PayPalApiException.php @@ -155,11 +155,11 @@ class PayPalApiException extends RuntimeException { return $json->message; } $improved_keys_messages = array( - 'PAYMENT_DENIED' => __( 'PayPal rejected the payment. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ), - 'TRANSACTION_REFUSED' => __( 'The transaction has been refused by the payment processor. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ), - 'DUPLICATE_INVOICE_ID' => __( 'The transaction has been refused because the Invoice ID already exists. Please create a new order or reach out to the store owner.', 'woocommerce-paypal-payments' ), - 'PAYER_CANNOT_PAY' => __( 'There was a problem processing this transaction. Please reach out to the store owner.', 'woocommerce-paypal-payments' ), - 'PAYEE_ACCOUNT_RESTRICTED' => __( 'There was a problem processing this transaction. Please reach out to the store owner.', 'woocommerce-paypal-payments' ), + 'PAYMENT_DENIED' => __( 'PayPal rejected the payment. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ), + 'TRANSACTION_REFUSED' => __( 'The transaction has been refused by the payment processor. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ), + 'DUPLICATE_INVOICE_ID' => __( 'The transaction has been refused because the Invoice ID already exists. Please create a new order or reach out to the store owner.', 'woocommerce-paypal-payments' ), + 'PAYER_CANNOT_PAY' => __( 'There was a problem processing this transaction. Please reach out to the store owner.', 'woocommerce-paypal-payments' ), + 'PAYEE_ACCOUNT_RESTRICTED' => __( 'There was a problem processing this transaction. Please reach out to the store owner.', 'woocommerce-paypal-payments' ), 'AGREEMENT_ALREADY_CANCELLED' => __( 'The requested agreement is already canceled. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ), ); $improved_errors = array_filter( diff --git a/modules/ppcp-applepay/src/ApplepayModule.php b/modules/ppcp-applepay/src/ApplepayModule.php index b1d0177bc..d9d93d6e6 100644 --- a/modules/ppcp-applepay/src/ApplepayModule.php +++ b/modules/ppcp-applepay/src/ApplepayModule.php @@ -231,6 +231,13 @@ class ApplepayModule implements ModuleInterface { ); } + /** + * Enqueues the editor assets. + * + * @param ContainerInterface $c The container. + * @param ApplePayButton $button The button. + * @return void + */ public function load_block_editor_assets( ContainerInterface $c, ApplePayButton $button ): void { // Enqueue backend scripts. add_action( diff --git a/modules/ppcp-applepay/src/Assets/ApplePayButton.php b/modules/ppcp-applepay/src/Assets/ApplePayButton.php index 16d28ad23..517f76cf0 100644 --- a/modules/ppcp-applepay/src/Assets/ApplePayButton.php +++ b/modules/ppcp-applepay/src/Assets/ApplePayButton.php @@ -468,9 +468,9 @@ class ApplePayButton implements ButtonInterface { return false; } return wp_verify_nonce( - $nonce, - 'woocommerce-process_checkout' - ) === 1; + $nonce, + 'woocommerce-process_checkout' + ) === 1; } /** @@ -559,11 +559,11 @@ class ApplePayButton implements ButtonInterface { list( $shipping_methods_array, $selected_shipping_method ) = $this->cart_shipping_methods( - $cart, - $customer_address, - $shipping_method, - $shipping_method_id - ); + $cart, + $customer_address, + $shipping_method, + $shipping_method_id + ); } $cart->calculate_shipping(); $cart->calculate_fees(); @@ -717,7 +717,7 @@ class ApplePayButton implements ButtonInterface { */ protected function calculate_totals_cart_page( array $customer_address, - $shipping_method = null + $shipping_method = null ): array { $results = array(); @@ -742,11 +742,11 @@ class ApplePayButton implements ButtonInterface { list( $shipping_methods_array, $selected_shipping_method ) = $this->cart_shipping_methods( - $cart, - $customer_address, - $shipping_method, - $shipping_method_id - ); + $cart, + $customer_address, + $shipping_method, + $shipping_method_id + ); } $cart->calculate_shipping(); $cart->calculate_fees(); From aa3a58af5f6e7a7481b82e14d7f401fe94605d0b Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:04:53 +0400 Subject: [PATCH 03/60] Refactor the `transaction_id` to be`capture_id` --- .../src/Shipment/Shipment.php | 16 ++++++++-------- .../src/Shipment/ShipmentFactory.php | 4 ++-- .../src/Shipment/ShipmentFactoryInterface.php | 4 ++-- .../src/Shipment/ShipmentInterface.php | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Shipment/Shipment.php b/modules/ppcp-order-tracking/src/Shipment/Shipment.php index 9661d574c..26e4e6f1c 100644 --- a/modules/ppcp-order-tracking/src/Shipment/Shipment.php +++ b/modules/ppcp-order-tracking/src/Shipment/Shipment.php @@ -32,11 +32,11 @@ class Shipment implements ShipmentInterface { private $wc_order_id; /** - * The transaction ID. + * The capture ID. * * @var string */ - protected $transaction_id; + protected $capture_id; /** * The tracking number. @@ -76,7 +76,7 @@ class Shipment implements ShipmentInterface { * Shipment constructor. * * @param int $wc_order_id The WC order ID. - * @param string $transaction_id The transaction ID. + * @param string $capture_id The capture ID. * @param string $tracking_number The tracking number. * @param string $status The shipment status. * @param string $carrier The shipment carrier. @@ -85,7 +85,7 @@ class Shipment implements ShipmentInterface { */ public function __construct( int $wc_order_id, - string $transaction_id, + string $capture_id, string $tracking_number, string $status, string $carrier, @@ -97,15 +97,15 @@ class Shipment implements ShipmentInterface { $this->carrier = $carrier; $this->carrier_name_other = $carrier_name_other; $this->line_items = $line_items; - $this->transaction_id = $transaction_id; + $this->capture_id = $capture_id; $this->wc_order_id = $wc_order_id; } /** * {@inheritDoc} */ - public function transaction_id(): string { - return $this->transaction_id; + public function capture_id(): string { + return $this->capture_id; } /** @@ -228,7 +228,7 @@ class Shipment implements ShipmentInterface { */ public function to_array(): array { $shipment = array( - 'transaction_id' => $this->transaction_id(), + 'capture_id' => $this->capture_id(), 'tracking_number' => $this->tracking_number(), 'status' => $this->status(), 'carrier' => $this->carrier(), diff --git a/modules/ppcp-order-tracking/src/Shipment/ShipmentFactory.php b/modules/ppcp-order-tracking/src/Shipment/ShipmentFactory.php index cddae0b2b..b77e71759 100644 --- a/modules/ppcp-order-tracking/src/Shipment/ShipmentFactory.php +++ b/modules/ppcp-order-tracking/src/Shipment/ShipmentFactory.php @@ -19,13 +19,13 @@ class ShipmentFactory implements ShipmentFactoryInterface { */ public function create_shipment( int $wc_order_id, - string $transaction_id, + string $capture_id, string $tracking_number, string $status, string $carrier, string $carrier_name_other, array $line_items ): ShipmentInterface { - return new Shipment( $wc_order_id, $transaction_id, $tracking_number, $status, $carrier, $carrier_name_other, $line_items ); + return new Shipment( $wc_order_id, $capture_id, $tracking_number, $status, $carrier, $carrier_name_other, $line_items ); } } diff --git a/modules/ppcp-order-tracking/src/Shipment/ShipmentFactoryInterface.php b/modules/ppcp-order-tracking/src/Shipment/ShipmentFactoryInterface.php index c1c471e48..25f8627a3 100644 --- a/modules/ppcp-order-tracking/src/Shipment/ShipmentFactoryInterface.php +++ b/modules/ppcp-order-tracking/src/Shipment/ShipmentFactoryInterface.php @@ -20,7 +20,7 @@ interface ShipmentFactoryInterface { * Returns the new shipment instance. * * @param int $wc_order_id The WC order ID. - * @param string $transaction_id The transaction ID. + * @param string $capture_id The capture ID. * @param string $tracking_number The tracking number. * @param string $status The shipment status. * @param string $carrier The shipment carrier. @@ -32,7 +32,7 @@ interface ShipmentFactoryInterface { */ public function create_shipment( int $wc_order_id, - string $transaction_id, + string $capture_id, string $tracking_number, string $status, string $carrier, diff --git a/modules/ppcp-order-tracking/src/Shipment/ShipmentInterface.php b/modules/ppcp-order-tracking/src/Shipment/ShipmentInterface.php index 29d7eecff..80657868b 100644 --- a/modules/ppcp-order-tracking/src/Shipment/ShipmentInterface.php +++ b/modules/ppcp-order-tracking/src/Shipment/ShipmentInterface.php @@ -24,7 +24,7 @@ namespace WooCommerce\PayPalCommerce\OrderTracking\Shipment; * tax_rate?: string * } * @psalm-type shipmentMap = array{ - * transaction_id: string, + * capture_id: string, * tracking_number: string, * status: string, * carrier: string, @@ -35,11 +35,11 @@ namespace WooCommerce\PayPalCommerce\OrderTracking\Shipment; interface ShipmentInterface { /** - * The transaction ID. + * The capture ID. * * @return string */ - public function transaction_id(): string; + public function capture_id(): string; /** * The tracking number. From 2cae4a723ad0e2897c066a56a436f9af81a9f23a Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:05:23 +0400 Subject: [PATCH 04/60] Use `capture_id` instead of the `transaction_id` --- .../src/Endpoint/OrderTrackingEndpoint.php | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php index ae2ca54f0..4b9d69efb 100644 --- a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php +++ b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php @@ -23,13 +23,14 @@ use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentInterface; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * The OrderTrackingEndpoint. * * @psalm-type SupportedStatuses = 'SHIPPED'|'ON_HOLD'|'DELIVERED'|'CANCELLED' * @psalm-type TrackingInfo = array{ - * transaction_id: string, + * capture_id: string, * status: SupportedStatuses, * tracking_number: string, * carrier: string, @@ -188,6 +189,7 @@ class OrderTrackingEndpoint { do_action( 'woocommerce_paypal_payments_before_tracking_is_added', $order_id, $shipment_request_data ); $response = $this->request( $url, $args ); + write_log($response); if ( is_wp_error( $response ) ) { $args = array( @@ -222,7 +224,7 @@ class OrderTrackingEndpoint { */ public function update_tracking_information( ShipmentInterface $shipment, int $order_id ) : void { $host = trailingslashit( $this->host ); - $tracker_id = $this->find_tracker_id( $shipment->transaction_id(), $shipment->tracking_number() ); + $tracker_id = $this->find_tracker_id( $shipment->capture_id(), $shipment->tracking_number() ); $url = "{$host}v1/shipping/trackers/{$tracker_id}"; $shipment_data = $shipment->to_array(); @@ -272,9 +274,11 @@ class OrderTrackingEndpoint { return null; } - $host = trailingslashit( $this->host ); - $tracker_id = $this->find_tracker_id( $wc_order->get_transaction_id(), $tracking_number ); - $url = "{$host}v1/shipping/trackers/{$tracker_id}"; + $host = trailingslashit( $this->host ); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); + $tracker_id = $this->find_tracker_id( $capture_id, $tracking_number ); + $url = "{$host}v1/shipping/trackers/{$tracker_id}"; $args = array( 'method' => 'GET', @@ -319,9 +323,10 @@ class OrderTrackingEndpoint { return array(); } - $host = trailingslashit( $this->host ); - $transaction_id = $wc_order->get_transaction_id(); - $url = "{$host}v1/shipping/trackers?transaction_id={$transaction_id}"; + $host = trailingslashit( $this->host ); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); + $url = "{$host}v1/shipping/trackers?transaction_id={$capture_id}"; $args = array( 'method' => 'GET', @@ -382,7 +387,7 @@ class OrderTrackingEndpoint { $carrier = $data['carrier'] ?? ''; $tracking_info = array( - 'transaction_id' => $data['transaction_id'] ?? '', + 'capture_id' => $data['capture_id'] ?? '', 'status' => $data['status'] ?? '', 'tracking_number' => $data['tracking_number'] ?? '', 'carrier' => $carrier, @@ -395,7 +400,7 @@ class OrderTrackingEndpoint { return $this->shipment_factory->create_shipment( $wc_order_id, - $tracking_info['transaction_id'], + $tracking_info['capture_id'], $tracking_info['tracking_number'], $tracking_info['status'], $tracking_info['carrier'], @@ -418,7 +423,7 @@ class OrderTrackingEndpoint { $carrier = $request_values['carrier'] ?? ''; $data_to_check = array( - 'transaction_id' => $request_values['transaction_id'] ?? '', + 'capture_id' => $request_values['capture_id'] ?? '', 'status' => $request_values['status'] ?? '', 'tracking_number' => $request_values['tracking_number'] ?? '', 'carrier' => $carrier, @@ -458,14 +463,14 @@ class OrderTrackingEndpoint { } /** - * Finds the tracker ID from given transaction ID and tracking number. + * Finds the tracker ID from given capture ID and tracking number. * - * @param string $transaction_id The transaction ID. + * @param string $capture_id The capture ID. * @param string $tracking_number The tracking number. * @return string The tracker ID. */ - protected function find_tracker_id( string $transaction_id, string $tracking_number ): string { - return ! empty( $tracking_number ) ? "{$transaction_id}-{$tracking_number}" : "{$transaction_id}-NOTRACKER"; + protected function find_tracker_id( string $capture_id, string $tracking_number ): string { + return ! empty( $tracking_number ) ? "{$capture_id}-{$tracking_number}" : "{$capture_id}-NOTRACKER"; } /** @@ -503,21 +508,18 @@ class OrderTrackingEndpoint { $host = trailingslashit( $this->host ); $shipment_data = $shipment->to_array(); - $old_api_data = $shipment_data; - unset( $old_api_data['items'] ); - $request_shipment_data = array( 'trackers' => array( $old_api_data ) ); - - if ( $this->should_use_new_api ) { - unset( $shipment_data['transaction_id'] ); - $shipment_data['capture_id'] = $shipment->transaction_id(); - $request_shipment_data = $shipment_data; + if ( ! $this->should_use_new_api ) { + unset( $shipment_data['capture_id'] ); + unset( $shipment_data['items'] ); + $shipment_data['transaction_id'] = $shipment->capture_id(); + $shipment_data = array( 'trackers' => array( $shipment_data ) ); } $url = $this->should_use_new_api ? "{$host}v2/checkout/orders/{$paypal_order_id}/track" : "{$host}v1/shipping/trackers"; $args = array( 'method' => 'POST', 'headers' => $this->request_headers(), - 'body' => wp_json_encode( (array) apply_filters( 'woocommerce_paypal_payments_tracking_data_before_sending', $request_shipment_data, $wc_order->get_id() ) ), + 'body' => wp_json_encode( (array) apply_filters( 'woocommerce_paypal_payments_tracking_data_before_sending', $shipment_data, $wc_order->get_id() ) ), ); return array( From 3fa1cb4da3f11c09464de9140f38cd3df2377f8c Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:05:37 +0400 Subject: [PATCH 05/60] Use `capture_id` instead of the `transaction_id` in metabox --- .../src/MetaBoxRenderer.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php index 916b9fbda..faf6b7464 100644 --- a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php +++ b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php @@ -9,11 +9,15 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\OrderTracking; +use Exception; use WC_Order; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; use WP_Post; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; + /** * Class MetaBoxRenderer * @@ -25,6 +29,8 @@ use WP_Post; */ class MetaBoxRenderer { + use TransactionIdHandlingTrait; + /** * Allowed shipping statuses. * @@ -87,7 +93,13 @@ class MetaBoxRenderer { return; } - $transaction_id = $wc_order->get_transaction_id() ?: ''; + try { + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); + } catch ( Exception $exception ) { + return; + } + $order_items = $wc_order->get_items(); $order_item_count = ! empty( $order_items ) ? count( $order_items ) : 0; @@ -102,8 +114,8 @@ class MetaBoxRenderer {

- - + +

1 && $this->should_use_new_api ) : ?>

From 068142ac2faaaf4315d2265a8203df29416a0e17 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:05:57 +0400 Subject: [PATCH 06/60] Use `capture_id` instead of the `transaction_id` for integrations --- .../GermanizedShipmentIntegration.php | 11 ++++++--- .../Integration/ShipStationIntegration.php | 11 ++++++--- .../ShipmentTrackingIntegration.php | 24 ++++++++++++------- .../Integration/WcShippingTaxIntegration.php | 17 +++++++------ .../Integration/YithShipmentIntegration.php | 11 ++++++--- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php b/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php index 7e44fd765..87ca37f85 100644 --- a/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php @@ -17,12 +17,16 @@ use Vendidero\Germanized\Shipments\Shipment; use Vendidero\Germanized\Shipments\ShipmentItem; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * Class GermanizedShipmentIntegration. */ class GermanizedShipmentIntegration implements Integration { + use TransactionIdHandlingTrait; + /** * The shipment factory. * @@ -79,8 +83,9 @@ class GermanizedShipmentIntegration implements Integration { return; } + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $wc_order_id = $wc_order->get_id(); - $transaction_id = $wc_order->get_transaction_id(); $tracking_number = $shipment->get_tracking_id(); $carrier = $shipment->get_shipping_provider(); @@ -91,14 +96,14 @@ class GermanizedShipmentIntegration implements Integration { $shipment->get_items() ); - if ( ! $tracking_number || ! $carrier || ! $transaction_id ) { + if ( ! $tracking_number || ! $carrier || ! $capture_id ) { return; } try { $ppcp_shipment = $this->shipment_factory->create_shipment( $wc_order_id, - $transaction_id, + $capture_id, $tracking_number, 'SHIPPED', 'OTHER', diff --git a/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php b/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php index 08a476e4b..cc1bf6bc6 100644 --- a/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php @@ -15,12 +15,16 @@ use WC_Order; use WooCommerce\PayPalCommerce\Compat\Integration; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * Class ShipStationIntegration. */ class ShipStationIntegration implements Integration { + use TransactionIdHandlingTrait; + /** * The shipment factory. * @@ -80,19 +84,20 @@ class ShipStationIntegration implements Integration { return; } + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $order_id = $wc_order->get_id(); - $transaction_id = $wc_order->get_transaction_id(); $tracking_number = $data['tracking_number'] ?? ''; $carrier = $data['carrier'] ?? ''; - if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $transaction_id ) { + if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $capture_id ) { return; } try { $ppcp_shipment = $this->shipment_factory->create_shipment( $order_id, - $transaction_id, + $capture_id, $tracking_number, 'SHIPPED', 'OTHER', diff --git a/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php b/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php index 6c506a5e8..c14af454d 100644 --- a/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php @@ -15,14 +15,18 @@ use WC_Order; use WooCommerce\PayPalCommerce\Compat\Integration; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; use WP_REST_Request; use WP_REST_Response; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * Class ShipmentTrackingIntegration. */ class ShipmentTrackingIntegration implements Integration { + use TransactionIdHandlingTrait; + /** * The shipment factory. * @@ -81,17 +85,18 @@ class ShipmentTrackingIntegration implements Integration { return; } - $transaction_id = $wc_order->get_transaction_id(); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $tracking_number = wc_clean( wp_unslash( $_POST['tracking_number'] ?? '' ) ); $carrier = wc_clean( wp_unslash( $_POST['tracking_provider'] ?? '' ) ); $carrier_other = wc_clean( wp_unslash( $_POST['custom_tracking_provider'] ?? '' ) ); $carrier = $carrier ?: $carrier_other ?: ''; - if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $transaction_id ) { + if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $capture_id ) { return; } - $this->sync_tracking( $order_id, $transaction_id, $tracking_number, $carrier ); + $this->sync_tracking( $order_id, $capture_id, $tracking_number, $carrier ); } ); @@ -116,17 +121,18 @@ class ShipmentTrackingIntegration implements Integration { return $response; } - $transaction_id = $wc_order->get_transaction_id(); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $tracking_number = $tracking_item['tracking_number'] ?? ''; $carrier = $tracking_item['tracking_provider'] ?? ''; $carrier_other = $tracking_item['custom_tracking_provider'] ?? ''; $carrier = $carrier ?: $carrier_other ?: ''; - if ( ! $tracking_number || ! $carrier || ! $transaction_id ) { + if ( ! $tracking_number || ! $carrier || ! $capture_id ) { return $response; } - $this->sync_tracking( $order_id, $transaction_id, $tracking_number, $carrier ); + $this->sync_tracking( $order_id, $capture_id, $tracking_number, $carrier ); return $response; }, @@ -139,21 +145,21 @@ class ShipmentTrackingIntegration implements Integration { * Syncs (add | update) the PayPal tracking with given info. * * @param int $wc_order_id The WC order ID. - * @param string $transaction_id The transaction ID. + * @param string $capture_id The capture ID. * @param string $tracking_number The tracking number. * @param string $carrier The shipment carrier. * @return void */ protected function sync_tracking( int $wc_order_id, - string $transaction_id, + string $capture_id, string $tracking_number, string $carrier ) { try { $ppcp_shipment = $this->shipment_factory->create_shipment( $wc_order_id, - $transaction_id, + $capture_id, $tracking_number, 'SHIPPED', 'OTHER', diff --git a/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php b/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php index a808c6ade..61ec2bbec 100644 --- a/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php @@ -16,16 +16,18 @@ use WooCommerce\PayPalCommerce\Compat\Integration; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; use WooCommerce\PayPalCommerce\OrderTracking\TrackingAvailabilityTrait; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; use WP_HTTP_Response; use WP_REST_Request; use WP_REST_Server; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * Class WcShippingTaxIntegration. */ class WcShippingTaxIntegration implements Integration { - use TrackingAvailabilityTrait; + use TrackingAvailabilityTrait, TransactionIdHandlingTrait; /** * The shipment factory. @@ -99,15 +101,16 @@ class WcShippingTaxIntegration implements Integration { continue; } - $transaction_id = $wc_order->get_transaction_id(); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $carrier = $label['carrier_id'] ?? $label['service_name'] ?? ''; $items = array_map( 'intval', $label['product_ids'] ?? array() ); - if ( ! $carrier || ! $transaction_id ) { + if ( ! $carrier || ! $capture_id ) { continue; } - $this->sync_tracking( $order_id, $transaction_id, $tracking_number, $carrier, $items ); + $this->sync_tracking( $order_id, $capture_id, $tracking_number, $carrier, $items ); } return $response; @@ -122,7 +125,7 @@ class WcShippingTaxIntegration implements Integration { * Syncs (add | update) the PayPal tracking with given info. * * @param int $wc_order_id The WC order ID. - * @param string $transaction_id The transaction ID. + * @param string $capture_id The capture ID. * @param string $tracking_number The tracking number. * @param string $carrier The shipment carrier. * @param int[] $items The list of line items IDs. @@ -130,7 +133,7 @@ class WcShippingTaxIntegration implements Integration { */ protected function sync_tracking( int $wc_order_id, - string $transaction_id, + string $capture_id, string $tracking_number, string $carrier, array $items @@ -138,7 +141,7 @@ class WcShippingTaxIntegration implements Integration { try { $ppcp_shipment = $this->shipment_factory->create_shipment( $wc_order_id, - $transaction_id, + $capture_id, $tracking_number, 'SHIPPED', 'OTHER', diff --git a/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php b/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php index 57a36babf..5255311f2 100644 --- a/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php @@ -15,12 +15,16 @@ use WC_Order; use WooCommerce\PayPalCommerce\Compat\Integration; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; +use function WooCommerce\PayPalCommerce\Api\ppcp_get_paypal_order; /** * Class YithShipmentIntegration. */ class YithShipmentIntegration implements Integration { + use TransactionIdHandlingTrait; + /** * The shipment factory. * @@ -76,20 +80,21 @@ class YithShipmentIntegration implements Integration { return; } - $transaction_id = $wc_order->get_transaction_id(); + $paypal_order = ppcp_get_paypal_order($wc_order); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $tracking_number = wc_clean( wp_unslash( $_POST['ywot_tracking_code'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $carrier = wc_clean( wp_unslash( $_POST['ywot_carrier_name'] ?? '' ) ); - if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $transaction_id ) { + if ( ! $tracking_number || ! is_string( $tracking_number ) || ! $carrier || ! is_string( $carrier ) || ! $capture_id ) { return; } try { $ppcp_shipment = $this->shipment_factory->create_shipment( $order_id, - $transaction_id, + $capture_id, $tracking_number, 'SHIPPED', 'OTHER', From a97358679cb3bffad850f7bad6ccc1b5b01ed605 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:06:06 +0400 Subject: [PATCH 07/60] Use `capture_id` instead of the `transaction_id` in JS --- .../ppcp-order-tracking/resources/js/order-edit-page.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-order-tracking/resources/js/order-edit-page.js b/modules/ppcp-order-tracking/resources/js/order-edit-page.js index baa6c16b3..bf1056102 100644 --- a/modules/ppcp-order-tracking/resources/js/order-edit-page.js +++ b/modules/ppcp-order-tracking/resources/js/order-edit-page.js @@ -9,7 +9,7 @@ document.addEventListener( const includeAllItemsCheckbox = document.getElementById('include-all-items'); const shipmentsWrapper = '#ppcp_order-tracking .ppcp-tracking-column.shipments'; - const transactionId = document.querySelector('.ppcp-tracking-transaction_id'); + const captureId = document.querySelector('.ppcp-tracking-capture_id'); const orderId = document.querySelector('.ppcp-tracking-order_id'); const carrier = document.querySelector('.ppcp-tracking-carrier'); const carrierNameOther = document.querySelector('.ppcp-tracking-carrier_name_other'); @@ -86,7 +86,7 @@ document.addEventListener( credentials: 'same-origin', body: JSON.stringify({ nonce: config.ajax.tracking_info.nonce, - transaction_id: transactionId ? transactionId.value : null, + capture_id: captureId ? captureId.value : null, tracking_number: trackingNumber ? trackingNumber.value : null, status: status ? status.value : null, carrier: carrier ? carrier.value : null, @@ -113,6 +113,7 @@ document.addEventListener( if (noShipemntsContainer) { noShipemntsContainer.parentNode.removeChild(noShipemntsContainer); } + trackingNumber.value = '' }); }) } @@ -135,7 +136,7 @@ document.addEventListener( credentials: 'same-origin', body: JSON.stringify({ nonce: config.ajax.tracking_info.nonce, - transaction_id: transactionId ? transactionId.value : null, + capture_id: captureId ? captureId.value : null, tracking_number: shipmentTrackingNumber ? shipmentTrackingNumber.value : null, status: shipmentStatus ? shipmentStatus.value : null, carrier: shipmentCarrier ? shipmentCarrier.value : null, From c61d95a182d1427555e565441673acf9369f92b0 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:15:22 +0400 Subject: [PATCH 08/60] Fix coding styles --- .../src/Endpoint/OrderTrackingEndpoint.php | 11 +++++------ .../src/Integration/GermanizedShipmentIntegration.php | 2 +- .../src/Integration/ShipStationIntegration.php | 2 +- .../src/Integration/ShipmentTrackingIntegration.php | 4 ++-- .../src/Integration/WcShippingTaxIntegration.php | 8 ++++---- .../src/Integration/YithShipmentIntegration.php | 2 +- modules/ppcp-order-tracking/src/MetaBoxRenderer.php | 2 +- modules/ppcp-order-tracking/src/Shipment/Shipment.php | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php index 4b9d69efb..5b3f96788 100644 --- a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php +++ b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php @@ -189,7 +189,6 @@ class OrderTrackingEndpoint { do_action( 'woocommerce_paypal_payments_before_tracking_is_added', $order_id, $shipment_request_data ); $response = $this->request( $url, $args ); - write_log($response); if ( is_wp_error( $response ) ) { $args = array( @@ -275,7 +274,7 @@ class OrderTrackingEndpoint { } $host = trailingslashit( $this->host ); - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $tracker_id = $this->find_tracker_id( $capture_id, $tracking_number ); $url = "{$host}v1/shipping/trackers/{$tracker_id}"; @@ -324,7 +323,7 @@ class OrderTrackingEndpoint { } $host = trailingslashit( $this->host ); - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $url = "{$host}v1/shipping/trackers?transaction_id={$capture_id}"; @@ -387,7 +386,7 @@ class OrderTrackingEndpoint { $carrier = $data['carrier'] ?? ''; $tracking_info = array( - 'capture_id' => $data['capture_id'] ?? '', + 'capture_id' => $data['capture_id'] ?? '', 'status' => $data['status'] ?? '', 'tracking_number' => $data['tracking_number'] ?? '', 'carrier' => $carrier, @@ -423,7 +422,7 @@ class OrderTrackingEndpoint { $carrier = $request_values['carrier'] ?? ''; $data_to_check = array( - 'capture_id' => $request_values['capture_id'] ?? '', + 'capture_id' => $request_values['capture_id'] ?? '', 'status' => $request_values['status'] ?? '', 'tracking_number' => $request_values['tracking_number'] ?? '', 'carrier' => $carrier, @@ -512,7 +511,7 @@ class OrderTrackingEndpoint { unset( $shipment_data['capture_id'] ); unset( $shipment_data['items'] ); $shipment_data['transaction_id'] = $shipment->capture_id(); - $shipment_data = array( 'trackers' => array( $shipment_data ) ); + $shipment_data = array( 'trackers' => array( $shipment_data ) ); } $url = $this->should_use_new_api ? "{$host}v2/checkout/orders/{$paypal_order_id}/track" : "{$host}v1/shipping/trackers"; diff --git a/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php b/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php index 87ca37f85..3dfe5bf73 100644 --- a/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/GermanizedShipmentIntegration.php @@ -83,7 +83,7 @@ class GermanizedShipmentIntegration implements Integration { return; } - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $wc_order_id = $wc_order->get_id(); $tracking_number = $shipment->get_tracking_id(); diff --git a/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php b/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php index cc1bf6bc6..dbb95aabc 100644 --- a/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/ShipStationIntegration.php @@ -84,7 +84,7 @@ class ShipStationIntegration implements Integration { return; } - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $order_id = $wc_order->get_id(); $tracking_number = $data['tracking_number'] ?? ''; diff --git a/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php b/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php index c14af454d..9417da693 100644 --- a/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/ShipmentTrackingIntegration.php @@ -85,7 +85,7 @@ class ShipmentTrackingIntegration implements Integration { return; } - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $tracking_number = wc_clean( wp_unslash( $_POST['tracking_number'] ?? '' ) ); $carrier = wc_clean( wp_unslash( $_POST['tracking_provider'] ?? '' ) ); @@ -121,7 +121,7 @@ class ShipmentTrackingIntegration implements Integration { return $response; } - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); $tracking_number = $tracking_item['tracking_number'] ?? ''; $carrier = $tracking_item['tracking_provider'] ?? ''; diff --git a/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php b/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php index 61ec2bbec..87cca24de 100644 --- a/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/WcShippingTaxIntegration.php @@ -101,10 +101,10 @@ class WcShippingTaxIntegration implements Integration { continue; } - $paypal_order = ppcp_get_paypal_order($wc_order); - $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); - $carrier = $label['carrier_id'] ?? $label['service_name'] ?? ''; - $items = array_map( 'intval', $label['product_ids'] ?? array() ); + $paypal_order = ppcp_get_paypal_order( $wc_order ); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); + $carrier = $label['carrier_id'] ?? $label['service_name'] ?? ''; + $items = array_map( 'intval', $label['product_ids'] ?? array() ); if ( ! $carrier || ! $capture_id ) { continue; diff --git a/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php b/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php index 5255311f2..9b2be196c 100644 --- a/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php +++ b/modules/ppcp-order-tracking/src/Integration/YithShipmentIntegration.php @@ -80,7 +80,7 @@ class YithShipmentIntegration implements Integration { return; } - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $tracking_number = wc_clean( wp_unslash( $_POST['ywot_tracking_code'] ?? '' ) ); diff --git a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php index faf6b7464..2502d8b5c 100644 --- a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php +++ b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php @@ -94,7 +94,7 @@ class MetaBoxRenderer { } try { - $paypal_order = ppcp_get_paypal_order($wc_order); + $paypal_order = ppcp_get_paypal_order( $wc_order ); $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); } catch ( Exception $exception ) { return; diff --git a/modules/ppcp-order-tracking/src/Shipment/Shipment.php b/modules/ppcp-order-tracking/src/Shipment/Shipment.php index 26e4e6f1c..c59a77387 100644 --- a/modules/ppcp-order-tracking/src/Shipment/Shipment.php +++ b/modules/ppcp-order-tracking/src/Shipment/Shipment.php @@ -97,7 +97,7 @@ class Shipment implements ShipmentInterface { $this->carrier = $carrier; $this->carrier_name_other = $carrier_name_other; $this->line_items = $line_items; - $this->capture_id = $capture_id; + $this->capture_id = $capture_id; $this->wc_order_id = $wc_order_id; } @@ -228,7 +228,7 @@ class Shipment implements ShipmentInterface { */ public function to_array(): array { $shipment = array( - 'capture_id' => $this->capture_id(), + 'capture_id' => $this->capture_id(), 'tracking_number' => $this->tracking_number(), 'status' => $this->status(), 'carrier' => $this->carrier(), From 9c029858b4bba193574524f9f0af09f67bf3a114 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 25 Apr 2024 20:21:13 +0400 Subject: [PATCH 09/60] Fix psalm errors --- .../src/Endpoint/OrderTrackingEndpoint.php | 2 +- modules/ppcp-order-tracking/src/MetaBoxRenderer.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php index 5b3f96788..9e454a4fe 100644 --- a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php +++ b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php @@ -275,7 +275,7 @@ class OrderTrackingEndpoint { $host = trailingslashit( $this->host ); $paypal_order = ppcp_get_paypal_order( $wc_order ); - $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ) ?? ''; $tracker_id = $this->find_tracker_id( $capture_id, $tracking_number ); $url = "{$host}v1/shipping/trackers/{$tracker_id}"; diff --git a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php index 2502d8b5c..c7a043d7c 100644 --- a/modules/ppcp-order-tracking/src/MetaBoxRenderer.php +++ b/modules/ppcp-order-tracking/src/MetaBoxRenderer.php @@ -93,10 +93,10 @@ class MetaBoxRenderer { return; } - try { - $paypal_order = ppcp_get_paypal_order( $wc_order ); - $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ); - } catch ( Exception $exception ) { + $paypal_order = ppcp_get_paypal_order( $wc_order ); + $capture_id = $this->get_paypal_order_transaction_id( $paypal_order ) ?? ''; + + if ( ! $capture_id ) { return; } From a03add90971d1bf9faf679636758975f44f24e45 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 29 Apr 2024 19:41:21 +0400 Subject: [PATCH 10/60] Set the 'Woo_PPCP' as a default value for `data-partner-attribution-id` --- modules/ppcp-button/src/Assets/SmartButton.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 37134804d..a4d1a63c8 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1506,7 +1506,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages private function bn_code_for_context( string $context ): string { $codes = $this->bn_codes(); - return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : ''; + return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP'; } /** From c05817d41e10abef711bd77e44b8c6729e4a35c7 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 30 Apr 2024 18:27:30 +0400 Subject: [PATCH 11/60] Allow PUI Gateway for refund processor --- modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php b/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php index ed653a5bc..91e73866c 100644 --- a/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/RefundProcessor.php @@ -16,7 +16,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount; use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization; -use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus; use WooCommerce\PayPalCommerce\ApiClient\Entity\Money; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments; @@ -25,6 +24,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; +use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway; use WooCommerce\PayPalCommerce\WcGateway\Helper\RefundFeesUpdater; /** @@ -109,7 +109,7 @@ class RefundProcessor { */ public function process( WC_Order $wc_order, float $amount = null, string $reason = '' ) : bool { try { - if ( ! in_array( $wc_order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID ), true ) ) { + if ( ! in_array( $wc_order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID, PayUponInvoiceGateway::ID ), true ) ) { return true; } From c64b94baddc45abd99767ef6af459451a61aa31e Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 30 Apr 2024 23:46:05 +0200 Subject: [PATCH 12/60] Fix the 'Trying to access array offset on value of type null' warning on the Block Cart and Checkout when PayLater messaging is active --- .../src/PayLaterWCBlocksRenderer.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php index e1a01393d..6709b9a5b 100644 --- a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php +++ b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php @@ -119,13 +119,7 @@ class PayLaterWCBlocksRenderer { $processor->set_attribute( 'data-pp-placement', esc_attr( $this->placement ) ); } - $updated_html = $processor->get_updated_html(); - - return sprintf( - '

%2$s
', - wp_kses_data( get_block_wrapper_attributes() ), - $updated_html - ); + return $processor->get_updated_html(); } } } From 27835fc51aaed3a2b1094f6150bfa4934a63c3ae Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 11:53:20 +0200 Subject: [PATCH 13/60] Use billing select element to format country and state in shipping view --- modules/ppcp-axo/resources/js/Views/ShippingView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-axo/resources/js/Views/ShippingView.js b/modules/ppcp-axo/resources/js/Views/ShippingView.js index 4f0a18f8d..a64b56a09 100644 --- a/modules/ppcp-axo/resources/js/Views/ShippingView.js +++ b/modules/ppcp-axo/resources/js/Views/ShippingView.js @@ -46,8 +46,8 @@ class ShippingView {
${data.value('street1')}
${data.value('street2')}
${data.value('postCode')} ${data.value('city')}
-
${valueOfSelect('#shipping_state', data.value('stateCode'))}
-
${valueOfSelect('#shipping_country', data.value('countryCode'))}
+
${valueOfSelect('#billing_state', data.value('stateCode'))}
+
${valueOfSelect('#billing_country', data.value('countryCode'))}
${data.value('phone')}
`; From 561599412830df3c9790f840dcc0fa30fe147104 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 14:54:59 +0200 Subject: [PATCH 14/60] Apply styles from settings --- modules/ppcp-axo/extensions.php | 36 ++++++++++++++------- modules/ppcp-axo/resources/js/AxoManager.js | 17 +++++++++- modules/ppcp-axo/src/Assets/AxoManager.php | 25 ++++++++++++-- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index e730166a7..7bcc07d86 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -94,6 +94,7 @@ return array( ->action_visible( 'axo_style_root_bg_color' ) ->action_visible( 'axo_style_root_error_color' ) ->action_visible( 'axo_style_root_font_family' ) + ->action_visible( 'axo_style_root_text_color_base' ) ->action_visible( 'axo_style_root_font_size_base' ) ->action_visible( 'axo_style_root_padding' ) ->action_visible( 'axo_style_root_primary_color' ) @@ -201,7 +202,7 @@ return array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#ffffff', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -212,7 +213,7 @@ return array( 'title' => __( 'Error Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#d9360b', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -223,7 +224,18 @@ return array( 'title' => __( 'Font Family', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => 'PayPal Open', + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_text_color_base' => array( + 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -234,7 +246,7 @@ return array( 'title' => __( 'Font Size Base', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '16px', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -245,7 +257,7 @@ return array( 'title' => __( 'Padding', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '4px', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -256,7 +268,7 @@ return array( 'title' => __( 'Primary Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#0057ff', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -279,7 +291,7 @@ return array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#ffffff', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -290,7 +302,7 @@ return array( 'title' => __( 'Border Radius', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '0.25em', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -301,7 +313,7 @@ return array( 'title' => __( 'Border Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#dadddd', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -312,7 +324,7 @@ return array( 'title' => __( 'Border Width', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '1px', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -323,7 +335,7 @@ return array( 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#010b0d', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), @@ -334,7 +346,7 @@ return array( 'title' => __( 'Focus Border Color', 'woocommerce-paypal-payments' ), 'type' => 'text', 'classes' => array( 'ppcp-field-indent' ), - 'default' => '#0057ff', + 'default' => '', 'screens' => array( State::STATE_ONBOARDED, ), diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 6fbdb8d73..3cfaf80ea 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -642,7 +642,8 @@ class AxoManager { return { fields: { cardholderName: {} // optionally pass this to show the card holder name - } + }, + styles: this.remove_keys_with_empty_string(this.axoConfig.style_options) } } @@ -743,6 +744,20 @@ class AxoManager { return this.axoConfig?.widgets?.email === 'use_widget'; } + remove_keys_with_empty_string = (obj) => { + for(let key of Object.keys(obj)){ + if (obj[key] === ''){ + delete obj[key]; + } + else if (typeof obj[key] === 'object'){ + obj[key] = this.remove_keys_with_empty_string(obj[key]); + if (Object.keys(obj[key]).length === 0 ) delete obj[key]; + } + } + + return Array.isArray(obj) ? obj.filter(val => val) : obj; + } + } export default AxoManager; diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php index adb5543c2..b41b392c2 100644 --- a/modules/ppcp-axo/src/Assets/AxoManager.php +++ b/modules/ppcp-axo/src/Assets/AxoManager.php @@ -151,13 +151,13 @@ class AxoManager { */ private function script_data() { return array( - 'environment' => array( + 'environment' => array( 'is_sandbox' => $this->environment->current_environment() === 'sandbox', ), - 'widgets' => array( + 'widgets' => array( 'email' => 'render', ), - 'insights' => array( + 'insights' => array( 'enabled' => true, 'client_id' => ( $this->settings->has( 'client_id' ) ? $this->settings->get( 'client_id' ) : null ), 'session_id' => @@ -171,6 +171,25 @@ class AxoManager { 'value' => WC()->cart->get_total( 'numeric' ), ), ), + 'style_options' => array( + 'root' => array( + 'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '', + 'errorColor' => $this->settings->has( 'axo_style_root_error_color' ) ? $this->settings->get( 'axo_style_root_error_color' ) : '', + 'fontFamily' => $this->settings->has( 'axo_style_root_font_family' ) ? $this->settings->get( 'axo_style_root_font_family' ) : '', + 'textColorBase' => $this->settings->has( 'axo_style_root_text_color_base' ) ? $this->settings->get( 'axo_style_root_text_color_base' ) : '', + 'fontSizeBase' => $this->settings->has( 'axo_style_root_font_size_base' ) ? $this->settings->get( 'axo_style_root_font_size_base' ) : '', + 'padding' => $this->settings->has( 'axo_style_root_padding' ) ? $this->settings->get( 'axo_style_root_padding' ) : '', + 'primaryColor' => $this->settings->has( 'axo_style_root_primary_color' ) ? $this->settings->get( 'axo_style_root_primary_color' ) : '', + ), + 'input' => array( + 'backgroundColor' => $this->settings->has( 'axo_style_input_bg_color' ) ? $this->settings->get( 'axo_style_input_bg_color' ) : '', + 'borderRadius' => $this->settings->has( 'axo_style_input_border_radius' ) ? $this->settings->get( 'axo_style_input_border_radius' ) : '', + 'borderColor' => $this->settings->has( 'axo_style_input_border_color' ) ? $this->settings->get( 'axo_style_input_border_color' ) : '', + 'borderWidth' => $this->settings->has( 'axo_style_input_border_width' ) ? $this->settings->get( 'axo_style_input_border_width' ) : '', + 'textColorBase' => $this->settings->has( 'axo_style_input_text_color_base' ) ? $this->settings->get( 'axo_style_input_text_color_base' ) : '', + 'focusBorderColor' => $this->settings->has( 'axo_style_input_focus_border_color' ) ? $this->settings->get( 'axo_style_input_focus_border_color' ) : '', + ), + ), ); } From c76872d9d1a6538c21bd36f09ae642d8dc8b18af Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 15:12:01 +0200 Subject: [PATCH 15/60] Add placeholders for values reference --- modules/ppcp-axo/extensions.php | 123 ++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 55 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 7bcc07d86..a9a2ae959 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -201,61 +201,7 @@ return array( 'axo_style_root_bg_color' => array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), 'type' => 'text', - 'classes' => array( 'ppcp-field-indent' ), - 'default' => '', - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'axo' ), - 'gateway' => array( 'dcc', 'axo' ), - ), - 'axo_style_root_error_color' => array( - 'title' => __( 'Error Color', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'classes' => array( 'ppcp-field-indent' ), - 'default' => '', - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'axo' ), - 'gateway' => array( 'dcc', 'axo' ), - ), - 'axo_style_root_font_family' => array( - 'title' => __( 'Font Family', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'classes' => array( 'ppcp-field-indent' ), - 'default' => '', - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'axo' ), - 'gateway' => array( 'dcc', 'axo' ), - ), - 'axo_style_root_text_color_base' => array( - 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'classes' => array( 'ppcp-field-indent' ), - 'default' => '', - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'axo' ), - 'gateway' => array( 'dcc', 'axo' ), - ), - 'axo_style_root_font_size_base' => array( - 'title' => __( 'Font Size Base', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'classes' => array( 'ppcp-field-indent' ), - 'default' => '', - 'screens' => array( - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'axo' ), - 'gateway' => array( 'dcc', 'axo' ), - ), - 'axo_style_root_padding' => array( - 'title' => __( 'Padding', 'woocommerce-paypal-payments' ), - 'type' => 'text', + 'placeholder' => '#ffffff', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -267,6 +213,67 @@ return array( 'axo_style_root_primary_color' => array( 'title' => __( 'Primary Color', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '#0057F', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_error_color' => array( + 'title' => __( 'Error Color', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'placeholder' => '#D9360B', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_font_family' => array( + 'title' => __( 'Font Family', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'placeholder' => 'PayPal Open', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_text_color_base' => array( + 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'placeholder' => '#010B0D', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_font_size_base' => array( + 'title' => __( 'Font Size Base', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'placeholder' => '16px', + 'classes' => array( 'ppcp-field-indent' ), + 'default' => '', + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), + 'axo_style_root_padding' => array( + 'title' => __( 'Padding', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'placeholder' => '4px', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -290,6 +297,7 @@ return array( 'axo_style_input_bg_color' => array( 'title' => __( 'Background Color', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '#ffffff', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -301,6 +309,7 @@ return array( 'axo_style_input_border_radius' => array( 'title' => __( 'Border Radius', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '0.25em', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -312,6 +321,7 @@ return array( 'axo_style_input_border_color' => array( 'title' => __( 'Border Color', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '#DADDDD', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -323,6 +333,7 @@ return array( 'axo_style_input_border_width' => array( 'title' => __( 'Border Width', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '1px', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -334,6 +345,7 @@ return array( 'axo_style_input_text_color_base' => array( 'title' => __( 'Text Color Base', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '#010B0D', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( @@ -345,6 +357,7 @@ return array( 'axo_style_input_focus_border_color' => array( 'title' => __( 'Focus Border Color', 'woocommerce-paypal-payments' ), 'type' => 'text', + 'placeholder' => '#0057FF', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( From c80f58abcf6dd59cdabf79163a4275ad6efd821f Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 15:33:23 +0200 Subject: [PATCH 16/60] Add setting option to enable/disable name on card field --- modules/ppcp-axo/extensions.php | 13 +++++++++++++ modules/ppcp-axo/resources/js/AxoManager.js | 9 ++++++--- modules/ppcp-axo/src/Assets/AxoManager.php | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index a9a2ae959..184dd5de4 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -152,6 +152,19 @@ return array( 'gateway' => array( 'dcc', 'axo' ), 'requirements' => array( 'axo' ), ), + 'axo_name_on_card' => array( + 'title' => __( 'Display "Name on Card" field', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'default' => 'yes', + 'classes' => array( 'ppcp-field-indent' ), + 'class' => array(), + 'label' => __( 'Enable "Name on Card" field', 'woocommerce-paypal-payments' ), + 'desc_tip' => true, + 'description' => __( 'Enable to display the "Name on Card" field for new Fastlane buyers.', 'woocommerce-paypal-payments' ), + 'screens' => array( State::STATE_ONBOARDED ), + 'gateway' => array( 'dcc', 'axo' ), + 'requirements' => array( 'axo' ), + ), 'axo_style_heading' => array( 'heading' => __( 'Advanced Style Settings (optional)', 'woocommerce-paypal-payments' ), 'heading_html' => sprintf( diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 3cfaf80ea..e3aeb7e7a 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -639,10 +639,13 @@ class AxoManager { } cardComponentData() { + let fields = {}; + if(this.axoConfig.name_on_card === '1') { + fields.cardholderName = {}; + } + return { - fields: { - cardholderName: {} // optionally pass this to show the card holder name - }, + fields: fields, styles: this.remove_keys_with_empty_string(this.axoConfig.style_options) } } diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php index b41b392c2..f0852f38b 100644 --- a/modules/ppcp-axo/src/Assets/AxoManager.php +++ b/modules/ppcp-axo/src/Assets/AxoManager.php @@ -190,6 +190,7 @@ class AxoManager { 'focusBorderColor' => $this->settings->has( 'axo_style_input_focus_border_color' ) ? $this->settings->get( 'axo_style_input_focus_border_color' ) : '', ), ), + 'name_on_card' => $this->settings->has( 'axo_name_on_card' ) ? $this->settings->get( 'axo_name_on_card' ) : '', ); } From 8a9dd52bd0a8ab90ec8fad716e68b0576a34a3da Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 17:01:15 +0200 Subject: [PATCH 17/60] Add type of user as form data to be received on wc process payment request --- modules/ppcp-axo/resources/js/AxoManager.js | 9 ++++++--- modules/ppcp-axo/src/Gateway/AxoGateway.php | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index e3aeb7e7a..71669845a 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -646,7 +646,7 @@ class AxoManager { return { fields: fields, - styles: this.remove_keys_with_empty_string(this.axoConfig.style_options) + styles: this.delete_keys_with_empty_string(this.axoConfig.style_options) } } @@ -697,6 +697,9 @@ class AxoManager { formData.set(key, data[key]); }); + // Set type of user (Ryan) to be received on WC gateway process payment request. + formData.set('fastlane_member', true); + fetch(wc_checkout_params.checkout_url, { // TODO: maybe create a new endpoint to process_payment. method: "POST", body: formData @@ -747,13 +750,13 @@ class AxoManager { return this.axoConfig?.widgets?.email === 'use_widget'; } - remove_keys_with_empty_string = (obj) => { + delete_keys_with_empty_string = (obj) => { for(let key of Object.keys(obj)){ if (obj[key] === ''){ delete obj[key]; } else if (typeof obj[key] === 'object'){ - obj[key] = this.remove_keys_with_empty_string(obj[key]); + obj[key] = this.delete_keys_with_empty_string(obj[key]); if (Object.keys(obj[key]).length === 0 ) delete obj[key]; } } diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 9e94e4dc7..1ca739476 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -208,10 +208,13 @@ class AxoGateway extends WC_Payment_Gateway { public function process_payment( $order_id ) { $wc_order = wc_get_order( $order_id ); - $payment_method_title = __( 'Credit Card (via Fastlane by PayPal)', 'woocommerce-paypal-payments' ); - - $wc_order->set_payment_method_title( $payment_method_title ); - $wc_order->save(); + // phpcs:ignore WordPress.Security.NonceVerification.Missing + $fastlane_member = wc_clean( wp_unslash( $_POST['fastlane_member'] ?? '' ) ); + if ( $fastlane_member ) { + $payment_method_title = __( 'Debit & Credit Cards (via Fastlane by PayPal)', 'woocommerce-paypal-payments' ); + $wc_order->set_payment_method_title( $payment_method_title ); + $wc_order->save(); + } $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order ); From 912e0af35ae5f32c58c6d81296270c1e7da6dbcc Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 17:31:25 +0200 Subject: [PATCH 18/60] Remove additional info icon for ryan flow --- modules/ppcp-axo/resources/js/AxoManager.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 71669845a..97578969b 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -463,9 +463,9 @@ class AxoManager { this.el.gatewayRadioButton.trigger('change'); } - async renderWatermark() { + async renderWatermark(includeAdditionalInfo = true) { (await this.fastlane.FastlaneWatermarkComponent({ - includeAdditionalInfo: true + includeAdditionalInfo })).render(this.el.watermarkContainer.selector); } @@ -562,6 +562,8 @@ class AxoManager { this.hideGatewaySelection = true; this.$('.wc_payment_methods label').hide(); + await this.renderWatermark(false); + this.rerender(); } else { @@ -577,6 +579,8 @@ class AxoManager { this.setStatus('validEmail', true); this.setStatus('hasProfile', false); + await this.renderWatermark(true); + this.cardComponent = (await this.fastlane.FastlaneCardComponent( this.cardComponentData() )).render(this.el.paymentContainer.selector + '-form'); From 44d260ea9ab792cd5c3b26644c47c87fae243f8a Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 18:09:43 +0200 Subject: [PATCH 19/60] Hide credit card gateway on checkout when using Fastlane --- modules/ppcp-axo/src/AxoModule.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 6680c9fd7..4f224f08b 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; /** * Class AxoModule @@ -77,6 +78,31 @@ class AxoModule implements ModuleInterface { 9 ); + // Hides credit card gateway on checkout when using Fastlane. + add_filter( + 'woocommerce_available_payment_gateways', + /** + * Param types removed to avoid third-party issues. + * + * @psalm-suppress MissingClosureParamType + */ + function ( $methods ) use ( $c ): array { + if ( ! is_array( $methods ) || ! $c->get( 'axo.eligible' ) ) { + return $methods; + } + + if ( + ! is_admin() + && is_user_logged_in() === false + && isset( $methods[ CreditCardGateway::ID ] ) + ) { + unset( $methods[ CreditCardGateway::ID ] ); + } + + return $methods; + } + ); + add_action( 'init', static function () use ( $c, $module ) { From e26d8f811050a40a916e6372f2ba7609677b085b Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 2 May 2024 11:56:06 +0200 Subject: [PATCH 20/60] Remove focus on email field for now --- modules/ppcp-axo/resources/js/AxoManager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 97578969b..59f2eaca5 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -431,7 +431,6 @@ class AxoManager { // Move email to the AXO container. let emailRow = document.querySelector(this.el.fieldBillingEmail.selector); wrapperElement.prepend(emailRow); - emailRow.querySelector('input').focus(); } } From 6f1529814ffe295ad584c1d6c4084a97511b18eb Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 2 May 2024 12:18:44 +0200 Subject: [PATCH 21/60] Hide credit card gateway only if axo enabled, also adds a filter to show/hide programmatically --- modules/ppcp-axo/src/AxoModule.php | 37 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 4f224f08b..ad1c68a1b 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; +use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; /** * Class AxoModule @@ -91,11 +92,13 @@ class AxoModule implements ModuleInterface { return $methods; } - if ( - ! is_admin() - && is_user_logged_in() === false - && isset( $methods[ CreditCardGateway::ID ] ) - ) { + $settings = $c->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + if ( apply_filters( + 'woocommerce_paypal_payments_axo_hide_credit_card_gateway', + $this->hide_credit_card_when_using_fastlane( $methods, $settings ) + ) ) { unset( $methods[ CreditCardGateway::ID ] ); } @@ -247,4 +250,28 @@ class AxoModule implements ModuleInterface { */ public function getKey() { } + + /** + * Condition to evaluate if Credit Card gateway should be hidden. + * + * @param array $methods + * @param bool $is_axo_enabled + * @return bool + */ + + /** + * Condition to evaluate if Credit Card gateway should be hidden. + * + * @param array $methods WC payment methods. + * @param Settings $settings The settings. + * @return bool + */ + private function hide_credit_card_when_using_fastlane( array $methods, Settings $settings ): bool { + $is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false; + + return ! is_admin() + && is_user_logged_in() === false + && isset( $methods[ CreditCardGateway::ID ] ) + && $is_axo_enabled; + } } From 0648a01ebbc3687079cded6ab9c65a87db9547e6 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 2 May 2024 14:39:23 +0200 Subject: [PATCH 22/60] Update name on card label and hide it when disabling Fastlane --- modules/ppcp-axo/extensions.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 184dd5de4..433e5d460 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -83,6 +83,7 @@ return array( ->condition_element( 'axo_enabled', '1' ) ->action_visible( 'axo_gateway_title' ) ->action_visible( 'axo_privacy' ) + ->action_visible( 'axo_name_on_card' ) ->action_visible( 'axo_style_heading' ) ->action_class( 'axo_enabled', 'active' ) ->to_array(), @@ -153,14 +154,12 @@ return array( 'requirements' => array( 'axo' ), ), 'axo_name_on_card' => array( - 'title' => __( 'Display "Name on Card" field', 'woocommerce-paypal-payments' ), + 'title' => __( 'Display Name on Card', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'default' => 'yes', 'classes' => array( 'ppcp-field-indent' ), 'class' => array(), - 'label' => __( 'Enable "Name on Card" field', 'woocommerce-paypal-payments' ), - 'desc_tip' => true, - 'description' => __( 'Enable to display the "Name on Card" field for new Fastlane buyers.', 'woocommerce-paypal-payments' ), + 'label' => __( 'Enable this to display the "Name on Card" field for new Fastlane buyers.', 'woocommerce-paypal-payments' ), 'screens' => array( State::STATE_ONBOARDED ), 'gateway' => array( 'dcc', 'axo' ), 'requirements' => array( 'axo' ), From c1e51cb8a3df7406212c3e26581fd122ea9c9335 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 2 May 2024 16:53:19 +0200 Subject: [PATCH 23/60] Updade privacy text --- modules/ppcp-axo/extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 433e5d460..148347f65 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -135,7 +135,7 @@ return array( 'title' => __( 'Privacy', 'woocommerce-paypal-payments' ), 'type' => 'select', 'label' => __( - 'Require customers to confirm express payments from the Cart and Express Checkout on the checkout page. + 'This setting will control whether Fastlane branding is shown by email field.

PayPal powers this accelerated checkout solution from Fastlane. Since you\'ll share consumers\' email addresses with PayPal, please consult your legal advisors on the apropriate privacy setting for your business.

', 'woocommerce-paypal-payments' ), From 2a20df9b6f91c6fc9174d1053bd2a7a0b905db95 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 12:28:14 +0200 Subject: [PATCH 24/60] Enable name on card and hide it from settings --- modules/ppcp-axo/extensions.php | 2 +- modules/ppcp-axo/resources/js/AxoManager.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 148347f65..e1d9dc3a1 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -161,7 +161,7 @@ return array( 'class' => array(), 'label' => __( 'Enable this to display the "Name on Card" field for new Fastlane buyers.', 'woocommerce-paypal-payments' ), 'screens' => array( State::STATE_ONBOARDED ), - 'gateway' => array( 'dcc', 'axo' ), + 'gateway' => array(), 'requirements' => array( 'axo' ), ), 'axo_style_heading' => array( diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 59f2eaca5..d36cfd4d2 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -642,10 +642,11 @@ class AxoManager { } cardComponentData() { - let fields = {}; - if(this.axoConfig.name_on_card === '1') { - fields.cardholderName = {}; - } + const fields = { + cardholderName: { + enabled: true + } + }; return { fields: fields, From f72b95fcc049333f00154b2cdc9a4cd5f8e68c27 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 6 May 2024 12:30:34 +0200 Subject: [PATCH 25/60] Fix alignment of AXO credit card icons --- modules/ppcp-axo/resources/css/styles.scss | 10 ---------- modules/ppcp-axo/src/Gateway/AxoGateway.php | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/ppcp-axo/resources/css/styles.scss b/modules/ppcp-axo/resources/css/styles.scss index 0fcfb2cd6..ef71f331b 100644 --- a/modules/ppcp-axo/resources/css/styles.scss +++ b/modules/ppcp-axo/resources/css/styles.scss @@ -1,13 +1,3 @@ - -.ppcp-axo-card-icons { - padding: 4px 0 16px 25px; - - .ppcp-card-icon { - float: left !important; - max-height: 25px; - } -} - .ppcp-axo-watermark-container { max-width: 200px; margin-top: 10px; diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 1ca739476..918ffa4c0 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -300,7 +300,7 @@ class AxoGateway extends WC_Payment_Gateway { > '; } - return '
' . implode( '', $images ) . '
'; + return implode( '', $images ); } /** From fe3e4762dd6338f0c167fb3251bdb8d25b707cbe Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 6 May 2024 12:46:33 +0200 Subject: [PATCH 26/60] Update the PayPal-Open font family name for the AXO setting --- modules/ppcp-axo/extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index 148347f65..b728d826d 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -249,7 +249,7 @@ return array( 'axo_style_root_font_family' => array( 'title' => __( 'Font Family', 'woocommerce-paypal-payments' ), 'type' => 'text', - 'placeholder' => 'PayPal Open', + 'placeholder' => 'PayPal-Open', 'classes' => array( 'ppcp-field-indent' ), 'default' => '', 'screens' => array( From e886b0027c037c3a545daefdbca27694c84318fd Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 12:49:41 +0200 Subject: [PATCH 27/60] Do not set billing address and card if no billing address in profile data response --- modules/ppcp-axo/resources/js/AxoManager.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index d36cfd4d2..2ebc5234f 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -547,13 +547,16 @@ class AxoManager { if (authResponse.authenticationState === 'succeeded') { log(JSON.stringify(authResponse)); - // Add addresses this.setShipping(authResponse.profileData.shippingAddress); - this.setBilling({ - address: authResponse.profileData.card.paymentSource.card.billingAddress, - phoneNumber: authResponse.profileData.shippingAddress.phoneNumber.nationalNumber ?? '' - }); - this.setCard(authResponse.profileData.card); + + const billingAddress = authResponse.profileData?.card?.paymentSource?.card?.billingAddress; + if(billingAddress) { + this.setBilling({ + address: billingAddress, + phoneNumber: authResponse.profileData.shippingAddress.phoneNumber.nationalNumber ?? '' + }); + this.setCard(authResponse.profileData.card); + } this.setStatus('validEmail', true); this.setStatus('hasProfile', true); From 404095423bf1cf5271c2de81e4e7b236e6b69876 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 14:03:44 +0200 Subject: [PATCH 28/60] Ensure sending billing phone number if it exist in shipping address --- modules/ppcp-axo/resources/js/AxoManager.js | 16 ++++++++++++++++ .../ppcp-axo/resources/js/Views/BillingView.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 2ebc5234f..cf1c61165 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -626,6 +626,8 @@ class AxoManager { this.shippingView.toSubmitData(data); this.cardView.toSubmitData(data); + this.ensureBillingPhoneNumber(data); + this.submit(this.data.card.id, data); } else { // Gary flow @@ -771,6 +773,20 @@ class AxoManager { return Array.isArray(obj) ? obj.filter(val => val) : obj; } + ensureBillingPhoneNumber(data) { + if (data.billing_phone === '') { + let phone = ''; + const cc = this.data?.shipping?.phoneNumber?.countryCode; + const number = this.data?.shipping?.phoneNumber?.nationalNumber; + + if (cc) { + phone = `+${cc} `; + } + phone += number; + + data.billing_phone = phone; + } + } } export default AxoManager; diff --git a/modules/ppcp-axo/resources/js/Views/BillingView.js b/modules/ppcp-axo/resources/js/Views/BillingView.js index aba44afcf..bba7f0d5c 100644 --- a/modules/ppcp-axo/resources/js/Views/BillingView.js +++ b/modules/ppcp-axo/resources/js/Views/BillingView.js @@ -91,7 +91,7 @@ class BillingView { 'selector': '#billing_company_field', 'valuePath': null, }, - phone: { + phoneNumber: { 'selector': '#billing_phone_field', 'valuePath': 'billing.phoneNumber' } From 6227ba40ae8acd80d526ca2a8211feaf05ee249a Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 14:22:51 +0200 Subject: [PATCH 29/60] Change shipping address display format --- modules/ppcp-axo/resources/js/Views/ShippingView.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ppcp-axo/resources/js/Views/ShippingView.js b/modules/ppcp-axo/resources/js/Views/ShippingView.js index a64b56a09..a6f3915a7 100644 --- a/modules/ppcp-axo/resources/js/Views/ShippingView.js +++ b/modules/ppcp-axo/resources/js/Views/ShippingView.js @@ -45,8 +45,7 @@ class ShippingView {
${data.value('firstName')} ${data.value('lastName')}
${data.value('street1')}
${data.value('street2')}
-
${data.value('postCode')} ${data.value('city')}
-
${valueOfSelect('#billing_state', data.value('stateCode'))}
+
${data.value('city')} ${valueOfSelect('#billing_state', data.value('stateCode'))} ${data.value('postCode')}
${valueOfSelect('#billing_country', data.value('countryCode'))}
${data.value('phone')}
From a12166e0d0691b4b9812a715f2aba3e8c3a24f9e Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 14:25:04 +0200 Subject: [PATCH 30/60] Change shipping address display format --- modules/ppcp-axo/resources/js/Views/ShippingView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-axo/resources/js/Views/ShippingView.js b/modules/ppcp-axo/resources/js/Views/ShippingView.js index a6f3915a7..0799fdbc5 100644 --- a/modules/ppcp-axo/resources/js/Views/ShippingView.js +++ b/modules/ppcp-axo/resources/js/Views/ShippingView.js @@ -45,7 +45,7 @@ class ShippingView {
${data.value('firstName')} ${data.value('lastName')}
${data.value('street1')}
${data.value('street2')}
-
${data.value('city')} ${valueOfSelect('#billing_state', data.value('stateCode'))} ${data.value('postCode')}
+
${data.value('city')}, ${valueOfSelect('#billing_state', data.value('stateCode'))} ${data.value('postCode')}
${valueOfSelect('#billing_country', data.value('countryCode'))}
${data.value('phone')}
From 9ff89f16f0b7a0a13230369a513e754e427fe27f Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 14:42:37 +0200 Subject: [PATCH 31/60] Revert billing view phone key to previous value --- modules/ppcp-axo/resources/js/Views/BillingView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-axo/resources/js/Views/BillingView.js b/modules/ppcp-axo/resources/js/Views/BillingView.js index bba7f0d5c..aba44afcf 100644 --- a/modules/ppcp-axo/resources/js/Views/BillingView.js +++ b/modules/ppcp-axo/resources/js/Views/BillingView.js @@ -91,7 +91,7 @@ class BillingView { 'selector': '#billing_company_field', 'valuePath': null, }, - phoneNumber: { + phone: { 'selector': '#billing_phone_field', 'valuePath': 'billing.phoneNumber' } From ed82a8df2bc2b5691bebc048c575a99313460e3f Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 6 May 2024 15:22:49 +0200 Subject: [PATCH 32/60] Add new AXO credit card icons --- modules/ppcp-axo/services.php | 30 +++++++++++++++++++++ modules/ppcp-axo/src/Gateway/AxoGateway.php | 24 ++++++++++++++--- modules/ppcp-wc-gateway/services.php | 8 ++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 8b65508ae..780f59a8a 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -68,6 +68,7 @@ return array( $container->get( 'wcgateway.url' ), $container->get( 'wcgateway.order-processor' ), $container->get( 'axo.card_icons' ), + $container->get( 'axo.card_icons.axo' ), $container->get( 'api.endpoint.order' ), $container->get( 'api.factory.purchase-unit' ), $container->get( 'api.factory.shipping-preference' ), @@ -98,6 +99,35 @@ return array( ); }, + 'axo.card_icons.axo' => static function ( ContainerInterface $container ): array { + return array( + array( + 'title' => 'Dinersclub', + 'file' => 'dinersclub-light.svg', + ), + array( + 'title' => 'Discover', + 'file' => 'discover-light.svg', + ), + array( + 'title' => 'JCB', + 'file' => 'jcb-light.svg', + ), + array( + 'title' => 'MasterCard', + 'file' => 'mastercard-light.svg', + ), + array( + 'title' => 'UnionPay', + 'file' => 'unionpay-light.svg', + ), + array( + 'title' => 'Visa', + 'file' => 'visa-light.svg', + ), + ); + }, + /** * The matrix which countries and currency combinations can be used for AXO. */ diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 918ffa4c0..41febd9a7 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -70,6 +70,13 @@ class AxoGateway extends WC_Payment_Gateway { */ protected $card_icons; + /** + * The AXO card icons. + * + * @var array + */ + protected $card_icons_axo; + /** * The order endpoint. * @@ -120,6 +127,7 @@ class AxoGateway extends WC_Payment_Gateway { * @param string $wcgateway_module_url The WcGateway module URL. * @param OrderProcessor $order_processor The Order processor. * @param array $card_icons The card icons. + * @param array $card_icons_axo The card icons. * @param OrderEndpoint $order_endpoint The order endpoint. * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory. * @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory. @@ -133,6 +141,7 @@ class AxoGateway extends WC_Payment_Gateway { string $wcgateway_module_url, OrderProcessor $order_processor, array $card_icons, + array $card_icons_axo, OrderEndpoint $order_endpoint, PurchaseUnitFactory $purchase_unit_factory, ShippingPreferenceFactory $shipping_preference_factory, @@ -147,6 +156,7 @@ class AxoGateway extends WC_Payment_Gateway { $this->wcgateway_module_url = $wcgateway_module_url; $this->order_processor = $order_processor; $this->card_icons = $card_icons; + $this->card_icons_axo = $card_icons_axo; $this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' ); $this->method_description = __( 'PayPal Fastlane offers an accelerated checkout experience that recognizes guest shoppers and autofills their details so they can pay in seconds.', 'woocommerce-paypal-payments' ); @@ -285,18 +295,26 @@ class AxoGateway extends WC_Payment_Gateway { * @return string */ public function get_icon() { - $icon = parent::get_icon(); + $icon = parent::get_icon(); + $icons = $this->card_icons; + $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/'; + + if ( $this->card_icons_axo ) { + $icons = $this->card_icons_axo; + $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/'; + } if ( empty( $this->card_icons ) ) { return $icon; } $images = array(); - foreach ( $this->card_icons as $card ) { + + foreach ( $icons as $card ) { $images[] = ' '; } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 65101e8b8..28915f0da 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -803,6 +803,14 @@ return array( 'elo' => _x( 'Elo', 'Name of credit card', 'woocommerce-paypal-payments' ), 'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-payments' ), ), + 'options_axo' => array( + 'dinersclub-light' => _x( 'Diners Club (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'discover-light' => _x( 'Discover (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'jcb-light' => _x( 'JCB (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'mastercard-light' => _x( 'Mastercard (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'unionpay-light' => _x( 'UnionPay (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'visa-light' => _x( 'Visa (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + ), 'screens' => array( State::STATE_ONBOARDED, ), From 5a037b1c9384a2309792eb5f60bf8ac1a6916de7 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 15:31:30 +0200 Subject: [PATCH 33/60] Hide terms and conditions checkbox before Fastlane authentication --- modules/ppcp-axo/resources/js/AxoManager.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index cf1c61165..ee4ddf4ee 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -162,6 +162,20 @@ class AxoManager { ev.preventDefault(); } }); + + // Listening to status update event + document.addEventListener('axo_status_updated', (ev) => { + const termsField = document.querySelector("[name='terms-field']"); + if(termsField) { + const status = ev.detail; + + if(status.active && status.validEmail === false && status.hasProfile === false) { + termsField.parentElement.style.display = 'none'; + } else { + termsField.parentElement.style.display = 'block'; + } + } + }); } rerender() { @@ -347,6 +361,8 @@ class AxoManager { log('Status updated', JSON.parse(JSON.stringify(this.status))); + document.dispatchEvent(new CustomEvent("axo_status_updated", {detail: this.status})); + this.rerender(); } From a7151a2ea435417a0ce35c563e9070403ff4941b Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 15:48:20 +0200 Subject: [PATCH 34/60] Remove duplicated docblock --- modules/ppcp-axo/src/AxoModule.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index ad1c68a1b..2b34892fb 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -251,14 +251,6 @@ class AxoModule implements ModuleInterface { public function getKey() { } - /** - * Condition to evaluate if Credit Card gateway should be hidden. - * - * @param array $methods - * @param bool $is_axo_enabled - * @return bool - */ - /** * Condition to evaluate if Credit Card gateway should be hidden. * From 117fbbef135b70ccd854ea0e19495aa55fe5ddcc Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 6 May 2024 16:14:59 +0200 Subject: [PATCH 35/60] Ensure otp failed or cancelled render card fields with no consent toggle --- modules/ppcp-axo/resources/js/AxoManager.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index ee4ddf4ee..c7bddc898 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -586,7 +586,17 @@ class AxoManager { } else { // authentication failed or canceled by the customer + // set status as guest customer log("Authentication Failed") + + this.setStatus('validEmail', true); + this.setStatus('hasProfile', false); + + await this.renderWatermark(true); + + this.cardComponent = (await this.fastlane.FastlaneCardComponent( + this.cardComponentData() + )).render(this.el.paymentContainer.selector + '-form'); } } else { From 0a793de4139f17ce8077b7f4334f7cc0ba2f529f Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 6 May 2024 16:40:35 +0200 Subject: [PATCH 36/60] Temporarily disable the new icons --- modules/ppcp-axo/src/Gateway/AxoGateway.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 41febd9a7..b0a099b81 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -299,10 +299,10 @@ class AxoGateway extends WC_Payment_Gateway { $icons = $this->card_icons; $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/'; - if ( $this->card_icons_axo ) { - $icons = $this->card_icons_axo; - $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/'; - } +// if ( $this->card_icons_axo ) { +// $icons = $this->card_icons_axo; +// $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/'; +// } if ( empty( $this->card_icons ) ) { return $icon; From ee571138d2c3d1fc3561200311a181880b9509de Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 6 May 2024 17:03:51 +0200 Subject: [PATCH 37/60] Remove the commented out code --- modules/ppcp-axo/src/Gateway/AxoGateway.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index b0a099b81..9fa8152ff 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -299,11 +299,6 @@ class AxoGateway extends WC_Payment_Gateway { $icons = $this->card_icons; $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/'; -// if ( $this->card_icons_axo ) { -// $icons = $this->card_icons_axo; -// $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/'; -// } - if ( empty( $this->card_icons ) ) { return $icon; } From f2c6ff09af39348b588f1958d50f206fe6fb850f Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 7 May 2024 09:55:48 +0200 Subject: [PATCH 38/60] Add improvements --- modules/ppcp-axo/resources/js/AxoManager.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index c7bddc898..f0ccca428 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -168,12 +168,9 @@ class AxoManager { const termsField = document.querySelector("[name='terms-field']"); if(termsField) { const status = ev.detail; + const shouldHide = status.active && status.validEmail === false && status.hasProfile === false; - if(status.active && status.validEmail === false && status.hasProfile === false) { - termsField.parentElement.style.display = 'none'; - } else { - termsField.parentElement.style.display = 'block'; - } + termsField.parentElement.style.display = shouldHide ? 'none' : 'block'; } }); } @@ -681,7 +678,7 @@ class AxoManager { return { fields: fields, - styles: this.delete_keys_with_empty_string(this.axoConfig.style_options) + styles: this.deleteKeysWithEmptyString(this.axoConfig.style_options) } } @@ -785,13 +782,13 @@ class AxoManager { return this.axoConfig?.widgets?.email === 'use_widget'; } - delete_keys_with_empty_string = (obj) => { + deleteKeysWithEmptyString = (obj) => { for(let key of Object.keys(obj)){ if (obj[key] === ''){ delete obj[key]; } else if (typeof obj[key] === 'object'){ - obj[key] = this.delete_keys_with_empty_string(obj[key]); + obj[key] = this.deleteKeysWithEmptyString(obj[key]); if (Object.keys(obj[key]).length === 0 ) delete obj[key]; } } From b43058f13ed7c53d15e87e8eb99ec2f1c56a13c7 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 7 May 2024 10:53:52 +0200 Subject: [PATCH 39/60] Fix wrong billing address admin areas values --- modules/ppcp-axo/resources/js/AxoManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index f0ccca428..ead60573d 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -690,8 +690,8 @@ class AxoManager { billingAddress: { addressLine1: this.billingView.inputValue('street1'), addressLine2: this.billingView.inputValue('street2'), - adminArea1: this.billingView.inputValue('city'), - adminArea2: this.billingView.inputValue('stateCode'), + adminArea1: this.billingView.inputValue('stateCode'), + adminArea2: this.billingView.inputValue('city'), postalCode: this.billingView.inputValue('postCode'), countryCode: this.billingView.inputValue('countryCode'), } From 94061bb2a5d8d378c83a7baabe6c876da9388245 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 7 May 2024 15:25:06 +0200 Subject: [PATCH 40/60] AXO: Fix state mapping details for shipping details --- modules/ppcp-axo/resources/js/AxoManager.js | 4 +++- modules/ppcp-axo/resources/js/Views/ShippingView.js | 12 ++++++++---- modules/ppcp-axo/src/Assets/AxoManager.php | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index ead60573d..97a946b6d 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -34,6 +34,8 @@ class AxoManager { card: null, }; + this.states = this.axoConfig.woocommerce.states; + this.el = new DomElementCollection(); this.styles = { @@ -46,7 +48,7 @@ class AxoManager { this.registerEventHandlers(); - this.shippingView = new ShippingView(this.el.shippingAddressContainer.selector, this.el); + this.shippingView = new ShippingView(this.el.shippingAddressContainer.selector, this.el, this.states ); this.billingView = new BillingView(this.el.billingAddressContainer.selector, this.el); this.cardView = new CardView(this.el.paymentContainer.selector + '-details', this.el, this); diff --git a/modules/ppcp-axo/resources/js/Views/ShippingView.js b/modules/ppcp-axo/resources/js/Views/ShippingView.js index 0799fdbc5..b0b1eb4e2 100644 --- a/modules/ppcp-axo/resources/js/Views/ShippingView.js +++ b/modules/ppcp-axo/resources/js/Views/ShippingView.js @@ -2,9 +2,9 @@ import FormFieldGroup from "../Components/FormFieldGroup"; class ShippingView { - constructor(selector, elements) { + constructor(selector, elements, states) { this.el = elements; - + this.states = states; this.group = new FormFieldGroup({ baseSelector: '.woocommerce-checkout', contentSelector: selector, @@ -34,6 +34,10 @@ class ShippingView { `; } + const countryCode = data.value('countryCode'); + const stateCode = data.value('stateCode'); + const stateName = (this.states[countryCode] && this.states[countryCode][stateCode]) ? this.states[countryCode][stateCode] : stateCode; + return `
@@ -45,8 +49,8 @@ class ShippingView {
${data.value('firstName')} ${data.value('lastName')}
${data.value('street1')}
${data.value('street2')}
-
${data.value('city')}, ${valueOfSelect('#billing_state', data.value('stateCode'))} ${data.value('postCode')}
-
${valueOfSelect('#billing_country', data.value('countryCode'))}
+
${data.value('city')}, ${stateName} ${data.value('postCode')}
+
${valueOfSelect('#billing_country', countryCode)}
${data.value('phone')}
`; diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php index f0852f38b..d3dff074b 100644 --- a/modules/ppcp-axo/src/Assets/AxoManager.php +++ b/modules/ppcp-axo/src/Assets/AxoManager.php @@ -191,6 +191,12 @@ class AxoManager { ), ), 'name_on_card' => $this->settings->has( 'axo_name_on_card' ) ? $this->settings->get( 'axo_name_on_card' ) : '', + 'woocommerce' => array( + 'states' => array( + 'US' => WC()->countries->get_states( 'US' ), + 'CA' => WC()->countries->get_states( 'CA' ), + ), + ), ); } From c5f51d897adce283c522d22c0988a42aafe5e1b9 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 7 May 2024 15:37:39 +0200 Subject: [PATCH 41/60] AXO: Fix gateway icons --- modules/ppcp-axo/resources/css/styles.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/ppcp-axo/resources/css/styles.scss b/modules/ppcp-axo/resources/css/styles.scss index ef71f331b..ccd82e14f 100644 --- a/modules/ppcp-axo/resources/css/styles.scss +++ b/modules/ppcp-axo/resources/css/styles.scss @@ -43,3 +43,7 @@ margin: var(--global-md-spacing) 0 1em; padding: 0.6em 1em; } + +label[for="payment_method_ppcp-axo-gateway"] .ppcp-card-icon { + max-height: 25px; +} From f673b3d4961083b605f455a987e1bdca94b0e94b Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Wed, 8 May 2024 00:30:59 +0200 Subject: [PATCH 42/60] Add enter key submission to AXO --- modules/ppcp-axo/resources/js/AxoManager.js | 33 +++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index f0ccca428..86e6ab095 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -36,6 +36,8 @@ class AxoManager { this.el = new DomElementCollection(); + this.emailInput = document.querySelector(this.el.fieldBillingEmail.selector + ' input'); + this.styles = { root: { backgroundColorPrimary: '#ffffff' @@ -160,9 +162,21 @@ class AxoManager { this.$('form.woocommerce-checkout input').on('keydown', async (ev) => { if(ev.key === 'Enter' && getCurrentPaymentMethod() === 'ppcp-axo-gateway' ) { ev.preventDefault(); + log('Enter key attempt'); + log('emailInput', this.emailInput.value); + log('this.lastEmailCheckedIdentity', this.lastEmailCheckedIdentity); + if (this.emailInput && this.lastEmailCheckedIdentity !== this.emailInput.value) { + await this.onChangeEmail(); + } } }); + // Clear last email checked identity when email field is focused. + this.$('#billing_email_field input').on('focus', (ev) => { + log('Clear the last email checked:', this.lastEmailCheckedIdentity); + this.lastEmailCheckedIdentity = ''; + }); + // Listening to status update event document.addEventListener('axo_status_updated', (ev) => { const termsField = document.querySelector("[name='terms-field']"); @@ -368,8 +382,10 @@ class AxoManager { this.initFastlane(); this.setStatus('active', true); - const emailInput = document.querySelector(this.el.fieldBillingEmail.selector + ' input'); - if (emailInput && this.lastEmailCheckedIdentity !== emailInput.value) { + log('Attempt on activation'); + log('emailInput', this.emailInput.value); + log('this.lastEmailCheckedIdentity', this.lastEmailCheckedIdentity); + if (this.emailInput && this.lastEmailCheckedIdentity !== this.emailInput.value) { this.onChangeEmail(); } } @@ -409,7 +425,6 @@ class AxoManager { // Watermark container const wc = this.el.watermarkContainer; if (!document.querySelector(wc.selector)) { - this.emailInput = document.querySelector(this.el.fieldBillingEmail.selector + ' input'); this.emailInput.insertAdjacentHTML('afterend', `
`); @@ -488,12 +503,18 @@ class AxoManager { // TODO } else { - - this.emailInput = document.querySelector(this.el.fieldBillingEmail.selector + ' input'); this.emailInput.addEventListener('change', async ()=> { - this.onChangeEmail(); + log('Change event attempt'); + log('emailInput', this.emailInput.value); + log('this.lastEmailCheckedIdentity', this.lastEmailCheckedIdentity); + if (this.emailInput && this.lastEmailCheckedIdentity !== this.emailInput.value) { + this.onChangeEmail(); + } }); + log('Last, this.emailInput.value attempt'); + log('emailInput', this.emailInput.value); + log('this.lastEmailCheckedIdentity', this.lastEmailCheckedIdentity); if (this.emailInput.value) { this.onChangeEmail(); } From ce280e9cbaee475282bc7280be852826e5bbc1f4 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 9 May 2024 13:06:20 +0200 Subject: [PATCH 43/60] Add new helper class that provides methods for Cart and Checkout type detection --- .../src/Helper/CartCheckoutDetector.php | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php diff --git a/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php b/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php new file mode 100644 index 000000000..c9826bfe3 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php @@ -0,0 +1,124 @@ +get_elementor_widgets( wc_get_page_id( 'checkout' ) ); + + if ( $elementor_widgets ) { + return in_array( 'woocommerce-checkout-page', $elementor_widgets); + } + + return false; + } + + /** + * Check if the Cart page is using Elementor. + * + * @return bool + */ + public function has_elementor_cart(): bool { + $elementor_widgets = $this->get_elementor_widgets( wc_get_page_id( 'cart' ) ); + + if ( $elementor_widgets ) { + return in_array( 'woocommerce-cart-page', $elementor_widgets); + } + + return false; + } + + /** + * Check if the Checkout page is using the block checkout. + * + * @return bool + */ + public function has_block_checkout(): bool { + $checkout_page_id = wc_get_page_id( 'checkout' ); + return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id ); + } + + /** + * Check if the Cart page is using the block cart. + * + * @return bool + */ + public function has_block_cart(): bool { + $cart_page_id = wc_get_page_id( 'cart' ); + return $cart_page_id && has_block( 'woocommerce/cart', $cart_page_id ); + } + + /** + * Check if the Checkout page is using the classic checkout. + * + * @return bool + */ + public function has_classic_checkout(): bool { + $checkout_page_id = wc_get_page_id( 'checkout' ); + return $checkout_page_id && has_block( 'woocommerce/classic-shortcode', $checkout_page_id ); + } + + /** + * Check if the Cart page is using the classic cart. + * + * @return bool + */ + public function has_classic_cart(): bool { + $cart_page_id = wc_get_page_id( 'cart' ); + return $cart_page_id && has_block( 'woocommerce/classic-shortcode', $cart_page_id ); + } +} From 42d50227f01a5bfbe593467ce717d9f5cec2451c Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 9 May 2024 14:01:58 +0200 Subject: [PATCH 44/60] Add new credit card icon files --- .gitignore | 1 + .../assets/images/axo/dinersclub-light.svg | 7 ++ .../assets/images/axo/discover-light.svg | 6 ++ .../assets/images/axo/jcb-light.svg | 71 +++++++++++++++++++ .../assets/images/axo/mastercard-light.svg | 31 ++++++++ .../assets/images/axo/unionpay-light.svg | 25 +++++++ .../assets/images/axo/visa-light.svg | 11 +++ 7 files changed, 152 insertions(+) create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg diff --git a/.gitignore b/.gitignore index 6b05a4982..9ffcb360b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules yarn-error.log modules/*/vendor/* modules/*/assets/* +!modules/ppcp-wc-gateway/assets/images *.zip .env .env.e2e diff --git a/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg new file mode 100644 index 000000000..5da52df9e --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg new file mode 100644 index 000000000..3491abe6d --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg new file mode 100644 index 000000000..7507d8df1 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg new file mode 100644 index 000000000..401f705d4 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg new file mode 100644 index 000000000..5fe47e295 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg new file mode 100644 index 000000000..4dffb2c48 --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + From 41b59bdfb4ad2dc3ca53446aab9d0f9b9f6e835e Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 9 May 2024 14:06:03 +0200 Subject: [PATCH 45/60] Enable the new icons for Fastlane checkout --- modules/ppcp-axo/src/Gateway/AxoGateway.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 9fa8152ff..41febd9a7 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -299,6 +299,11 @@ class AxoGateway extends WC_Payment_Gateway { $icons = $this->card_icons; $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/'; + if ( $this->card_icons_axo ) { + $icons = $this->card_icons_axo; + $icons_src = esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/'; + } + if ( empty( $this->card_icons ) ) { return $icon; } From 39cf0c99fc3bf97bcc4b16fb647a64c9dc18137b Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 9 May 2024 16:14:37 +0200 Subject: [PATCH 46/60] Ensure empty data scenarios --- modules/ppcp-axo/resources/js/AxoManager.js | 23 +++++++++++++------ .../resources/js/Views/ShippingView.js | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index e3140b64e..3b0555787 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -583,15 +583,24 @@ class AxoManager { if (authResponse.authenticationState === 'succeeded') { log(JSON.stringify(authResponse)); - this.setShipping(authResponse.profileData.shippingAddress); + const shippingData = authResponse.profileData.shippingAddress; + if(shippingData) { + this.setShipping(shippingData); + } - const billingAddress = authResponse.profileData?.card?.paymentSource?.card?.billingAddress; - if(billingAddress) { - this.setBilling({ - address: billingAddress, - phoneNumber: authResponse.profileData.shippingAddress.phoneNumber.nationalNumber ?? '' - }); + const cardBillingAddress = authResponse.profileData?.card?.paymentSource?.card?.billingAddress; + if(cardBillingAddress) { this.setCard(authResponse.profileData.card); + + const billingData = { + address: cardBillingAddress, + }; + const phoneNumber = authResponse.profileData?.shippingAddress?.phoneNumber?.nationalNumber ?? ''; + if(phoneNumber) { + billingData.phoneNumber = phoneNumber + } + + this.setBilling(billingData); } this.setStatus('validEmail', true); diff --git a/modules/ppcp-axo/resources/js/Views/ShippingView.js b/modules/ppcp-axo/resources/js/Views/ShippingView.js index b0b1eb4e2..ec8cfb149 100644 --- a/modules/ppcp-axo/resources/js/Views/ShippingView.js +++ b/modules/ppcp-axo/resources/js/Views/ShippingView.js @@ -38,6 +38,20 @@ class ShippingView { const stateCode = data.value('stateCode'); const stateName = (this.states[countryCode] && this.states[countryCode][stateCode]) ? this.states[countryCode][stateCode] : stateCode; + if( + this.hasEmptyValues(data, stateName) + ) { + return ` +
+
+

Shipping

+ Edit +
+
Please fill in your shipping details.
+
+ `; + } + return `
@@ -118,6 +132,15 @@ class ShippingView { }); } + hasEmptyValues(data, stateName) { + return !data.value('email') + || !data.value('firstName') + || !data.value('lastName') + || !data.value('street1') + || !data.value('city') + || !stateName; + } + isActive() { return this.group.active; } From a14624b1f388d7227d266673f783723abf583c8a Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Fri, 10 May 2024 00:55:28 +0200 Subject: [PATCH 47/60] Add Amex icon and fix the icons order --- modules/ppcp-axo/resources/css/styles.scss | 11 +++++-- modules/ppcp-axo/services.php | 32 +++++++++++-------- .../assets/images/axo/amex-light.svg | 1 + modules/ppcp-wc-gateway/services.php | 11 ++++--- 4 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg diff --git a/modules/ppcp-axo/resources/css/styles.scss b/modules/ppcp-axo/resources/css/styles.scss index ccd82e14f..196b2086c 100644 --- a/modules/ppcp-axo/resources/css/styles.scss +++ b/modules/ppcp-axo/resources/css/styles.scss @@ -44,6 +44,13 @@ padding: 0.6em 1em; } -label[for="payment_method_ppcp-axo-gateway"] .ppcp-card-icon { - max-height: 25px; +#payment .payment_methods li label[for="payment_method_ppcp-axo-gateway"] { + img { + float: none; + vertical-align: middle; + } + + .ppcp-card-icon { + max-height: 25px; + } } diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 780f59a8a..e7a450692 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -102,28 +102,32 @@ return array( 'axo.card_icons.axo' => static function ( ContainerInterface $container ): array { return array( array( - 'title' => 'Dinersclub', - 'file' => 'dinersclub-light.svg', - ), - array( - 'title' => 'Discover', - 'file' => 'discover-light.svg', - ), - array( - 'title' => 'JCB', - 'file' => 'jcb-light.svg', + 'title' => 'Visa', + 'file' => 'visa-light.svg', ), array( 'title' => 'MasterCard', 'file' => 'mastercard-light.svg', ), array( - 'title' => 'UnionPay', - 'file' => 'unionpay-light.svg', + 'title' => 'Amex', + 'file' => 'amex-light.svg', ), array( - 'title' => 'Visa', - 'file' => 'visa-light.svg', + 'title' => 'Discover', + 'file' => 'discover-light.svg', + ), + array( + 'title' => 'Diners Club', + 'file' => 'dinersclub-light.svg', + ), + array( + 'title' => 'JCB', + 'file' => 'jcb-light.svg', + ), + array( + 'title' => 'UnionPay', + 'file' => 'unionpay-light.svg', ), ); }, diff --git a/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg new file mode 100644 index 000000000..1228978ca --- /dev/null +++ b/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 28915f0da..dcbc43333 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -804,12 +804,13 @@ return array( 'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-payments' ), ), 'options_axo' => array( - 'dinersclub-light' => _x( 'Diners Club (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), - 'discover-light' => _x( 'Discover (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), - 'jcb-light' => _x( 'JCB (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), - 'mastercard-light' => _x( 'Mastercard (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), - 'unionpay-light' => _x( 'UnionPay (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), 'visa-light' => _x( 'Visa (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'mastercard-light' => _x( 'Mastercard (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'amex-light' => _x( 'Amex (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'discover-light' => _x( 'Discover (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'dinersclub-light' => _x( 'Diners Club (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'jcb-light' => _x( 'JCB (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), + 'unionpay-light' => _x( 'UnionPay (light)', 'Name of credit card', 'woocommerce-paypal-payments' ), ), 'screens' => array( State::STATE_ONBOARDED, From 1f3bc015266a96cc0de19d7b7304ecc124f2db47 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Fri, 10 May 2024 02:07:51 +0200 Subject: [PATCH 48/60] Add the checkout detection notice to the AXO gateway settings --- modules/ppcp-axo/extensions.php | 14 +++++++ modules/ppcp-axo/services.php | 28 +++++++++++++ .../ppcp-wc-gateway/resources/css/common.scss | 30 +++++++++++++ .../src/Helper/CartCheckoutDetector.php | 42 ++++++++++--------- .../src/Settings/SettingsRenderer.php | 25 +++++++++++ .../ppcp-wc-gateway/src/WCGatewayModule.php | 1 + 6 files changed, 120 insertions(+), 20 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index e81176244..09b590fd7 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Axo; +use WooCommerce\PayPalCommerce\Axo\Helper\NoticeRenderer; use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; @@ -82,6 +83,7 @@ return array( ->rule() ->condition_element( 'axo_enabled', '1' ) ->action_visible( 'axo_gateway_title' ) + ->action_visible( 'axo_checkout_config_notice' ) ->action_visible( 'axo_privacy' ) ->action_visible( 'axo_name_on_card' ) ->action_visible( 'axo_style_heading' ) @@ -112,6 +114,18 @@ return array( ), 'classes' => array( 'ppcp-valign-label-middle', 'ppcp-align-label-center' ), ), + 'axo_checkout_config_notice' => array( + 'heading' => '', + 'html' => $container->get( 'axo.checkout-config-notice' ), + 'type' => 'ppcp-html', + 'classes' => array( 'ppcp-field-indent' ), + 'class' => array(), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'dcc', 'axo' ), + 'gateway' => array( 'dcc', 'axo' ), + ), 'axo_gateway_title' => array( 'title' => __( 'Gateway Title', 'woocommerce-paypal-payments' ), 'type' => 'text', diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php index 780f59a8a..980f5bbbd 100644 --- a/modules/ppcp-axo/services.php +++ b/modules/ppcp-axo/services.php @@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager; use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\Axo\Helper\ApmApplies; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector; return array( @@ -145,4 +146,31 @@ return array( ); }, + 'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string { + $checkout_page_link = get_edit_post_link( wc_get_page_id( 'checkout' ) ); + + if ( CartCheckoutDetector::has_elementor_checkout() ) { + $notice_content = sprintf( + /* translators: %1$s: URL to the Checkout edit page. */ + __( + 'Important: Your store has a Checkout page with the Elementor Checkout widget configured. Fastlane requires your current Checkout page to include a Classic Checkout or [woocommerce_checkout] shortcode to accelerate the payment process.', + 'woocommerce-paypal-payments' + ), + esc_url( $checkout_page_link ) + ); + } elseif ( CartCheckoutDetector::has_block_checkout() ) { + $notice_content = sprintf( + /* translators: %1$s: URL to the Checkout edit page. */ + __( + 'Important: Your store has a Checkout page with the WooCommerce Checkout block configured. Fastlane requires your current Checkout page to include a Classic Checkout or [woocommerce_checkout] shortcode to accelerate the payment process.', + 'woocommerce-paypal-payments' + ), + esc_url( $checkout_page_link ) + ); + } else { + return ''; + } + + return '

' . $notice_content . '

'; + }, ); diff --git a/modules/ppcp-wc-gateway/resources/css/common.scss b/modules/ppcp-wc-gateway/resources/css/common.scss index 1d074ee34..1dc7ecbd4 100644 --- a/modules/ppcp-wc-gateway/resources/css/common.scss +++ b/modules/ppcp-wc-gateway/resources/css/common.scss @@ -56,6 +56,24 @@ $background-ident-color: #fbfbfb; } } +.ppcp-notice { + background: #fff; + border: 1px solid #c3c4c7; + border-left-width: 4px; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); + margin: 5px 15px 2px; + padding: 1px 12px; +} + +.ppcp-notice-warning { + border-left-color: #dba617; + + .highlight { + background: transparent; + color: #dba617; + } +} + // Box indented fields. @media screen and (min-width: 800px) { .ppcp-settings-field { @@ -77,6 +95,18 @@ $background-ident-color: #fbfbfb; th, &.ppcp-settings-field-heading td { padding-left: 40px; + padding-right: 40px; + } + + .ppcp-notice { + margin-left: 40px; + margin-right: 10px; + padding: 1px 12px; + + p { + margin: .5em 0; + padding: 2px; + } } th, td { diff --git a/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php b/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php index c9826bfe3..9f3bc8313 100644 --- a/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php +++ b/modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php @@ -17,28 +17,30 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; class CartCheckoutDetector { /** - * Returns Elementor widgets if they exist (for a specific page). - * @param $page_id - * @return array + * Returns a list of Elementor widgets if they exist for a specific page. + * + * @param int $page_id The ID of the page. + * + * @return array List of widget types if any exist, otherwise an empty array. */ - private function get_elementor_widgets( $page_id ): array { + private static function get_elementor_widgets( $page_id ): array { $elementor_data = get_post_meta( $page_id, '_elementor_data' ); - if ( isset($elementor_data[0] ) ) { - // parse elementor json and found all widgets in json for specific page - $reg_exp = '/"widgetType":"([^"]*)/i'; + if ( isset( $elementor_data[0] ) ) { + // Parse the Elementor json and find all widgets for a specific page. + $reg_exp = '/"widgetType":"([^"]*)/i'; $output_array = array(); if ( is_array( $elementor_data[0] ) ) { - $elementor_data[0] = json_encode( $elementor_data[0] ); + $elementor_data[0] = wp_json_encode( $elementor_data[0] ); } preg_match_all( $reg_exp, $elementor_data[0], $output_array, PREG_SET_ORDER ); $widgets_list = array(); - foreach( $output_array as $found ) { - if ( !isset( $found[1] ) ) { + foreach ( $output_array as $found ) { + if ( ! isset( $found[1] ) ) { continue; } @@ -57,11 +59,11 @@ class CartCheckoutDetector { * * @return bool */ - public function has_elementor_checkout(): bool { - $elementor_widgets = $this->get_elementor_widgets( wc_get_page_id( 'checkout' ) ); + public static function has_elementor_checkout(): bool { + $elementor_widgets = self::get_elementor_widgets( wc_get_page_id( 'checkout' ) ); if ( $elementor_widgets ) { - return in_array( 'woocommerce-checkout-page', $elementor_widgets); + return in_array( 'woocommerce-checkout-page', $elementor_widgets, true ); } return false; @@ -72,11 +74,11 @@ class CartCheckoutDetector { * * @return bool */ - public function has_elementor_cart(): bool { - $elementor_widgets = $this->get_elementor_widgets( wc_get_page_id( 'cart' ) ); + public static function has_elementor_cart(): bool { + $elementor_widgets = self::get_elementor_widgets( wc_get_page_id( 'cart' ) ); if ( $elementor_widgets ) { - return in_array( 'woocommerce-cart-page', $elementor_widgets); + return in_array( 'woocommerce-cart-page', $elementor_widgets, true ); } return false; @@ -87,7 +89,7 @@ class CartCheckoutDetector { * * @return bool */ - public function has_block_checkout(): bool { + public static function has_block_checkout(): bool { $checkout_page_id = wc_get_page_id( 'checkout' ); return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id ); } @@ -97,7 +99,7 @@ class CartCheckoutDetector { * * @return bool */ - public function has_block_cart(): bool { + public static function has_block_cart(): bool { $cart_page_id = wc_get_page_id( 'cart' ); return $cart_page_id && has_block( 'woocommerce/cart', $cart_page_id ); } @@ -107,7 +109,7 @@ class CartCheckoutDetector { * * @return bool */ - public function has_classic_checkout(): bool { + public static function has_classic_checkout(): bool { $checkout_page_id = wc_get_page_id( 'checkout' ); return $checkout_page_id && has_block( 'woocommerce/classic-shortcode', $checkout_page_id ); } @@ -117,7 +119,7 @@ class CartCheckoutDetector { * * @return bool */ - public function has_classic_cart(): bool { + public static function has_classic_cart(): bool { $cart_page_id = wc_get_page_id( 'cart' ); return $cart_page_id && has_block( 'woocommerce/classic-shortcode', $cart_page_id ); } diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index 03ef59ca6..46216b548 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -268,6 +268,31 @@ class SettingsRenderer { return $html; } + /** + * Renders the html field. + * + * @param string $field The current field HTML. + * @param string $key The current key. + * @param array $config The configuration array. + * @param string $value The current value. + * + * @return string + */ + public function render_html( $field, $key, $config, $value ): string { + + if ( 'ppcp-html' !== $config['type'] ) { + return $field; + } + + $html = sprintf( + '
%s
', + esc_attr( implode( ' ', $config['classes'] ) ), + $config['html'] + ); + + return $html; + } + /** * Renders the table row. * diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 8e765a8e9..19f67ef53 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -627,6 +627,7 @@ class WCGatewayModule implements ModuleInterface { $field = $renderer->render_password( $field, $key, $args, $value ); $field = $renderer->render_heading( $field, $key, $args, $value ); $field = $renderer->render_table( $field, $key, $args, $value ); + $field = $renderer->render_html( $field, $key, $args, $value ); return $field; }, 10, From fccde705d167c666956e40dea05b2dbcfa5fccfb Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Fri, 10 May 2024 10:51:19 +0200 Subject: [PATCH 49/60] AXO: Update icons for the Ryan flow --- modules/ppcp-axo/resources/js/Views/CardView.js | 9 ++++++--- modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg | 8 +++++++- .../assets/images/axo/dinersclub-light.svg | 2 +- .../ppcp-wc-gateway/assets/images/axo/discover-light.svg | 2 +- modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg | 2 +- .../assets/images/axo/mastercard-light.svg | 2 +- .../ppcp-wc-gateway/assets/images/axo/unionpay-light.svg | 2 +- modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg | 2 +- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-axo/resources/js/Views/CardView.js b/modules/ppcp-axo/resources/js/Views/CardView.js index 1dd268612..9d8f4caf8 100644 --- a/modules/ppcp-axo/resources/js/Views/CardView.js +++ b/modules/ppcp-axo/resources/js/Views/CardView.js @@ -32,10 +32,13 @@ class CardView { const expiry = data.value('expiry').split('-'); const cardIcons = { - 'VISA': 'visa-dark.svg', - 'MASTER_CARD': 'mastercard-dark.svg', + 'VISA': 'visa-light.svg', + 'MASTER_CARD': 'mastercard-light.svg', 'AMEX': 'amex.svg', 'DISCOVER': 'discover.svg', + 'DINERS': 'dinersclub-light.svg', + 'JCB': 'jcb-light.svg', + 'UNIONPAY': 'unionpay-light.svg', }; return ` @@ -49,7 +52,7 @@ class CardView { ${data.value('brand')}
diff --git a/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg index 1228978ca..495d3409f 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/amex-light.svg @@ -1 +1,7 @@ - \ No newline at end of file + + + + + + + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg index 5da52df9e..5f226276f 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/dinersclub-light.svg @@ -1,4 +1,4 @@ - + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg index 3491abe6d..41995f760 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/discover-light.svg @@ -1,4 +1,4 @@ - + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg index 7507d8df1..c0bc1719a 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/jcb-light.svg @@ -1,4 +1,4 @@ - + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg index 401f705d4..0f3cb2bd4 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/mastercard-light.svg @@ -1,4 +1,4 @@ - + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg index 5fe47e295..e13bd06fc 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/unionpay-light.svg @@ -1,4 +1,4 @@ - + diff --git a/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg b/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg index 4dffb2c48..21afc5ef4 100644 --- a/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg +++ b/modules/ppcp-wc-gateway/assets/images/axo/visa-light.svg @@ -1,4 +1,4 @@ - + From 9b89a7b9f81a5693c03120d70f420c5ffc042cc5 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 13 May 2024 11:04:28 +0200 Subject: [PATCH 50/60] AXO: Make AXO the default payment method for guest customers (3088) --- modules/ppcp-axo/src/AxoModule.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 2b34892fb..104e47b98 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager; +use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; @@ -198,6 +199,16 @@ class AxoModule implements ModuleInterface { 2 ); + // Set Axo as the default payment method on checkout for guest customers. + add_action( + 'template_redirect', + function () { + if ( ! is_user_logged_in() && is_checkout() && ! is_wc_endpoint_url() ) { + WC()->session->set( 'chosen_payment_method', AxoGateway::ID ); + } + } + ); + }, 1 ); From 652cce9d6d1a0f3088925fbce607c4ffd04e5163 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 13 May 2024 11:50:59 +0200 Subject: [PATCH 51/60] AXO: Chnage Fastlane descriptions to communicate better that when enabled Fastlane is the default payment method for guests --- modules/ppcp-axo/extensions.php | 2 +- modules/ppcp-axo/src/Gateway/AxoGateway.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index e81176244..df1c21529 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -69,7 +69,7 @@ return array( 'type' => 'checkbox', 'label' => __( 'Enable Fastlane by PayPal', 'woocommerce-paypal-payments' ) . '

' - . __( 'Help accelerate checkout for guests with PayPal\'s autofill solution.', 'woocommerce-paypal-payments' ) + . __( 'Help accelerate the checkout process for guests with PayPal\'s autofill solution. When enabled, Fastlane is presented as the default payment method for guests.', 'woocommerce-paypal-payments' ) . '

', 'default' => 'yes', 'screens' => array( State::STATE_ONBOARDED ), diff --git a/modules/ppcp-axo/src/Gateway/AxoGateway.php b/modules/ppcp-axo/src/Gateway/AxoGateway.php index 9fa8152ff..30f3a355a 100644 --- a/modules/ppcp-axo/src/Gateway/AxoGateway.php +++ b/modules/ppcp-axo/src/Gateway/AxoGateway.php @@ -159,7 +159,7 @@ class AxoGateway extends WC_Payment_Gateway { $this->card_icons_axo = $card_icons_axo; $this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' ); - $this->method_description = __( 'PayPal Fastlane offers an accelerated checkout experience that recognizes guest shoppers and autofills their details so they can pay in seconds.', 'woocommerce-paypal-payments' ); + $this->method_description = __( 'Fastlane accelerates the checkout experience for guest shoppers and autofills their details so they can pay in seconds. When enabled, Fastlane is presented as the default payment method for guests.', 'woocommerce-paypal-payments' ); $is_axo_enabled = $this->ppcp_settings->has( 'axo_enabled' ) && $this->ppcp_settings->get( 'axo_enabled' ); $this->update_option( 'enabled', $is_axo_enabled ? 'yes' : 'no' ); From c3dbf42db85e581a07ea78d58e64b1813418d568 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 13 May 2024 11:56:24 +0200 Subject: [PATCH 52/60] Bump 2.7.1-rc1 version --- changelog.txt | 7 +++++++ package.json | 2 +- readme.txt | 9 ++++++++- woocommerce-paypal-payments.php | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index bcba15236..2332be339 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,12 @@ *** Changelog *** += 2.7.1 - xxxx-xx-xx = +* Fix - Ensure package tracking data is sent to original PayPal transaction #2180 +* Fix - Set the 'Woo_PPCP' as a default value for data-partner-attribution-id #2188 +* Fix - Allow PUI Gateway for refund processor #2192 +* Fix - Notice on newly created block cart checkout #2211 +* Fix - Apple Pay button in the editor #2177 + = 2.7.0 - 2024-04-30 = * Fix - Zero sum subscriptions cause CANNOT_BE_ZERO_OR_NEGATIVE when using Vault v3 #2152 * Fix - Incorrect Pricing Issue with Variable Subscriptions in PayPal Subscriptions Mode #2156 diff --git a/package.json b/package.json index 6476f3d1b..bf52a8677 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woocommerce-paypal-payments", - "version": "2.7.0", + "version": "2.7.1", "description": "WooCommerce PayPal Payments", "repository": "https://github.com/woocommerce/woocommerce-paypal-payments", "license": "GPL-2.0", diff --git a/readme.txt b/readme.txt index a234e9d34..42840c062 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, checkout, cart, pay later, apple Requires at least: 5.3 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 2.7.0 +Stable tag: 2.7.1 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -179,6 +179,13 @@ If you encounter issues with the PayPal buttons not appearing after an update, p == Changelog == += 2.7.1 - xxxx-xx-xx = +* Fix - Ensure package tracking data is sent to original PayPal transaction #2180 +* Fix - Set the 'Woo_PPCP' as a default value for data-partner-attribution-id #2188 +* Fix - Allow PUI Gateway for refund processor #2192 +* Fix - Notice on newly created block cart checkout #2211 +* Fix - Apple Pay button in the editor #2177 + = 2.7.0 - 2024-04-30 = * Fix - Zero sum subscriptions cause CANNOT_BE_ZERO_OR_NEGATIVE when using Vault v3 #2152 * Fix - Incorrect Pricing Issue with Variable Subscriptions in PayPal Subscriptions Mode #2156 diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index e193c42f0..ce5883709 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce PayPal Payments * Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/ * Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage. - * Version: 2.7.0 + * Version: 2.7.1 * Author: WooCommerce * Author URI: https://woocommerce.com/ * License: GPL-2.0 @@ -26,7 +26,7 @@ define( 'PAYPAL_API_URL', 'https://api-m.paypal.com' ); define( 'PAYPAL_URL', 'https://www.paypal.com' ); define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' ); define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' ); -define( 'PAYPAL_INTEGRATION_DATE', '2024-04-22' ); +define( 'PAYPAL_INTEGRATION_DATE', '2024-05-13' ); ! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' ); ! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' ); From f9066b15aedaea3a4b74030b2d09e5d5605de978 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 13 May 2024 16:23:16 +0200 Subject: [PATCH 53/60] Refine the condition for setting Fastlane as default --- modules/ppcp-axo/src/AxoModule.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 104e47b98..779968328 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -23,6 +23,7 @@ use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; +use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector; /** * Class AxoModule @@ -202,8 +203,11 @@ class AxoModule implements ModuleInterface { // Set Axo as the default payment method on checkout for guest customers. add_action( 'template_redirect', - function () { - if ( ! is_user_logged_in() && is_checkout() && ! is_wc_endpoint_url() ) { + function () use ( $c ) { + $settings = $c->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + if ( $this->should_render_fastlane( $settings ) ) { WC()->session->set( 'chosen_payment_method', AxoGateway::ID ); } } @@ -270,11 +274,22 @@ class AxoModule implements ModuleInterface { * @return bool */ private function hide_credit_card_when_using_fastlane( array $methods, Settings $settings ): bool { + return $this->should_render_fastlane( $settings ) && isset( $methods[ CreditCardGateway::ID ] ); + } + + /** + * Condition to evaluate if Fastlane should be rendered. + * + * Fastlane should only render on the classic checkout, when Fastlane is enabled in the settings and also only for guest customers. + * + * @param Settings $settings The settings. + * @return bool + */ + private function should_render_fastlane( Settings $settings): bool { $is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false; - return ! is_admin() - && is_user_logged_in() === false - && isset( $methods[ CreditCardGateway::ID ] ) + return ! is_user_logged_in() + && CartCheckoutDetector::has_classic_checkout() && $is_axo_enabled; } } From a8e8643d3dcaee8e2f4a957fade9d3599168b319 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 13 May 2024 16:23:17 +0200 Subject: [PATCH 54/60] Re-enable name on card --- modules/ppcp-axo/extensions.php | 2 +- modules/ppcp-axo/resources/js/AxoManager.js | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-axo/extensions.php b/modules/ppcp-axo/extensions.php index e81176244..b728d826d 100644 --- a/modules/ppcp-axo/extensions.php +++ b/modules/ppcp-axo/extensions.php @@ -161,7 +161,7 @@ return array( 'class' => array(), 'label' => __( 'Enable this to display the "Name on Card" field for new Fastlane buyers.', 'woocommerce-paypal-payments' ), 'screens' => array( State::STATE_ONBOARDED ), - 'gateway' => array(), + 'gateway' => array( 'dcc', 'axo' ), 'requirements' => array( 'axo' ), ), 'axo_style_heading' => array( diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 3b0555787..ce6c3e573 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -702,14 +702,12 @@ class AxoManager { } cardComponentData() { - const fields = { - cardholderName: { - enabled: true - } - }; - return { - fields: fields, + fields: { + cardholderName: { + enabled: this.axoConfig.name_on_card === '1' + } + }, styles: this.deleteKeysWithEmptyString(this.axoConfig.style_options) } } From 5b5654d371150eb76209f86ed374d7fc29a028d6 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 13 May 2024 16:32:10 +0200 Subject: [PATCH 55/60] Rename .hidden class to avoid overrides from external code --- modules/ppcp-axo/resources/css/styles.scss | 2 +- modules/ppcp-axo/resources/js/AxoManager.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-axo/resources/css/styles.scss b/modules/ppcp-axo/resources/css/styles.scss index 196b2086c..605ac18b2 100644 --- a/modules/ppcp-axo/resources/css/styles.scss +++ b/modules/ppcp-axo/resources/css/styles.scss @@ -7,7 +7,7 @@ padding: 1rem 0; background-color: #ffffff; - &.hidden { + &.axo-hidden { display: none; } } diff --git a/modules/ppcp-axo/resources/js/AxoManager.js b/modules/ppcp-axo/resources/js/AxoManager.js index 3b0555787..cc4082863 100644 --- a/modules/ppcp-axo/resources/js/AxoManager.js +++ b/modules/ppcp-axo/resources/js/AxoManager.js @@ -437,7 +437,7 @@ class AxoManager { if (!document.querySelector(pc.selector)) { const gatewayPaymentContainer = document.querySelector('.payment_method_ppcp-axo-gateway'); gatewayPaymentContainer.insertAdjacentHTML('beforeend', ` - diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php index d3dff074b..2ed5fc04c 100644 --- a/modules/ppcp-axo/src/Assets/AxoManager.php +++ b/modules/ppcp-axo/src/Assets/AxoManager.php @@ -197,6 +197,7 @@ class AxoManager { 'CA' => WC()->countries->get_states( 'CA' ), ), ), + 'module_url' => untrailingslashit( $this->module_url ), ); }