diff --git a/woocommerce/changelog.txt b/woocommerce/changelog.txt index a194b0fd1..40222930d 100644 --- a/woocommerce/changelog.txt +++ b/woocommerce/changelog.txt @@ -1,6 +1,7 @@ *** SkyVerge WooCommerce Plugin Framework Changelog *** 2025.nn.nn - version 5.15.3 +* Fix - Add Merchant ID to Google Pay, distinguishing it from Gateway merchant ID 2024.11.25 - version 5.15.2 * Fix - Prevent "Capture Charge" bulk action from loading on non-order pages diff --git a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Admin.php b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Admin.php index 26c6ee5ba..aee2a350e 100755 --- a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Admin.php +++ b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Admin.php @@ -97,6 +97,14 @@ public function get_settings() { 'default' => 'no', ], + [ + 'id' => 'sv_wc_google_pay_merchant_id', + 'title' => __( 'Merchant ID', 'woocommerce-plugin-framework' ), + /** translators: Placeholders: %1$s - tag, %2$s - tag */ + 'desc' => sprintf( __( 'A Google merchant identifier issued after registration with the %1$sGoogle Pay & Wallet Console%2$s. 12-18 characters. Required in production environment.', 'woocommerce-plugin-framework' ), '', '' ), + 'type' => 'text', + ], + [ 'id' => 'sv_wc_google_pay_display_locations', /* translators: Allow Google Pay button on selected display locations (e.g. cart, checkout, product page...) */ diff --git a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php index 200ffb863..9f3b2b050 100644 --- a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php +++ b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php @@ -125,9 +125,10 @@ protected function get_js_handler_args() { return (array) apply_filters( 'wc_' . $this->get_gateway()->get_id() . '_google_pay_js_handler_params', [ 'plugin_id' => $this->get_gateway()->get_plugin()->get_id(), 'merchant_id' => $this->get_handler()->get_merchant_id(), - 'merchant_name' => get_bloginfo( 'name' ), + 'merchant_name' => $this->get_handler()->get_merchant_name(), 'gateway_id' => $this->get_gateway()->get_id(), 'gateway_id_dasherized' => $this->get_gateway()->get_id_dasherized(), + 'gateway_merchant_id' => $this->get_handler()->get_gateway_merchant_id(), 'environment' => $this->get_gateway()->get_environment() == 'production' ? 'PRODUCTION' : 'TEST', 'ajax_url' => admin_url( 'admin-ajax.php' ), 'recalculate_totals_nonce' => wp_create_nonce( 'wc_' . $this->get_gateway()->get_id() . '_google_pay_recalculate_totals' ), diff --git a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php index e4bd5556c..78faf0807 100755 --- a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php +++ b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php @@ -702,18 +702,58 @@ public function get_supported_networks() { } + /** + * Gets the Google Pay merchant ID. + * + * @since 5.10.0 + * + * @see https://developers.google.com/pay/api/web/reference/request-objects#MerchantInfo + * + * @return string + */ + public function get_merchant_id() : string { + + return get_option( "sv_wc_{$this->id}_merchant_id" ) ?? ''; + } + /** * Gets the gateway merchant ID. * + * This is different from the Google Pay Merchant ID. * Each plugin can override this method to get the merchant ID from their own setting. * - * @since 5.10.0 + * @see https://developers.google.com/pay/api/web/guides/tutorial#tokenization + * + * @since 5.15.3 + * + * @return string + */ + public function get_gateway_merchant_id() : string { + + $gateway = $this->get_processing_gateway(); + + return method_exists( $gateway, 'get_merchant_id' ) ? $gateway->get_merchant_id() : ''; + } + + /** + * Gets the merchant name. + * + * Defaults to the blog name. + * + * @since 5.15.3 * * @return string */ - public function get_merchant_id() { + public function get_merchant_name() :string { - return method_exists( $this->get_processing_gateway(), 'get_merchant_id' ) ? $this->get_processing_gateway()->get_merchant_id() : ''; + /** + * Filters the Google Pay merchant name. + * + * @since 5.15.3 + * + * @param string $name the merchant name (defaults to blog name) + */ + return apply_filters( 'sv_wc_google_pay_merchant_name', get_bloginfo( 'name' ) ); } diff --git a/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js b/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js index b63e1ce22..f8b4a1eb8 100644 --- a/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js +++ b/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js @@ -22,6 +22,7 @@ jQuery( function( $ ) { * @param {string} params.merchant_name The site name * @param {string} params.gateway_id The gateway ID * @param {string} params.gateway_id_dasherized The gateway ID dasherized + * @param {string} params.gateway_merchant_id The gateway merchant ID * @param {string} params.environment The gateway environment (PRODUCTION or TEST) * @param {string} params.ajax_url The AJAX URL * @param {string} params.recalculate_totals_nonce Nonce for the recalculate_totals AJAX action @@ -42,6 +43,7 @@ jQuery( function( $ ) { merchant_name, gateway_id, gateway_id_dasherized, + gateway_merchant_id, environment, ajax_url, recalculate_totals_nonce, @@ -55,6 +57,7 @@ jQuery( function( $ ) { } = params; this.gatewayID = gateway_id; + this.gatewayMerchantID = gateway_merchant_id; this.merchantID = merchant_id; this.merchantName = merchant_name; this.environment = environment; @@ -109,7 +112,7 @@ jQuery( function( $ ) { type: 'PAYMENT_GATEWAY', parameters: { 'gateway': plugin_id, - 'gatewayMerchantId': this.merchantID + 'gatewayMerchantId': this.gatewayMerchantID } };