11/// <reference path="../references.ts" />
22
33module ProcessOut {
4- export class GooglePayClient {
5- googleClient : any
6- processOutInstance : ProcessOut
7- paymentConfig : DynamicCheckoutPaymentConfig
8- isReadyToPayRequest : {
9- apiVersion : number
10- apiVersionMinor : number
11- allowedPaymentMethods : {
4+ interface IsReadyToPayRequest {
5+ apiVersion : number
6+ apiVersionMinor : number
7+ allowedPaymentMethods : {
8+ type : string
9+ parameters : {
10+ allowedAuthMethods : string [ ]
11+ allowedCardNetworks : string [ ]
12+ }
13+ tokenizationSpecification : {
1214 type : string
1315 parameters : {
14- allowedAuthMethods : string [ ]
15- allowedCardNetworks : string [ ]
16- }
17- tokenizationSpecification : {
18- type : string
19- parameters : {
20- gateway : string
21- gatewayMerchantId : string
22- }
16+ gateway : string
17+ gatewayMerchantId : string
2318 }
24- } [ ]
25- }
19+ }
20+ } [ ]
21+ }
2622
27- paymentRequest : {
28- apiVersion : number
29- apiVersionMinor : number
30- allowedPaymentMethods : {
23+ interface PaymentRequest {
24+ apiVersion : number
25+ apiVersionMinor : number
26+ allowedPaymentMethods : {
27+ type : string
28+ parameters : {
29+ allowedAuthMethods : string [ ]
30+ allowedCardNetworks : string [ ]
31+ }
32+ tokenizationSpecification : {
3133 type : string
3234 parameters : {
33- allowedAuthMethods : string [ ]
34- allowedCardNetworks : string [ ]
35- }
36- tokenizationSpecification : {
37- type : string
38- parameters : {
39- gateway : string
40- gatewayMerchantId : string
41- }
35+ gateway : string
36+ gatewayMerchantId : string
4237 }
43- } [ ]
44- transactionInfo : {
45- totalPriceStatus : string
46- totalPrice : string
47- currencyCode : string
48- }
49- merchantInfo : {
50- merchantName : string
5138 }
39+ } [ ]
40+ transactionInfo : {
41+ totalPriceStatus : string
42+ totalPrice : string
43+ currencyCode : string
44+ }
45+ merchantInfo : {
46+ merchantName : string
47+ merchantId : string
5248 }
49+ }
50+ export class GooglePayClient {
51+ googleClient : any
52+ processOutInstance : ProcessOut
53+ paymentConfig : DynamicCheckoutPaymentConfig
54+ isReadyToPayRequest : IsReadyToPayRequest
55+ paymentRequest : PaymentRequest
5356
5457 constructor ( processOutInstance : ProcessOut , paymentConfig : DynamicCheckoutPaymentConfig ) {
5558 this . processOutInstance = processOutInstance
@@ -62,7 +65,6 @@ module ProcessOut {
6265 getViewContainer : ( ) => HTMLElement ,
6366 ) {
6467 const googleClientScript = document . createElement ( "script" )
65-
6668 googleClientScript . src = googlePaySdkUrl
6769 googleClientScript . onload = ( ) => {
6870 this . googleClient =
@@ -113,15 +115,13 @@ module ProcessOut {
113115 JSON . parse ( paymentData . paymentMethodData . tokenizationData . token ) ,
114116 )
115117
116- const processOutInstance = this . processOutInstance
117-
118- processOutInstance . tokenize (
118+ this . processOutInstance . tokenize (
119119 paymentToken ,
120120 { } ,
121121 token => {
122122 DynamicCheckoutEventsUtils . dispatchTokenizePaymentSuccessEvent ( token )
123123
124- processOutInstance . makeCardPayment (
124+ this . processOutInstance . makeCardPayment (
125125 invoiceData . id ,
126126 token ,
127127 {
@@ -135,6 +135,7 @@ module ProcessOut {
135135 this . paymentConfig ,
136136 ) . element ,
137137 )
138+
138139 DynamicCheckoutEventsUtils . dispatchPaymentSuccessEvent ( {
139140 invoiceId,
140141 returnUrl : this . paymentConfig . invoiceDetails . return_url ,
@@ -145,17 +146,19 @@ module ProcessOut {
145146 new DynamicCheckoutPaymentErrorView ( this . processOutInstance , this . paymentConfig )
146147 . element ,
147148 )
149+
148150 DynamicCheckoutEventsUtils . dispatchPaymentErrorEvent ( error )
149151 } ,
150152 )
151153 } ,
152- err => {
154+ error => {
153155 getViewContainer ( ) . appendChild (
154156 new DynamicCheckoutPaymentErrorView ( this . processOutInstance , this . paymentConfig )
155157 . element ,
156158 )
159+
157160 DynamicCheckoutEventsUtils . dispatchTokenizePaymentErrorEvent ( {
158- message : `Tokenize payment error: ${ JSON . stringify ( err , undefined , 2 ) } ` ,
161+ message : `Tokenize payment error: ${ JSON . stringify ( error , undefined , 2 ) } ` ,
159162 } )
160163 } ,
161164 )
@@ -225,6 +228,7 @@ module ProcessOut {
225228 } ,
226229 merchantInfo : {
227230 merchantName : invoiceData . name ,
231+ merchantId : googlePayMethod . googlepay . gateway_merchant_id ,
228232 } ,
229233 }
230234 }
0 commit comments