Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] Google Pay #3655

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.1.0 - xxxx-xx-xx =
* Add - Includes Google Pay as a new wallet payment method.
* Fix - Fix ECE crash in classic cart and checkout pages for non-English language sites.
* Fix - Correctly handles UK postcodes redacted by Apple Pay.
* Tweak - Avoid re-sending Processing Order customer email when merchant wins dispute.
Expand Down
10 changes: 8 additions & 2 deletions client/blocks/upe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PAYMENT_METHOD_CLEARPAY,
PAYMENT_METHOD_GIROPAY,
PAYMENT_METHOD_LINK,
PAYMENT_METHOD_GOOGLE_PAY,
} from '../../stripe-utils/constants';
import Icons from '../../payment-method-icons';
import { getDeferredIntentCreationUPEFields } from './upe-deferred-intent-creation/payment-elements.js';
Expand Down Expand Up @@ -42,8 +43,13 @@ const upeMethods = getPaymentMethodsConstants();
const paymentMethodsConfig =
getBlocksConfiguration()?.paymentMethodsConfig ?? {};
Object.entries( paymentMethodsConfig )
.filter( ( [ upeName ] ) => upeName !== PAYMENT_METHOD_LINK )
.filter( ( [ upeName ] ) => upeName !== PAYMENT_METHOD_GIROPAY ) // Skip giropay as it was deprecated by Jun, 30th 2024.
.filter( ( [ upeName ] ) => {
return ! [
PAYMENT_METHOD_LINK,
PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024.
PAYMENT_METHOD_GOOGLE_PAY, // Remove Google Pay since it does not need to be passed to Stripe settings.
].includes( upeName );
} )
.forEach( ( [ upeName, upeConfig ] ) => {
let iconName = upeName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { PAYMENT_METHOD_CASHAPP } from 'wcstripe/stripe-utils/constants';
* @return {Object} The Stripe element options.
*/
const getStripeElementOptions = () => {
const paymentMethodsConfig = getBlocksConfiguration()?.paymentMethodsConfig;
let options = {
fields: {
billingDetails: {
Expand All @@ -47,7 +48,7 @@ const getStripeElementOptions = () => {
},
wallets: {
applePay: 'never',
googlePay: 'never',
googlePay: paymentMethodsConfig?.google_pay ? 'auto' : 'never',
},
};

Expand Down
2 changes: 1 addition & 1 deletion client/classic/upe/deferred-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jQuery( function ( $ ) {
}
}

// On every page load and on hash change, check to see whether we should display the Voucher (Boleto/Oxxo/Multibanco) or Wallet (CashApp/WeChat Pay) modal.
// On every page load and on hash change, check to see whether we should display the Voucher (Boleto/Oxxo/Multibanco) or Wallet (Google Pay/CashApp/WeChat Pay) modal.
// Every page load is needed for the Pay for Order page which doesn't trigger the hash change.
maybeConfirmVoucherOrWalletPayment();
$( window ).on( 'hashchange', () => {
Expand Down
2 changes: 1 addition & 1 deletion client/classic/upe/payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function createStripePaymentElement( api, paymentMethodType = null ) {
...getDefaultValues(),
wallets: {
applePay: 'never',
googlePay: 'never',
googlePay: paymentMethodsConfig?.google_pay ? 'auto' : 'never',
},
} );

Expand Down
2 changes: 2 additions & 0 deletions client/payment-method-icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import BoletoIcon from './boleto';
import OxxoIcon from './oxxo';
import WechatPayIcon from './wechat-pay';
import CashAppIcon from './cashapp';
import GooglePayIcon from './google-pay';

export default {
alipay: AlipayIcon,
Expand All @@ -36,4 +37,5 @@ export default {
oxxo: OxxoIcon,
wechat_pay: WechatPayIcon,
cashapp: CashAppIcon,
google_pay: GooglePayIcon,
};
145 changes: 145 additions & 0 deletions client/payment-methods-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,151 @@ export default {
Icon: icons.bancontact,
currencies: [ 'EUR' ],
},
google_pay: {
id: 'google_pay',
label: __( 'Google Pay', 'woocommerce-gateway-stripe' ),
description: __(
'Google Pay allows customers to make payments in your app or website using any credit or debit card saved to their Google Account.',
'woocommerce-gateway-stripe'
),
Icon: icons.google_pay,
currencies: [
'USD',
'AED',
'AFN',
'ALL',
'AMD',
'ANG',
'AOA',
'ARS',
'AUD',
'AWG',
'AZN',
'BAM',
'BBD',
'BDT',
'BGN',
'BIF',
'BMD',
'BND',
'BOB',
'BRL',
'BSD',
'BWP',
'BYN',
'BZD',
'CAD',
'CDF',
'CHF',
'CLP',
'CNY',
'COP',
'CRC',
'CVE',
'CZK',
'DJF',
'DKK',
'DOP',
'DZD',
'EGP',
'ETB',
'EUR',
'FJD',
'FKP',
'GBP',
'GEL',
'GIP',
'GMD',
'GNF',
'GTQ',
'GYD',
'HKD',
'HNL',
'HTG',
'HUF',
'IDR',
'ILS',
'INR',
'ISK',
'JMD',
'JPY',
'KES',
'KGS',
'KHR',
'KMF',
'KRW',
'KYD',
'KZT',
'LAK',
'LBP',
'LKR',
'LRD',
'LSL',
'MAD',
'MDL',
'MGA',
'MKD',
'MMK',
'MNT',
'MOP',
'MUR',
'MVR',
'MWK',
'MXN',
'MYR',
'MZN',
'NAD',
'NGN',
'NIO',
'NOK',
'NPR',
'NZD',
'PAB',
'PEN',
'PGK',
'PHP',
'PKR',
'PLN',
'PYG',
'QAR',
'RON',
'RSD',
'RUB',
'RWF',
'SAR',
'SBD',
'SCR',
'SEK',
'SGD',
'SHP',
'SLL',
'SOS',
'SRD',
'STD',
'SZL',
'THB',
'TJS',
'TOP',
'TRY',
'TTD',
'TWD',
'TZS',
'UAH',
'UGX',
'UYU',
'UZS',
'VND',
'VUV',
'WST',
'XAF',
'XCD',
'XOF',
'XPF',
'YER',
'ZAR',
'ZMW',
],
},
ideal: {
id: 'ideal',
label: __( 'iDEAL', 'woocommerce-gateway-stripe' ),
Expand Down
1 change: 1 addition & 0 deletions includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public function payment_icons() {
WC_Stripe_Payment_Methods::OXXO => '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/oxxo.svg" class="stripe-oxxo-icon stripe-icon" alt="OXXO" />',
'cards' => '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards.svg" class="stripe-cards-icon stripe-icon" alt="credit / debit card" />',
WC_Stripe_Payment_Methods::CASHAPP_PAY => '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cashapp.svg" class="stripe-cashapp-icon stripe-icon" alt="Cash App Pay" />',
WC_Stripe_Payment_Methods::GOOGLE_PAY => '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/google-pay.svg" class="stripe-google-pay-icon stripe-icon" alt="Google Pay" />',
]
);
}
Expand Down
7 changes: 7 additions & 0 deletions includes/constants/class-wc-stripe-currency-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WC_Stripe_Currency_Code {
const COLOMBIAN_PESO = 'COP'; // Colombian peso.
const COSTA_RICAN_COLON = 'CRC'; // Costa Rican colon.
const CAPE_VERDE_ESCUDO = 'CVE'; // Cape Verde escudo.
const CROATIAN_KUNA = 'HRK'; // Croatian kuna.
const CZECH_KORUNA = 'CZK'; // Czech koruna.
const DJIBOUTIAN_FRANC = 'DJF'; // Djiboutian franc.
const DANISH_KRONE = 'DKK'; // Danish krone.
Expand Down Expand Up @@ -72,6 +73,7 @@ class WC_Stripe_Currency_Code {
const JORDANIAN_DINAR = 'JOD'; // Jordanian dinar.
const JAPANESE_YEN = 'JPY'; // Japanese yen.
const KENYAN_SHILLING = 'KES'; // Kenyan shilling.
const KUWAITI_DINAR = 'KWD'; // Kuwaiti dinar.
const KYRGYZSTANI_SOM = 'KGS'; // Kyrgyzstani som.
const CAMBODIAN_RIEL = 'KHR'; // Cambodian riel.
const COMORIAN_FRANC = 'KMF'; // Comorian franc.
Expand All @@ -82,6 +84,7 @@ class WC_Stripe_Currency_Code {
const LEBANESE_POUND = 'LBP'; // Lebanese pound.
const SRI_LANKAN_RUPEE = 'LKR'; // Sri Lankan rupee.
const LIBERIAN_DOLLAR = 'LRD'; // Liberian dollar.
const LIBYAN_DINAR = 'LYD'; // Libyan dinar.
const LESOTHO_LOTI = 'LSL'; // Lesotho loti.
const MOROCCAN_DIRHAM = 'MAD'; // Moroccan dirham.
const MOLDOVAN_LEU = 'MDL'; // Moldovan leu.
Expand All @@ -102,6 +105,7 @@ class WC_Stripe_Currency_Code {
const NORWEGIAN_KRONE = 'NOK'; // Norwegian krone.
const NEPALESE_RUPEE = 'NPR'; // Nepalese rupee.
const NEW_ZEALAND_DOLLAR = 'NZD'; // New Zealand dollar.
const OMANI_RIAL = 'OMR'; // Omani rial.
const PANAMANIAN_BALBOA = 'PAB'; // Panamanian balboa.
const PERUVIAN_SOL = 'PEN'; // Peruvian sol.
const PAPUA_NEW_GUINEAN_KINA = 'PGK'; // Papua New Guinean kina.
Expand All @@ -128,14 +132,17 @@ class WC_Stripe_Currency_Code {
const THAI_BAHT = 'THB'; // Thai baht.
const TAJIKISTANI_SOMONI = 'TJS'; // Tajikistani somoni.
const TONGAN_PAANGA = 'TOP'; // Tongan paʻanga.
const TUNISIAN_DINAR = 'TND'; // Tunisian dinar.
const TURKISH_LIRA = 'TRY'; // Turkish lira.
const TURKMENISTAN_MANAT = 'TMT'; // Turkmenistan manat.
const TRINIDAD_AND_TOBAGO_DOLLAR = 'TTD'; // Trinidad and Tobago dollar.
const NEW_TAIWAN_DOLLAR = 'TWD'; // New Taiwan dollar.
const TANZANIAN_SHILLING = 'TZS'; // Tanzanian shilling.
const UKRAINIAN_HRYVNIA = 'UAH'; // Ukrainian hryvnia.
const UGANDAN_SHILLING = 'UGX'; // Ugandan shilling.
const URUGUAYAN_PESO = 'UYU'; // Uruguayan peso.
const UZBEKISTANI_SOM = 'UZS'; // Uzbekistani som.
const VENEZUELAN_BOLIVAR = 'VES'; // Venezuelan bolívar.
const VIETNAMESE_DONG = 'VND'; // Vietnamese đồng.
const VANUATU_VATU = 'VUV'; // Vanuatu vatu.
const SAMOAN_TALA = 'WST'; // Samoan tala.
Expand Down
2 changes: 2 additions & 0 deletions includes/constants/class-wc-stripe-payment-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class WC_Stripe_Payment_Methods {
const CASHAPP_PAY = 'cashapp';
const EPS = 'eps';
const GIROPAY = 'giropay';
const GOOGLE_PAY = 'google_pay';
const IDEAL = 'ideal';
const KLARNA = 'klarna';
const LINK = 'link';
Expand Down Expand Up @@ -54,5 +55,6 @@ class WC_Stripe_Payment_Methods {
const WALLET_PAYMENT_METHODS = [
self::CASHAPP_PAY,
self::WECHAT_PAY,
self::GOOGLE_PAY,
];
}
20 changes: 19 additions & 1 deletion includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
WC_Stripe_UPE_Payment_Method_Link::class,
WC_Stripe_UPE_Payment_Method_Wechat_Pay::class,
WC_Stripe_UPE_Payment_Method_Cash_App_Pay::class,
WC_Stripe_UPE_Payment_Method_Google_Pay::class,
];

/**
Expand Down Expand Up @@ -222,6 +223,8 @@ public function __construct() {
add_action( 'wc_ajax_wc_stripe_save_appearance', [ $this, 'save_appearance_ajax' ] );

add_filter( 'woocommerce_saved_payment_methods_list', [ $this, 'filter_saved_payment_methods_list' ], 10, 2 );

add_filter( 'woocommerce_available_payment_gateways', [ $this, 'filter_wallets_from_available_payment_gateways' ], 10, 1 );
}

/**
Expand Down Expand Up @@ -2367,6 +2370,21 @@ public function add_payment_method() {
}
}

/**
* Filters wallets methods that are rendered inside the card element from the list of available payment gateways (such as Google Pay).
*
* @param $gateways array of WC_Stripe_UPE_Payment_Method
* @return array
*/
public function filter_wallets_from_available_payment_gateways( $gateways ) {
foreach ( $gateways as $key => $gateway ) {
if ( $gateway instanceof WC_Stripe_UPE_Payment_Method_Google_Pay ) {
unset( $gateways[ $key ] );
}
}
return $gateways;
}

/**
* Returns a URL to process UPE redirect payments.
*
Expand Down Expand Up @@ -2543,7 +2561,7 @@ private function is_refund_request() {
* Depending on the payment method used to process the payment, we may need to redirect the user to a URL for further processing.
*
* - Voucher payments (Boleto or Oxxo or Multibanco) respond with a hash URL so the client JS code can recognize the response, pull out the necessary args and handle the displaying of the voucher.
* - Wallet payments (CashApp or WeChat) respond with a hash URL so the client JS code can recognize the response, pull out the necessary args and handle the displaying of the modal.
* - Wallet payments (Google pay, CashApp or WeChat) respond with a hash URL so the client JS code can recognize the response, pull out the necessary args and handle the displaying of the modal.
* - Other payment methods like Giropay, iDEAL, Alipay etc require a redirect to a URL provided by Stripe.
* - 3DS Card payments return a hash URL so the client JS code can recognize the response, pull out the necessary PI args and display the 3DS confirmation modal.
*
Expand Down
Loading
Loading