diff --git a/modules/ppcp-googlepay/resources/js/Preview/GooglePayPreviewButton.js b/modules/ppcp-googlepay/resources/js/Preview/GooglePayPreviewButton.js index e6b27ee55..7387c97aa 100644 --- a/modules/ppcp-googlepay/resources/js/Preview/GooglePayPreviewButton.js +++ b/modules/ppcp-googlepay/resources/js/Preview/GooglePayPreviewButton.js @@ -4,7 +4,13 @@ import PreviewButton from '../../../../ppcp-button/resources/js/modules/Preview/ /** * A single GooglePay preview button instance. */ -export default class GooglePayPreviewButton extends PreviewButton { +export default class GooglePayPreviewButton extends PreviewButton { /** + * Instance of the preview button. + * + * @type {?PaymentButton} + */ + #button = null; + constructor( args ) { super( args ); @@ -21,14 +27,18 @@ export default class GooglePayPreviewButton extends PreviewButton { } createButton( buttonConfig ) { - const button = new GooglepayButton( - 'preview', - null, - buttonConfig, - this.ppcpConfig - ); + if (!this.#button) { + this.#button = new GooglepayButton( + 'preview', + null, + buttonConfig, + this.ppcpConfig + ); + } - button.init( this.apiConfig ); + this.#button.configure( this.apiConfig, null ); + this.#button.applyButtonStyles( buttonConfig, this.ppcpConfig ); + this.#button.reinit(); } /**