From 376e9f247aff0ab47073d409e721fa05d5b40f99 Mon Sep 17 00:00:00 2001 From: joe goodall Date: Wed, 8 Jan 2025 13:00:26 +0000 Subject: [PATCH] pass js string to Purchase SDK --- ios/PrePurchaseSDK+Extension.swift | 8 +++++++- ios/PurchaseSDK.swift | 7 +++++++ src/IgniteProvider.tsx | 15 +++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ios/PrePurchaseSDK+Extension.swift b/ios/PrePurchaseSDK+Extension.swift index b72da40..092026a 100644 --- a/ios/PrePurchaseSDK+Extension.swift +++ b/ios/PrePurchaseSDK+Extension.swift @@ -3,6 +3,7 @@ import TicketmasterAuthentication import TicketmasterDiscoveryAPI import TicketmasterPrePurchase import TicketmasterPurchase +import WebKit extension PrePurchaseSDK: TMPrePurchaseNavigationDelegate, TMPrePurchaseAnalyticsDelegate { @@ -31,6 +32,10 @@ extension PrePurchaseSDK: TMPrePurchaseNavigationDelegate, TMPrePurchaseAnalytic let eventHeaderTypeString = Config.shared.get(for: "eventHeaderType") let eventHeaderType = EventHeaderType(rawValue: eventHeaderTypeString) let marketDomain = MarketDomainObject.shared.getMarketDomain() + let consentJSForWebView = Config.shared.get(for: "consentJSForWebView") + let script = WKUserScript(source: consentJSForWebView, injectionTime: .atDocumentStart, forMainFrameOnly: false) + let userContent = WKUserContentController() + userContent.addUserScript(script) TMPurchase.shared.configure(apiKey: apiKey, region: TMAuthentication.TMXDeploymentRegion(rawValue: region) ?? .US, completion: {isPurchaseApiSet in print("Purchase api key set result: \(isPurchaseApiSet)") @@ -41,7 +46,8 @@ extension PrePurchaseSDK: TMPrePurchaseNavigationDelegate, TMPrePurchaseAnalytic let headerConfig = TMPurchaseWebsiteConfiguration(eventID: eventIdentifier) headerConfig.showInfoToolbarButton = (eventHeaderType == .eventInfo || eventHeaderType == .eventInfoShare) headerConfig.showShareToolbarButton = (eventHeaderType == .eventShare || eventHeaderType == .eventInfoShare) - + headerConfig.internalTestingKeys["getConsentString"] = userContent + TMDiscoveryAPI.shared.configure(apiKey: apiKey, region: TMAuthentication.TMXDeploymentRegion(rawValue: region) ?? .US, completion: { isDiscoveryApiSet in TMDiscoveryAPI.shared.marketDomain = marketDomain diff --git a/ios/PurchaseSDK.swift b/ios/PurchaseSDK.swift index 3a5d884..9866dc2 100644 --- a/ios/PurchaseSDK.swift +++ b/ios/PurchaseSDK.swift @@ -1,5 +1,6 @@ import TicketmasterAuthentication import TicketmasterPurchase +import WebKit @objc(PurchaseSDK) class PurchaseSDK: UIViewController { @@ -38,6 +39,11 @@ class PurchaseSDK: UIViewController { let eventHeaderTypeString = Config.shared.get(for: "eventHeaderType") let eventHeaderType = EventHeaderType(rawValue: eventHeaderTypeString) let marketDomain = MarketDomainObject.shared.getMarketDomain() + + let consentJSForWebView = Config.shared.get(for: "consentJSForWebView") + let script = WKUserScript(source: consentJSForWebView, injectionTime: .atDocumentStart, forMainFrameOnly: false) + let userContent = WKUserContentController() + userContent.addUserScript(script) TMPurchase.shared.configure(apiKey: apiKey, region: TMAuthentication.TMXDeploymentRegion(rawValue: region) ?? .US, completion: { isPurchaseApiSet in print("Purchase api key set result: \(isPurchaseApiSet)") @@ -48,6 +54,7 @@ class PurchaseSDK: UIViewController { let headerConfig = TMPurchaseWebsiteConfiguration(eventID: self.eventId) headerConfig.showInfoToolbarButton = (eventHeaderType == .eventInfo || eventHeaderType == .eventInfoShare) headerConfig.showShareToolbarButton = (eventHeaderType == .eventShare || eventHeaderType == .eventInfoShare) + headerConfig.internalTestingKeys["getConsentString"] = userContent let edpNav = TMPurchaseNavigationController(configuration: headerConfig) edpNav.modalPresentationStyle = .fullScreen diff --git a/src/IgniteProvider.tsx b/src/IgniteProvider.tsx index b66d94c..9923984 100644 --- a/src/IgniteProvider.tsx +++ b/src/IgniteProvider.tsx @@ -62,6 +62,7 @@ type IgniteContextType = { refreshConfigParams: RefreshConfigParams ) => Promise; setTicketDeepLink: (id: string) => void; + setConsentJSForWebView: (value: string) => void; authState: AuthStateParams; isLoggingIn: boolean; }; @@ -113,6 +114,7 @@ export const IgniteContext = createContext({ refreshToken: async () => null, refreshConfiguration: async () => {}, setTicketDeepLink: () => {}, + setConsentJSForWebView: () => {}, isLoggingIn: false, authState: { isConfigured: false, @@ -253,6 +255,10 @@ export const IgniteProvider: React.FC = ({ Config.setConfig('orderIdDeepLink', id); }; + const setConsentJSForWebView = (value: string) => { + Config.setConfig('consentJSForWebView', value); + }; + useEffect(() => { const onConfigureAccountsSdk = async () => { setNativeConfigValues(); @@ -269,7 +275,7 @@ export const IgniteProvider: React.FC = ({ useEffect(() => { const igniteEventEmitter = new NativeEventEmitter( - NativeModules.GlobalEventEmitter + NativeModules.EventEmitter ); igniteEventEmitter.addListener( 'igniteAnalytics', @@ -327,9 +333,6 @@ export const IgniteProvider: React.FC = ({ !skipUpdate && setIsLoggingIn(false); } else if (Platform.OS === 'android') { !skipUpdate && setIsLoggingIn(true); - setTimeout(() => { - if (isLoggingIn && !skipUpdate) setIsLoggingIn(false); - }, 8000); AccountsSDK.login(async (resultCode: any) => { if (resultCode === -1) { console.log('Accounts SDK login successful'); @@ -339,6 +342,9 @@ export const IgniteProvider: React.FC = ({ resolve(); !skipUpdate && setIsLoggingIn(false); }); + setTimeout(() => { + if (isLoggingIn && !skipUpdate) setIsLoggingIn(false); + }, 8000); } }); }, @@ -481,6 +487,7 @@ export const IgniteProvider: React.FC = ({ refreshToken, refreshConfiguration, setTicketDeepLink, + setConsentJSForWebView, authState, isLoggingIn, }}