1
- import PropTypes from "prop-types" ;
2
1
import GooglePayButton from "@google-pay/button-react" ;
3
- import useGooglepay from "./useGooglepay" ;
4
- import { useDispatch , useSelect } from "@wordpress/data" ;
2
+ import { useDispatch } from "@wordpress/data" ;
5
3
import pagarmeTokenStore from "../store/googlepay"
6
-
7
- const { registerPaymentMethod } = window . wc . wcBlocksRegistry ;
8
-
9
- const backendConfig = wc . wcSettings . getSetting (
10
- "woo-pagarme-payments-googlepay_data" ,
11
- ) ;
12
-
13
- const environment = backendConfig . isSandboxMode ? "TEST" : "PRODUCTION" ;
4
+ import validateBilling from "./validateBilling" ;
14
5
15
6
const PagarmeGooglePayComponent = ( props ) => {
16
- const { emitResponse , eventRegistration } = props ;
17
-
18
- useGooglepay ( emitResponse , eventRegistration , backendConfig ) ;
7
+ const backendConfig = wc . wcSettings . getSetting (
8
+ "woo-pagarme-payments-googlepay_data" ,
9
+ ) ;
19
10
11
+ const environment = backendConfig . isSandboxMode ? "TEST" : "PRODUCTION" ;
12
+ const billingAddress = props ?. billing ?. billingAddress ;
20
13
const {
21
14
setToken
22
15
} = useDispatch ( pagarmeTokenStore ) ;
23
-
16
+
24
17
return (
25
18
26
19
< GooglePayButton
@@ -35,7 +28,7 @@ const PagarmeGooglePayComponent = (props) => {
35
28
type : "CARD" ,
36
29
parameters : {
37
30
allowedAuthMethods : [ "PAN_ONLY" ] ,
38
- allowedCardNetworks : [ "MASTERCARD" , "VISA" , "ELO" ] ,
31
+ allowedCardNetworks : backendConfig . allowedGoogleBrands ,
39
32
} ,
40
33
tokenizationSpecification : {
41
34
type : "PAYMENT_GATEWAY" ,
@@ -59,37 +52,14 @@ const PagarmeGooglePayComponent = (props) => {
59
52
} ,
60
53
} }
61
54
onLoadPaymentData = { ( paymentRequest ) => {
62
- let googleToken = paymentRequest . paymentMethodData . tokenizationData . token ;
63
- setToken ( googleToken ) ;
55
+ if ( validateBilling ( billingAddress ) ) {
56
+ let googleToken = paymentRequest . paymentMethodData . tokenizationData . token ;
57
+ setToken ( googleToken ) ;
58
+ }
64
59
jQuery ( ".wc-block-components-checkout-place-order-button" ) . click ( ) ;
65
60
} }
66
61
/>
67
62
) ;
68
63
69
64
} ;
70
-
71
- const PagarmeGooglePayLabel = ( { components } ) => {
72
- const { PaymentMethodLabel } = components ;
73
- return < PaymentMethodLabel text = { backendConfig . label } /> ;
74
- } ;
75
-
76
- PagarmeGooglePayComponent . propTypes = {
77
- emitResponse : PropTypes . object ,
78
- eventRegistration : PropTypes . object ,
79
- } ;
80
-
81
- PagarmeGooglePayLabel . propTypes = {
82
- components : PropTypes . object ,
83
- } ;
84
-
85
-
86
- const pagarmeGooglePayPaymentMethod = {
87
- name : backendConfig . name ,
88
- label : < PagarmeGooglePayLabel /> ,
89
- content : < PagarmeGooglePayComponent /> ,
90
- edit : < PagarmeGooglePayComponent /> ,
91
- canMakePayment : ( ) => true ,
92
- ariaLabel : backendConfig . ariaLabel ,
93
- } ;
94
-
95
- registerPaymentMethod ( pagarmeGooglePayPaymentMethod ) ;
65
+ export default PagarmeGooglePayComponent ;
0 commit comments