Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/poc-google-pay-as-payment-method
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

POC: Google Pay as a payment method
3 changes: 3 additions & 0 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import enqueueFraudScripts from 'fraud-scripts';
import {
expressCheckoutElementApplePay,
expressCheckoutElementGooglePay,
paymentMethodGooglePay,
} from 'wcpay/express-checkout/blocks';

import { getDeferredIntentCreationUPEFields } from './payment-elements';
Expand Down Expand Up @@ -111,6 +112,8 @@ const addCheckoutTracking = () => {
}
};

registerPaymentMethod( paymentMethodGooglePay( api ) );

// Call handleWooPayEmailInput if woopay is enabled and this is the checkout page.
if ( getUPEConfig( 'isWooPayEnabled' ) ) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ExpressCheckoutComponent = ( {
expressPaymentMethod = '',
buttonAttributes,
isPreview = false,
eventRegistration,
} ) => {
const {
buttonOptions,
Expand All @@ -96,6 +97,7 @@ const ExpressCheckoutComponent = ( {
onClick,
onClose,
setExpressPaymentError,
eventRegistration,
} );
const onClickHandler = ! isPreview ? onButtonClick : () => {};
const onShippingAddressChange = ( event ) =>
Expand Down
18 changes: 15 additions & 3 deletions client/express-checkout/blocks/hooks/use-express-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
onClick,
onClose,
setExpressPaymentError,
eventRegistration,
} ) => {
const stripe = useStripe();
const elements = useElements();
Expand All @@ -39,7 +40,7 @@

const onCancel = () => {
onCancelHandler();
onClose();
onClose?.();
};

const completePayment = ( redirectUrl ) => {
Expand All @@ -54,13 +55,23 @@

const onButtonClick = useCallback(
( event ) => {
if ( eventRegistration?.onPlaceOrderButtonValidation ) {
const validationResult = eventRegistration.onPlaceOrderButtonValidation();
console.log( '### vr', validationResult );

Check warning on line 60 in client/express-checkout/blocks/hooks/use-express-checkout.js

View workflow job for this annotation

GitHub Actions / JS linting

Unexpected console statement
if ( ! validationResult ) {
return;
}
}

// If login is required for checkout, display redirect confirmation dialog.
if ( getExpressCheckoutData( 'login_confirmation' ) ) {
displayLoginConfirmation( event.expressPaymentType );
return;
}

const shippingAddressRequired = shippingData?.needsShipping;
const shippingAddressRequired = eventRegistration?.onPlaceOrderButtonValidation
? false
: shippingData?.needsShipping;

let shippingRates;
if ( shippingAddressRequired ) {
Expand Down Expand Up @@ -122,7 +133,7 @@
};

// Click event from WC Blocks.
onClick();
onClick?.();
// Global click event handler from WooPayments to ECE.
onClickHandler( event );
event.resolve( options );
Expand All @@ -133,6 +144,7 @@
billing.cartTotal.value,
shippingData.needsShipping,
shippingData.shippingRates,
eventRegistration,
]
);

Expand Down
33 changes: 33 additions & 0 deletions client/express-checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,36 @@ export const expressCheckoutElementGooglePay = ( api ) => ( {
return checkPaymentMethodIsAvailable( 'googlePay', cart, api );
},
} );

const CustomWrapper = ( { children } ) => <div>{ children }</div>;
export const paymentMethodGooglePay = ( api ) => {
return {
name: 'woocommerce_payments_googlePay',
edit: <CustomWrapper />,
content: <CustomWrapper />,
paymentMethodId: 'woocommerce_payments_googlePay',
placeOrderButton: ( props ) => {
return (
<ExpressCheckoutContainer
api={ api }
expressPaymentMethod="googlePay"
{ ...props }
/>
);
},
label: 'Google Pay - WooPayments',
ariaLabel: 'Google Pay - WooPayments',
supports: {
showSavedCards: false,
showSaveOption: false,
features: getConfig( 'features' ),
},
canMakePayment: ( { cart } ) => {
if ( typeof wcpayExpressCheckoutParams === 'undefined' ) {
return false;
}

return checkPaymentMethodIsAvailable( 'googlePay', cart );
},
};
};
43 changes: 43 additions & 0 deletions includes/class-wc-gateway-google-pay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Class WC_Gateway_Google_Pay
*
* Adds Google Pay as a payment gateway.
*
* @package WooCommerce\Payments
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Google Pay Payment Gateway.
*/
class WC_Gateway_Google_Pay extends WC_Payment_Gateway_CC {

/**
* Constructor.
*/
public function __construct() {
$this->id = 'woocommerce_payments_googlePay';
$this->method_title = __( 'Google Pay', 'woocommerce-payments' );
$this->title = __( 'Google Pay', 'woocommerce-payments' );
$this->has_fields = false;
$this->enabled = true;
$this->description = '';
$this->supports = [
'products',
'refunds',
];
}

/**
* Make this gateway always available.
*
* @return bool
*/
public function is_available() {
return true;
}
}
3 changes: 3 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ public static function register_gateway( $gateways ) {
$gateways[] = self::get_payment_gateway_by_id( $payment_method_id );
}

require_once WCPAY_ABSPATH . '/includes/class-wc-gateway-google-pay.php';
$gateways[] = 'WC_Gateway_Google_Pay';

return $gateways;
}

Expand Down
Loading