mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Unify constructor arguments of PaymentButton
Factory method and constuctor have same arguments in the same order
This commit is contained in:
parent
9ac4300995
commit
7729007774
2 changed files with 32 additions and 5 deletions
|
@ -139,6 +139,11 @@ export default class PaymentButton {
|
||||||
*/
|
*/
|
||||||
#ppcpConfig;
|
#ppcpConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variation of a context bootstrap handler.
|
||||||
|
*/
|
||||||
|
#externalHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A variation of a context handler object, like CheckoutHandler.
|
* A variation of a context handler object, like CheckoutHandler.
|
||||||
* This handler provides a standardized interface for certain standardized checks and actions.
|
* This handler provides a standardized interface for certain standardized checks and actions.
|
||||||
|
@ -190,9 +195,9 @@ export default class PaymentButton {
|
||||||
if ( ! buttonInstances.has( instanceKey ) ) {
|
if ( ! buttonInstances.has( instanceKey ) ) {
|
||||||
const button = new this(
|
const button = new this(
|
||||||
context,
|
context,
|
||||||
|
externalHandler,
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
ppcpConfig,
|
ppcpConfig,
|
||||||
externalHandler,
|
|
||||||
contextHandler
|
contextHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -238,11 +243,18 @@ export default class PaymentButton {
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} context - Button context name.
|
* @param {string} context - Button context name.
|
||||||
|
* @param {Object} externalHandler - Handler object.
|
||||||
* @param {Object} buttonConfig - Payment button specific configuration.
|
* @param {Object} buttonConfig - Payment button specific configuration.
|
||||||
* @param {Object} ppcpConfig - Plugin wide configuration object.
|
* @param {Object} ppcpConfig - Plugin wide configuration object.
|
||||||
* @param {Object} contextHandler - Handler object.
|
* @param {Object} contextHandler - Handler object.
|
||||||
*/
|
*/
|
||||||
constructor( context, buttonConfig, ppcpConfig, contextHandler ) {
|
constructor(
|
||||||
|
context,
|
||||||
|
externalHandler = null,
|
||||||
|
buttonConfig = {},
|
||||||
|
ppcpConfig = {},
|
||||||
|
contextHandler = null
|
||||||
|
) {
|
||||||
if ( this.methodId === PaymentButton.methodId ) {
|
if ( this.methodId === PaymentButton.methodId ) {
|
||||||
throw new Error( 'Cannot initialize the PaymentButton base class' );
|
throw new Error( 'Cannot initialize the PaymentButton base class' );
|
||||||
}
|
}
|
||||||
|
@ -257,6 +269,7 @@ export default class PaymentButton {
|
||||||
this.#context = context;
|
this.#context = context;
|
||||||
this.#buttonConfig = buttonConfig;
|
this.#buttonConfig = buttonConfig;
|
||||||
this.#ppcpConfig = ppcpConfig;
|
this.#ppcpConfig = ppcpConfig;
|
||||||
|
this.#externalHandler = externalHandler;
|
||||||
this.#contextHandler = contextHandler;
|
this.#contextHandler = contextHandler;
|
||||||
|
|
||||||
this.#wrappers = this.constructor.getWrappers(
|
this.#wrappers = this.constructor.getWrappers(
|
||||||
|
@ -339,6 +352,13 @@ export default class PaymentButton {
|
||||||
return this.#ppcpConfig;
|
return this.#ppcpConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Object} The bootstrap handler instance, or an empty object.
|
||||||
|
*/
|
||||||
|
get externalHandler() {
|
||||||
|
return this.#externalHandler || {};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the button's context handler.
|
* Access the button's context handler.
|
||||||
* When no context handler was provided (like for a preview button), an empty object is returned.
|
* When no context handler was provided (like for a preview button), an empty object is returned.
|
||||||
|
@ -708,13 +728,14 @@ export default class PaymentButton {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log( 'addButton', button );
|
|
||||||
const wrapper = this.wrapperElement;
|
const wrapper = this.wrapperElement;
|
||||||
|
|
||||||
if ( this.#button ) {
|
if ( this.#button ) {
|
||||||
this.removeButton();
|
this.removeButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.log( 'addButton', button );
|
||||||
|
|
||||||
this.#button = button;
|
this.#button = button;
|
||||||
wrapper.appendChild( this.#button );
|
wrapper.appendChild( this.#button );
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,12 +93,18 @@ class GooglepayButton extends PaymentButton {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
context,
|
context,
|
||||||
|
externalHandler,
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
ppcpConfig,
|
ppcpConfig,
|
||||||
externalHandler,
|
|
||||||
contextHandler
|
contextHandler
|
||||||
) {
|
) {
|
||||||
super( context, buttonConfig, ppcpConfig, contextHandler );
|
super(
|
||||||
|
context,
|
||||||
|
externalHandler,
|
||||||
|
buttonConfig,
|
||||||
|
ppcpConfig,
|
||||||
|
contextHandler
|
||||||
|
);
|
||||||
|
|
||||||
this.onPaymentAuthorized = this.onPaymentAuthorized.bind( this );
|
this.onPaymentAuthorized = this.onPaymentAuthorized.bind( this );
|
||||||
this.onPaymentDataChanged = this.onPaymentDataChanged.bind( this );
|
this.onPaymentDataChanged = this.onPaymentDataChanged.bind( this );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue