google-pay / google-pay/google-pay-button
How to stop the modal window from appearing when the button is clicked, but some validations I run in onClick fail?
@dmengelt is already working on this.
Since Sep 12, 2025.
- Dominant language
- TypeScript
- Stars
- 305
- Forks
- 90
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 7
Description
Originally posted by Iorweth333 September 10, 2025
I'm using the React package. Regarding the onClick callback the page in NPM repository says
Display of the payment sheet can be prevented by calling event.preventDefault().
But event.preventDefault() doesn't stop the modal window from appearing. In onClick callback I run a validation of the form the button is a part of and when the form is invalid I call event.preventDefault(). The window appears anyway, shows loading spinner and then an error message and an instruction to go back to the payment page because not all information necessary was provided.
The error message in the modal window is perfectly right, but this is not what I expected after reading
payment sheet can be prevented
I investigated the code of both google-pay-button and pay.js and I found there is a flag EnableLoadingScreenForPopupMode which seemed to allow this behaviour, so I changed it in the onReadyToPayChange callback:
function changeFlag() {
// @ts-ignore
if (window.google.payments.api.EnableLoadingScreenForPopupMode) {
// @ts-ignore
window.google.payments.api.EnableLoadingScreenForPopupMode = false;
}
}
return (
<GooglePayButton
onReadyToPayChange={changeFlag}
//...
But since only the PaymentsClient is documented among all the things that live in google.payments.api I guess this is a hack and I shouldn't really let this go to the prod.
Is there any legit way to do this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.