diff --git a/packages/example/ios/Podfile.lock b/packages/example/ios/Podfile.lock index a55bb9357..ad29c6df0 100644 --- a/packages/example/ios/Podfile.lock +++ b/packages/example/ios/Podfile.lock @@ -291,7 +291,7 @@ PODS: - React-jsinspector (0.72.0) - React-logger (0.72.0): - glog - - react-native-safe-area-context (4.8.1): + - react-native-safe-area-context (4.10.1): - React-Core - react-native-segmented-control (2.4.3): - React-Core @@ -400,9 +400,10 @@ PODS: - React-jsi (= 0.72.0) - React-logger (= 0.72.0) - React-perflogger (= 0.72.0) - - RNScreens (3.29.0): + - RNScreens (3.31.1): - RCT-Folly (= 2021.07.22.00) - React-Core + - React-RCTImage - SocketRocket (0.6.0) - Yoga (1.14.0) @@ -559,7 +560,7 @@ SPEC CHECKSUMS: FBReactNativeSpec: 6e7e74b1ed7f0a1a469a82a67521b33285f5fef3 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b - primer-io-react-native: fade159ffa5df541ff29feb0844aaa1f651e2bbe + primer-io-react-native: f2c8d69d0547147dfac348f81c5e9f9f0a2c6085 Primer3DS: 81e7969033230c7346a517cd609be956914738bb PrimerIPay88MYSDK: 436ee0be7e2c97e4e81456ccddee20175e9e3c4d PrimerKlarnaSDK: 83e9a1357a7247bf8fa2836fc945cf97644d601d @@ -570,23 +571,23 @@ SPEC CHECKSUMS: RCTTypeSafety: 82bd23b63f043d1a6b8e80e72fd15c08e04528a4 React: 4f2c0b59d1a1c0ae02771deb69e5ee78999fee79 React-callinvoker: d5aa9fa6cd6b67d6033de2cb5af6de7ae3dac6ca - React-Codegen: 7dcfe258f856ac8381a905f0669435736bcfb5b9 - React-Core: fce0e8a04de16c69e766f26b652e7ca9927eda9b - React-CoreModules: b02ca7a4fb869bcbe4c0ed2c939d433f13a120c5 - React-cxxreact: 9738d95069cfbe030d5f44319c9b44028f442d82 + React-Codegen: 506266f5e2c83591968d55503592f7d5f6430338 + React-Core: 41451991ffe7b3ed9c6ba38dd2022fb946569507 + React-CoreModules: 2dce6b42adf5add0b5365cd1f855268a28471192 + React-cxxreact: 297abdb09bf9bfdbf87b23d4723f019a0cd35f2f React-debug: 77ab539975d81d27153e2998bc1214a2473cde01 React-jsc: 3c0b9256529613da65281effc9ddf1067a2e075f - React-jsi: 26276762f73bf53c33c3d5252664c32ba4509f8b - React-jsiexecutor: de4e98ab0f2661affeb54931806a79a93a34d1ea + React-jsi: 1601d4786868ad204a84a7380212461e8a2d795f + React-jsiexecutor: ccd893f86087353e673f1f4b0787628555734d7a React-jsinspector: 8d754fc957255a29d93e52fc67a895045cdc8703 - React-logger: 454ffb01980778a43b0153ee98721d0275b56616 - react-native-safe-area-context: cd1169d797a2ef722a00bfc5af10748d5b6c94f9 - react-native-segmented-control: d88b35fcd06c0c8e1f1f7ed1eb066c2b02570fdd - React-NativeModulesApple: 1d81d927ef1a67a3545a01e14c2e98500bf9b199 + React-logger: d495a94eed417cef5c7208eef5131bc95c0b42a7 + react-native-safe-area-context: 8c70551c8688cd584a53487aa1b9361e991a3b4a + react-native-segmented-control: 439324cc8069ce3ba39e69d1e239e31698d1b131 + React-NativeModulesApple: 47454372967e0995641ca677a05e8f2baf6b3d78 React-perflogger: 684a11499a0589cc42135d6d5cc04d0e4e0e261a React-RCTActionSheet: 00b0a4c382a13b834124fa3f541a7d8d1d56efb9 React-RCTAnimation: 10c24c66fb504f2faa53f4ec0666c4568255cff9 - React-RCTAppDelegate: 0402b094e4f630aee6831570731759a43a69a28c + React-RCTAppDelegate: 56930a866ff0f59b787341af4a9389a76f3f9b92 React-RCTBlob: 48aaf595ea4f209faa8a80f26c23a4b9c271248f React-RCTImage: 2f609dd1c80c4aec8edf2ca235cba476fdd442ec React-RCTLinking: d7f20b7d51246bf34790ce1362d124cc1b42671b @@ -596,10 +597,10 @@ SPEC CHECKSUMS: React-RCTVibration: fb4135690f091ac9bcfbeb8dc4388208ca0e18b1 React-rncore: 91a21f0b3c16a5e011bc54d1e204bd6c5bfdf8e2 React-runtimeexecutor: 56b9f7665138fe8cda0d6c210cf95ee3f625c237 - React-runtimescheduler: 4a36521cc1ec1bc3997ae2462b6779dadaae376b - React-utils: c12d2e75c8bbc727939ddc4319ed95493395ed5a - ReactCommon: b9547f82aed45eccc1aa59034dc6c72809e37000 - RNScreens: 3c5b9f4a9dcde752466854b6109b79c0e205dad3 + React-runtimescheduler: 8a0c6a86483c945de0e2c251ea70d9cc4bf4c48e + React-utils: 2db8c09b02121a1fdbe6cc1522ae766439a2f27c + ReactCommon: eab2561b28e817cc15ce5c894469d916c62b89e1 + RNScreens: 448026fcd1beb88770b0a67a871a3d1bf9cdde0a SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 Yoga: 1d6727ed193122f6adaf435c3de1a768326ff83b diff --git a/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Assets Manager/RNTAssetsManager.swift b/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Assets Manager/RNTAssetsManager.swift index af1ab6321..5eae73e2c 100644 --- a/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Assets Manager/RNTAssetsManager.swift +++ b/packages/sdk/ios/Sources/Headless Universal Checkout/Managers/Assets Manager/RNTAssetsManager.swift @@ -7,101 +7,113 @@ import Foundation import PrimerSDK +import React @objc(RNTPrimerHeadlessUniversalCheckoutAssetsManager) class RNTPrimerHeadlessUniversalCheckoutAssetsManager: RCTEventEmitter { - override func supportedEvents() -> [String]! { - return [] + override func supportedEvents() -> [String]! { + return [] + } + + override class func requiresMainQueueSetup() -> Bool { + return true + } + + @objc + func getCardNetworkImage( + _ cardNetworkStr: String, + resolver: RCTPromiseResolveBlock, + rejecter: RCTPromiseRejectBlock + ) { + do { + + guard let cardNetwork = CardNetwork(rawValue: cardNetworkStr) else { + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "Failed to find asset of \(cardNetworkStr).", + recoverySuggestion: nil) + throw err + } + + guard + let cardNetworkImage = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager + .getCardNetworkImage(for: cardNetwork) + else { + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "Failed to find asset of \(cardNetworkStr).", + recoverySuggestion: nil) + throw err + } + + let localUrl = try cardNetworkImage.store(withName: cardNetwork.rawValue) + resolver(["cardNetworkImageURL": localUrl.absoluteString]) + + } catch { + rejecter(error.rnError["errorId"]!, error.rnError["description"], error) } - - override class func requiresMainQueueSetup() -> Bool { - return true - } - - @objc - func getCardNetworkImage( - _ cardNetworkStr: String, - resolver: RCTPromiseResolveBlock, - rejecter: RCTPromiseRejectBlock - ) { - do { - - guard let cardNetwork = CardNetwork(rawValue: cardNetworkStr) else { - let err = RNTNativeError( - errorId: "native-ios", - errorDescription: "Failed to find asset of \(cardNetworkStr).", - recoverySuggestion: nil) - throw err - } - - guard let cardNetworkImage = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager.getCardNetworkImage(for: cardNetwork) else { - let err = RNTNativeError( - errorId: "native-ios", - errorDescription: "Failed to find asset of \(cardNetworkStr).", - recoverySuggestion: nil) - throw err - } - - let localUrl = try cardNetworkImage.store(withName: cardNetwork.rawValue) - resolver(["cardNetworkImageURL": localUrl.absoluteString]) - - } catch { - rejecter(error.rnError["errorId"]!, error.rnError["description"], error) - } + } + + @objc + func getPaymentMethodAsset( + _ paymentMethodType: String, + resolver: RCTPromiseResolveBlock, + rejecter: RCTPromiseRejectBlock + ) { + do { + guard + let paymentMethodAsset = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager + .getPaymentMethodAsset(for: paymentMethodType) + else { + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "Failed to find asset of \(paymentMethodType) for this session", + recoverySuggestion: nil) + throw err + } + + if let rntPaymentMethodAsset = try? RNTPrimerPaymentMethodAsset( + primerPaymentMethodAsset: paymentMethodAsset + ).toJsonObject() { + resolver(["paymentMethodAsset": rntPaymentMethodAsset]) + } else { + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "Failed to create the RNTPrimerPaymentMethodAsset", + recoverySuggestion: nil) + throw err + } + + } catch { + rejecter(error.rnError["errorId"]!, error.rnError["description"], error) } - - @objc - func getPaymentMethodAsset( - _ paymentMethodType: String, - resolver: RCTPromiseResolveBlock, - rejecter: RCTPromiseRejectBlock - ) { - do { - guard let paymentMethodAsset = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager.getPaymentMethodAsset(for: paymentMethodType) else { - let err = RNTNativeError( - errorId: "native-ios", - errorDescription: "Failed to find asset of \(paymentMethodType) for this session", - recoverySuggestion: nil) - throw err - } - - if let rntPaymentMethodAsset = try? RNTPrimerPaymentMethodAsset(primerPaymentMethodAsset: paymentMethodAsset).toJsonObject() { - resolver(["paymentMethodAsset": rntPaymentMethodAsset]) - } else { - let err = RNTNativeError( - errorId: "native-ios", - errorDescription: "Failed to create the RNTPrimerPaymentMethodAsset", - recoverySuggestion: nil) - throw err - } - - } catch { - rejecter(error.rnError["errorId"]!, error.rnError["description"], error) - } - } - - @objc - func getPaymentMethodAssets( - _ resolver: RCTPromiseResolveBlock, - rejecter: RCTPromiseRejectBlock - ) { - do { - let paymentMethodAssets = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager.getPaymentMethodAssets() - - let rntPaymentMethodAssets = paymentMethodAssets.compactMap({ try? RNTPrimerPaymentMethodAsset(primerPaymentMethodAsset: $0).toJsonObject() }) - guard !rntPaymentMethodAssets.isEmpty else { - let err = RNTNativeError( - errorId: "native-ios", - errorDescription: "Failed to find assets for this session", - recoverySuggestion: nil) - throw err - } - - resolver(["paymentMethodAssets": rntPaymentMethodAssets]) - - } catch { - rejecter(error.rnError["errorId"]!, error.rnError["description"], error) - } + } + + @objc + func getPaymentMethodAssets( + _ resolver: RCTPromiseResolveBlock, + rejecter: RCTPromiseRejectBlock + ) { + do { + let paymentMethodAssets = try PrimerSDK.PrimerHeadlessUniversalCheckout.AssetsManager + .getPaymentMethodAssets() + + let rntPaymentMethodAssets = paymentMethodAssets.compactMap({ + try? RNTPrimerPaymentMethodAsset(primerPaymentMethodAsset: $0).toJsonObject() + }) + guard !rntPaymentMethodAssets.isEmpty else { + let err = RNTNativeError( + errorId: "native-ios", + errorDescription: "Failed to find assets for this session", + recoverySuggestion: nil) + throw err + } + + resolver(["paymentMethodAssets": rntPaymentMethodAssets]) + + } catch { + rejecter(error.rnError["errorId"]!, error.rnError["description"], error) } + } }