@@ -50,6 +50,7 @@ import {
50
50
} from "@paypal/funding-components/src" ;
51
51
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src" ;
52
52
import { create , EVENT , type ZoidComponent } from "@krakenjs/zoid/src" ;
53
+ import { send as postRobotSend } from "@krakenjs/post-robot/src" ;
53
54
import {
54
55
uniqueID ,
55
56
memoize ,
@@ -99,6 +100,7 @@ export type ButtonsComponent = ZoidComponent<ButtonProps>;
99
100
100
101
export const getButtonsComponent : ( ) => ButtonsComponent = memoize ( ( ) => {
101
102
const queriedEligibleFunding = [ ] ;
103
+
102
104
return create ( {
103
105
tag : "paypal-buttons" ,
104
106
url : ( ) => `${ getPayPalDomain ( ) } ${ __PAYPAL_CHECKOUT__ . __URI__ . __BUTTONS__ } ` ,
@@ -246,6 +248,63 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
246
248
} ,
247
249
248
250
props : {
251
+ // App Switch Properties
252
+ appSwitchWhenAvailable : {
253
+ // this value is a string for now while we test the app switch
254
+ // feature. Before we give this to a real merchant, we should
255
+ // change this to a boolean - Shane 11 Dec 2024
256
+ type : "string" ,
257
+ required : false ,
258
+ } ,
259
+
260
+ hashChangeHandler : {
261
+ type : "function" ,
262
+ sendToChild : false ,
263
+ queryParam : false ,
264
+ required : false ,
265
+ value : ( ) => ( event ) => {
266
+ const iframes = document . querySelectorAll ( "iframe" ) ;
267
+
268
+ // I don't understand why but trying to make iframes which is a NodeList
269
+ // into an Iterable (so we could do a for..of loop or .forEach) is not
270
+ // working. It ends up iterating over itself so instead of looping over the contents
271
+ // of the NodeList you loop over the NodeList itself which is extremely unexpected
272
+ // for..in works though :shrug: - Shane 11 Dec 2024
273
+ for ( let i = 0 ; i < iframes . length ; i ++ ) {
274
+ if ( iframes [ i ] . name . includes ( "zoid__paypal_buttons" ) ) {
275
+ postRobotSend (
276
+ iframes [ i ] . contentWindow ,
277
+ "paypal-hashchange" ,
278
+ {
279
+ url : event . newURL ,
280
+ } ,
281
+ { domain : getPayPalDomain ( ) }
282
+ ) ;
283
+ }
284
+ }
285
+ } ,
286
+ } ,
287
+
288
+ listenForHashChanges : {
289
+ type : "function" ,
290
+ queryParam : false ,
291
+ value :
292
+ ( { props } ) =>
293
+ ( ) => {
294
+ window . addEventListener ( "hashchange" , props . hashChangeHandler ) ;
295
+ } ,
296
+ } ,
297
+
298
+ removeListenerForHashChanges : {
299
+ type : "function" ,
300
+ queryParam : false ,
301
+ value :
302
+ ( { props } ) =>
303
+ ( ) => {
304
+ window . removeEventListener ( "hashchange" , props . hashChangeHandler ) ;
305
+ } ,
306
+ } ,
307
+
249
308
// allowBillingPayments prop is used by Honey Extension to render the one-click button
250
309
// with payment methods & to use the payment methods instead of the Billing Agreement
251
310
allowBillingPayments : {
0 commit comments