From 57d2ac4f50d63e3a7e87b976a6b5dc9ab09595df Mon Sep 17 00:00:00 2001 From: Boris Nikolic Date: Mon, 27 May 2024 18:12:52 +0200 Subject: [PATCH] Fix error when Klarna is not included in Pods --- ...HeadlessUniversalCheckoutKlarnaComponent.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Klarna/PrimerRNHeadlessUniversalCheckoutKlarnaComponent.swift b/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Klarna/PrimerRNHeadlessUniversalCheckoutKlarnaComponent.swift index 59cd08347..056dcb90e 100644 --- a/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Klarna/PrimerRNHeadlessUniversalCheckoutKlarnaComponent.swift +++ b/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Klarna/PrimerRNHeadlessUniversalCheckoutKlarnaComponent.swift @@ -12,7 +12,9 @@ import PrimerSDK @objc(RNTPrimerHeadlessUniversalCheckoutKlarnaComponent) class RNTPrimerHeadlessUniversalCheckoutKlarnaComponent: RCTEventEmitter { +#if canImport(PrimerKlarnaSDK) private var klarnaManager: PrimerHeadlessUniversalCheckout.KlarnaManager = PrimerHeadlessUniversalCheckout.KlarnaManager() +#endif var klarnaComponent: (any KlarnaComponent)? var clientToken: String? @@ -46,12 +48,21 @@ class RNTPrimerHeadlessUniversalCheckoutKlarnaComponent: RCTEventEmitter { recoverySuggestion: "'intent' can be 'CHECKOUT' or 'VAULT'.") throw err } - +#if canImport(PrimerKlarnaSDK) klarnaComponent = try klarnaManager.provideKlarnaComponent(with: sessionIntent) klarnaComponent?.stepDelegate = self klarnaComponent?.errorDelegate = self klarnaComponent?.validationDelegate = self - +#else + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "PrimerKlarnaSDK missing", + recoverySuggestion: "Check if PrimerKlarnaSDK is included in your Podfile") + + throw err +#endif + + resolver(nil) } catch { rejecter(error.rnError["errorId"]!, error.rnError["description"], error)