Skip to content

Commit 5a9bfd7

Browse files
Merge pull request #729 from godaddy-wordpress/MWC-3539/add-google-merchant-id
Add Google Merchant ID field
2 parents b694c1f + e74e7e2 commit 5a9bfd7

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

woocommerce/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** SkyVerge WooCommerce Plugin Framework Changelog ***
22

33
2025.nn.nn - version 5.15.3
4+
* Fix - Add Merchant ID to Google Pay, distinguishing it from Gateway merchant ID
45

56
2024.11.25 - version 5.15.2
67
* Fix - Prevent "Capture Charge" bulk action from loading on non-order pages

woocommerce/payment-gateway/External_Checkout/Google_Pay/Admin.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function get_settings() {
9797
'default' => 'no',
9898
],
9999

100+
[
101+
'id' => 'sv_wc_google_pay_merchant_id',
102+
'title' => __( 'Merchant ID', 'woocommerce-plugin-framework' ),
103+
/** translators: Placeholders: %1$s - <a href="..."> tag, %2$s - </a> tag */
104+
'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' ), '<a href="https://pay.google.com/business/console" target="_blank">', '</a>' ),
105+
'type' => 'text',
106+
],
107+
100108
[
101109
'id' => 'sv_wc_google_pay_display_locations',
102110
/* translators: Allow Google Pay button on selected display locations (e.g. cart, checkout, product page...) */

woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ protected function get_js_handler_args() {
125125
return (array) apply_filters( 'wc_' . $this->get_gateway()->get_id() . '_google_pay_js_handler_params', [
126126
'plugin_id' => $this->get_gateway()->get_plugin()->get_id(),
127127
'merchant_id' => $this->get_handler()->get_merchant_id(),
128-
'merchant_name' => get_bloginfo( 'name' ),
128+
'merchant_name' => $this->get_handler()->get_merchant_name(),
129129
'gateway_id' => $this->get_gateway()->get_id(),
130130
'gateway_id_dasherized' => $this->get_gateway()->get_id_dasherized(),
131+
'gateway_merchant_id' => $this->get_handler()->get_gateway_merchant_id(),
131132
'environment' => $this->get_gateway()->get_environment() == 'production' ? 'PRODUCTION' : 'TEST',
132133
'ajax_url' => admin_url( 'admin-ajax.php' ),
133134
'recalculate_totals_nonce' => wp_create_nonce( 'wc_' . $this->get_gateway()->get_id() . '_google_pay_recalculate_totals' ),

woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,18 +702,58 @@ public function get_supported_networks() {
702702
}
703703

704704

705+
/**
706+
* Gets the Google Pay merchant ID.
707+
*
708+
* @since 5.10.0
709+
*
710+
* @see https://developers.google.com/pay/api/web/reference/request-objects#MerchantInfo
711+
*
712+
* @return string
713+
*/
714+
public function get_merchant_id() : string {
715+
716+
return get_option( "sv_wc_{$this->id}_merchant_id" ) ?? '';
717+
}
718+
705719
/**
706720
* Gets the gateway merchant ID.
707721
*
722+
* This is different from the Google Pay Merchant ID.
708723
* Each plugin can override this method to get the merchant ID from their own setting.
709724
*
710-
* @since 5.10.0
725+
* @see https://developers.google.com/pay/api/web/guides/tutorial#tokenization
726+
*
727+
* @since 5.15.3
728+
*
729+
* @return string
730+
*/
731+
public function get_gateway_merchant_id() : string {
732+
733+
$gateway = $this->get_processing_gateway();
734+
735+
return method_exists( $gateway, 'get_merchant_id' ) ? $gateway->get_merchant_id() : '';
736+
}
737+
738+
/**
739+
* Gets the merchant name.
740+
*
741+
* Defaults to the blog name.
742+
*
743+
* @since 5.15.3
711744
*
712745
* @return string
713746
*/
714-
public function get_merchant_id() {
747+
public function get_merchant_name() :string {
715748

716-
return method_exists( $this->get_processing_gateway(), 'get_merchant_id' ) ? $this->get_processing_gateway()->get_merchant_id() : '';
749+
/**
750+
* Filters the Google Pay merchant name.
751+
*
752+
* @since 5.15.3
753+
*
754+
* @param string $name the merchant name (defaults to blog name)
755+
*/
756+
return apply_filters( 'sv_wc_google_pay_merchant_name', get_bloginfo( 'name' ) );
717757
}
718758

719759

woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jQuery( function( $ ) {
2222
* @param {string} params.merchant_name The site name
2323
* @param {string} params.gateway_id The gateway ID
2424
* @param {string} params.gateway_id_dasherized The gateway ID dasherized
25+
* @param {string} params.gateway_merchant_id The gateway merchant ID
2526
* @param {string} params.environment The gateway environment (PRODUCTION or TEST)
2627
* @param {string} params.ajax_url The AJAX URL
2728
* @param {string} params.recalculate_totals_nonce Nonce for the recalculate_totals AJAX action
@@ -42,6 +43,7 @@ jQuery( function( $ ) {
4243
merchant_name,
4344
gateway_id,
4445
gateway_id_dasherized,
46+
gateway_merchant_id,
4547
environment,
4648
ajax_url,
4749
recalculate_totals_nonce,
@@ -55,6 +57,7 @@ jQuery( function( $ ) {
5557
} = params;
5658

5759
this.gatewayID = gateway_id;
60+
this.gatewayMerchantID = gateway_merchant_id;
5861
this.merchantID = merchant_id;
5962
this.merchantName = merchant_name;
6063
this.environment = environment;
@@ -109,7 +112,7 @@ jQuery( function( $ ) {
109112
type: 'PAYMENT_GATEWAY',
110113
parameters: {
111114
'gateway': plugin_id,
112-
'gatewayMerchantId': this.merchantID
115+
'gatewayMerchantId': this.gatewayMerchantID
113116
}
114117
};
115118

0 commit comments

Comments
 (0)