Skip to content

Commit

Permalink
pass js string to Purchase SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-goodall-ticketmaster committed Jan 8, 2025
1 parent 15fce03 commit 376e9f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ios/PrePurchaseSDK+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TicketmasterAuthentication
import TicketmasterDiscoveryAPI
import TicketmasterPrePurchase
import TicketmasterPurchase
import WebKit

extension PrePurchaseSDK: TMPrePurchaseNavigationDelegate, TMPrePurchaseAnalyticsDelegate {

Expand Down Expand Up @@ -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)")
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions ios/PurchaseSDK.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TicketmasterAuthentication
import TicketmasterPurchase
import WebKit

@objc(PurchaseSDK)
class PurchaseSDK: UIViewController {
Expand Down Expand Up @@ -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)")
Expand All @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/IgniteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type IgniteContextType = {
refreshConfigParams: RefreshConfigParams
) => Promise<void>;
setTicketDeepLink: (id: string) => void;
setConsentJSForWebView: (value: string) => void;
authState: AuthStateParams;
isLoggingIn: boolean;
};
Expand Down Expand Up @@ -113,6 +114,7 @@ export const IgniteContext = createContext<IgniteContextType>({
refreshToken: async () => null,
refreshConfiguration: async () => {},
setTicketDeepLink: () => {},
setConsentJSForWebView: () => {},
isLoggingIn: false,
authState: {
isConfigured: false,
Expand Down Expand Up @@ -253,6 +255,10 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
Config.setConfig('orderIdDeepLink', id);
};

const setConsentJSForWebView = (value: string) => {
Config.setConfig('consentJSForWebView', value);
};

useEffect(() => {
const onConfigureAccountsSdk = async () => {
setNativeConfigValues();
Expand All @@ -269,7 +275,7 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({

useEffect(() => {
const igniteEventEmitter = new NativeEventEmitter(
NativeModules.GlobalEventEmitter
NativeModules.EventEmitter
);
igniteEventEmitter.addListener(
'igniteAnalytics',
Expand Down Expand Up @@ -327,9 +333,6 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
!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');
Expand All @@ -339,6 +342,9 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
resolve();
!skipUpdate && setIsLoggingIn(false);
});
setTimeout(() => {
if (isLoggingIn && !skipUpdate) setIsLoggingIn(false);
}, 8000);
}
});
},
Expand Down Expand Up @@ -481,6 +487,7 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
refreshToken,
refreshConfiguration,
setTicketDeepLink,
setConsentJSForWebView,
authState,
isLoggingIn,
}}
Expand Down

0 comments on commit 376e9f2

Please sign in to comment.