mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add button method for checkout context
This commit is contained in:
parent
473b286de0
commit
82f46baa16
2 changed files with 41 additions and 0 deletions
|
@ -62,6 +62,30 @@ class GooglepayButton {
|
|||
)
|
||||
.then( ( response ) => {
|
||||
if ( response.result ) {
|
||||
if ( this.context === 'checkout' ) {
|
||||
const wrapper = document.getElementById(
|
||||
'ppc-button-ppcp-googlepay'
|
||||
);
|
||||
|
||||
if ( wrapper ) {
|
||||
const { ppcpStyle, buttonStyle } =
|
||||
this.contextConfig();
|
||||
wrapper.className = `ppcp-button-${ ppcpStyle.shape }`;
|
||||
|
||||
if ( ppcpStyle.height ) {
|
||||
wrapper.style.height = `${ ppcpStyle.height }px`;
|
||||
}
|
||||
|
||||
this.addButtonCheckout(
|
||||
this.baseCardPaymentMethod,
|
||||
wrapper,
|
||||
buttonStyle
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.addButton( this.baseCardPaymentMethod );
|
||||
}
|
||||
} )
|
||||
|
@ -221,6 +245,19 @@ class GooglepayButton {
|
|||
} );
|
||||
}
|
||||
|
||||
addButtonCheckout( baseCardPaymentMethod, wrapper, buttonStyle ) {
|
||||
const button = this.paymentsClient.createButton( {
|
||||
onClick: this.onButtonClick.bind( this ),
|
||||
allowedPaymentMethods: [ baseCardPaymentMethod ],
|
||||
buttonColor: buttonStyle.color || 'black',
|
||||
buttonType: buttonStyle.type || 'pay',
|
||||
buttonLocale: buttonStyle.language || 'en',
|
||||
buttonSizeMode: 'fill',
|
||||
} );
|
||||
|
||||
wrapper.appendChild( button );
|
||||
}
|
||||
|
||||
waitForWrapper( selector, callback, delay = 100, timeout = 2000 ) {
|
||||
const startTime = Date.now();
|
||||
const interval = setInterval( () => {
|
||||
|
|
|
@ -186,6 +186,10 @@ class GooglepayModule implements ModuleInterface {
|
|||
return $methods;
|
||||
}
|
||||
);
|
||||
|
||||
add_action('woocommerce_review_order_after_payment', function () {
|
||||
echo '<div id="ppc-button-' . esc_attr( GooglePayGateway::ID ) . '"></div>';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue