22< html >
33< head >
44 < title > Google Pay COEP</ title >
5- < script src ="https://pay.google.com/gp/p/js/pay.js "> </ script >
5+ <!--<script src="https://pay.google.com/gp/p/js/pay.js"></script>-->
6+
67</ head >
78< body >
89 < div id ="container "> </ div >
910
1011 < script >
11- const paymentsClient = new google . payments . api . PaymentsClient ( { environment : 'TEST' } ) ;
12+ window . addEventListener ( "error" , ( event ) => {
13+ console . error ( event ) ;
14+ } ) ;
15+
16+ window . addEventListener ( "unhandledrejection" , ( event ) => {
17+ console . error ( event ) ;
18+ } ) ;
1219
1320 const baseRequest = {
1421 apiVersion : 2 ,
2027
2128 const tokenizationSpecification = {
2229 type : 'PAYMENT_GATEWAY' ,
23- parameters : {
30+ parametes : {
2431 gateway : 'example' ,
2532 gatewayMerchantId : 'exampleMerchantId'
2633 }
6067 } ) ;
6168 }
6269
70+ function getGooglePaymentsClient ( ) {
71+ return new google . payments . api . PaymentsClient ( { environment : 'TEST' } ) ;
72+ }
73+
6374 function onGooglePayLoaded ( ) {
75+ const paymentsClient = getGooglePaymentsClient ( ) ;
6476 paymentsClient . isReadyToPay ( getGoogleIsReadyToPayRequest ( ) )
6577 . then ( function ( response ) {
6678 if ( response . result ) {
7688 }
7789
7890 function onGooglePaymentButtonClicked ( ) {
91+ const paymentsClient = getGooglePaymentsClient ( ) ;
7992 const paymentDataRequest = getGooglePaymentDataRequest ( ) ;
8093 paymentsClient . loadPaymentData ( paymentDataRequest )
8194 . then ( function ( paymentData ) {
8497 . catch ( function ( err ) {
8598 console . error ( 'Payment failed: ' , err ) ;
8699 } ) ;
87- }
100+ }
88101
89- window . onload = onGooglePayLoaded ;
102+ // window.onload = onGooglePayLoaded;
90103 </ script >
104+ < script src ="http://localhost:10079/gp/p/js/pay.js " onload ="onGooglePayLoaded() " crossorigin > </ script >
91105</ body >
92106</ html >
0 commit comments