-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/code style and clean up #45
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rearranged constructor
diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt index 9a887f7..80d7a30 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt @@ -131,15 +131,13 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } else { AdyenLogger.setLogLevel(NONE) } + }override fun cleanUpDropIn() { + DropInServiceResultMessenger.instance().removeObservers(activity) + DropInPaymentMethodDeletionPlatformMessenger.instance().removeObservers(activity) + DropInAdditionalDetailsPlatformMessenger.instance().removeObservers(activity) } - override fun cleanUpDropIn() { - DropInServiceResultMessenger.instance().removeObservers(activity) - DropInPaymentMethodDeletionPlatformMessenger.instance().removeObservers(activity) - DropInAdditionalDetailsPlatformMessenger.instance().removeObservers(activity) - } - - private suspend fun createCheckoutSession( + private suspend fun createCheckoutSession( sessionModel: com.adyen.checkout.sessions.core.SessionModel, dropInConfiguration: com.adyen.checkout.dropin.DropInConfiguration, ): CheckoutSession { diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/dropInAdvancedFlow/AdvancedFlowDropInService.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/dropInAdvancedFlow/AdvancedFlowDropInService.kt index 1ff5bce..e745bc1 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/dropInAdvancedFlow/AdvancedFlowDropInService.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/dropInAdvancedFlow/AdvancedFlowDropInService.kt @@ -116,8 +116,12 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner { return if (deleteStoredPaymentMethodResultDTO?.isSuccessfullyRemoved == true) { RecurringDropInServiceResult.PaymentMethodRemoved(deleteStoredPaymentMethodResultDTO.storedPaymentMethodId) } else { - //TODO - the error message should be provided by the native SDK - RecurringDropInServiceResult.Error(errorDialog = ErrorDialog(message = "Removal of the stored payment method failed. Please try again later.")) + // TODO - the error message should be provided by the native SDK + RecurringDropInServiceResult.Error( + errorDialog = ErrorDialog( + message = "Removal of the stored payment method failed. Please try again later." + ) + ) } } diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/dropInSession/SessionDropInService.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/dropInSession/SessionDropInService.kt index 95a1f1a..cac7c4c 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/dropInSession/SessionDropInService.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/dropInSession/SessionDropInService.kt @@ -48,8 +48,12 @@ class SessionDropInService : SessionDropInService(), LifecycleOwner { return if (deleteStoredPaymentMethodResultDTO?.isSuccessfullyRemoved == true) { RecurringDropInServiceResult.PaymentMethodRemoved(deleteStoredPaymentMethodResultDTO.storedPaymentMethodId) } else { - //TODO - the error message should be provided by the native SDK - RecurringDropInServiceResult.Error(errorDialog = ErrorDialog(message = "Removal of the stored payment method failed. Please try again later.")) + // TODO - the error message should be provided by the native SDK + RecurringDropInServiceResult.Error( + errorDialog = ErrorDialog( + message = "Removal of the stored payment method failed. Please try again later." + ) + ) } }
diff --git a/ios/Classes/.swiftformat b/ios/Classes/.swiftformat new file mode 100644 index 0000000..7536c60 --- /dev/null +++ b/ios/Classes/.swiftformat @@ -0,0 +1 @@ +--exclude PlatformApi.swift \ No newline at end of file diff --git a/ios/Classes/AdyenCheckoutPlugin.swift b/ios/Classes/AdyenCheckoutPlugin.swift index d6df227..e05deb9 100644 --- a/ios/Classes/AdyenCheckoutPlugin.swift +++ b/ios/Classes/AdyenCheckoutPlugin.swift @@ -2,12 +2,10 @@ import Flutter import UIKit public class AdyenCheckoutPlugin: NSObject, FlutterPlugin { - public static func register(with registrar: FlutterPluginRegistrar) { - let messenger : FlutterBinaryMessenger = registrar.messenger() + let messenger: FlutterBinaryMessenger = registrar.messenger() let checkoutFlutterApi = CheckoutFlutterApi(binaryMessenger: messenger) - let checkoutPlatformApi: CheckoutPlatformApi = CheckoutPlatformApi(checkoutFlutterApi: checkoutFlutterApi) + let checkoutPlatformApi = CheckoutPlatformApi(checkoutFlutterApi: checkoutFlutterApi) CheckoutPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: checkoutPlatformApi) } - } diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 86c349c..2d908fe 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -3,39 +3,39 @@ import Foundation import Adyen import AdyenNetworking -//TODO: Add config: +// TODO: Add config: // 1) Add Info.plist for adding photo library usage description // 2) Add url scheme // 3) Add AppDelegate redirect -class CheckoutPlatformApi : CheckoutPlatformInterface { +class CheckoutPlatformApi: CheckoutPlatformInterface { var dropInComponent: DropInComponent? private let jsonDecoder = JSONDecoder() private let configurationMapper = ConfigurationMapper() private let checkoutFlutterApi: CheckoutFlutterApi - private var viewController : UIViewController? + private var viewController: UIViewController? private var session: AdyenSession? - private var dropInSessionDelegate : AdyenSessionDelegate? - private var dropInSessionPresentationDelegate : PresentationDelegate? - private var dropInAdvancedFlowDelegate : DropInComponentDelegate? + private var dropInSessionDelegate: AdyenSessionDelegate? + private var dropInSessionPresentationDelegate: PresentationDelegate? + private var dropInAdvancedFlowDelegate: DropInComponentDelegate? private var dropInSessionStoredPaymentMethodsDelegate: DropInSessionsStoredPaymentMethodsDelegate? - private var dropInAdvancedFlowStoredPaymentMethodsDelegate : DropInAdvancedFlowStoredPaymentMethodsDelegate? - + private var dropInAdvancedFlowStoredPaymentMethodsDelegate: DropInAdvancedFlowStoredPaymentMethodsDelegate? + init(checkoutFlutterApi: CheckoutFlutterApi) { self.checkoutFlutterApi = checkoutFlutterApi } - + func getPlatformVersion(completion: @escaping (Result<String, Error>) -> Void) { let systemVersion = UIDevice.current.systemVersion completion(Result.success(systemVersion)) } - + func startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: SessionDTO) { do { guard let viewController = getViewController() else { return } - + self.viewController = viewController dropInSessionDelegate = DropInSessionsDelegate(viewController: viewController, checkoutFlutterApi: checkoutFlutterApi) dropInSessionPresentationDelegate = DropInSessionsPresentationDelegate() @@ -45,10 +45,11 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { context: adyenContext) dropInSessionStoredPaymentMethodsDelegate = DropInSessionsStoredPaymentMethodsDelegate(viewController: viewController, checkoutFlutterApi: checkoutFlutterApi) - + AdyenSession.initialize(with: sessionConfiguration, delegate: dropInSessionDelegate!, - presentationDelegate: dropInSessionPresentationDelegate!) { [weak self] result in + presentationDelegate: dropInSessionPresentationDelegate!) + { [weak self] result in switch result { case let .success(session): do { @@ -59,23 +60,23 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { configuration: dropInConfiguration!) dropInComponent.delegate = session dropInComponent.partialPaymentDelegate = session - if (dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled) { + if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled { dropInComponent.storedPaymentMethodsDelegate = self?.dropInSessionStoredPaymentMethodsDelegate } self?.dropInComponent = dropInComponent self?.viewController?.present(dropInComponent.viewController, animated: true) - } catch let error { + } catch { self?.sendSessionError(error: error) } case let .failure(error): self?.sendSessionError(error: error) } } - } catch let error { + } catch { sendSessionError(error: error) } } - + func startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) { do { guard let viewController = getViewController() else { @@ -83,7 +84,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { } self.viewController = viewController let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfigurationDTO) - let paymentMethods = try jsonDecoder.decode(PaymentMethods.self, from:Data(paymentMethodsResponse.utf8)) + let paymentMethods = try jsonDecoder.decode(PaymentMethods.self, from: Data(paymentMethodsResponse.utf8)) let paymentMethodsWithoutGiftCards = removeGiftCardPaymentMethods(paymentMethods: paymentMethods) let configuration = try configurationMapper.createDropInConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) let dropInComponent = DropInComponent(paymentMethods: paymentMethodsWithoutGiftCards, @@ -92,37 +93,37 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { dropInAdvancedFlowDelegate = DropInAdvancedFlowDelegate(checkoutFlutterApi: checkoutFlutterApi, component: dropInComponent) dropInComponent.delegate = dropInAdvancedFlowDelegate - if (dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled == true) { - dropInAdvancedFlowStoredPaymentMethodsDelegate = DropInAdvancedFlowStoredPaymentMethodsDelegate(viewController:viewController, + if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled == true { + dropInAdvancedFlowStoredPaymentMethodsDelegate = DropInAdvancedFlowStoredPaymentMethodsDelegate(viewController: viewController, checkoutFlutterApi: checkoutFlutterApi) dropInComponent.storedPaymentMethodsDelegate = dropInAdvancedFlowStoredPaymentMethodsDelegate } self.dropInComponent = dropInComponent self.viewController?.present(dropInComponent.viewController, animated: true) - } catch let error { + } catch { let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription)) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } } - + func getReturnUrl(completion: @escaping (Result<String, Error>) -> Void) { completion(Result.failure(PlatformError(errorDescription: "Please use your app url type instead of this method."))) } - + func onPaymentsResult(paymentsResult: DropInResultDTO) { handleDropInResult(dropInResult: paymentsResult) } - + func onPaymentsDetailsResult(paymentsDetailsResult: DropInResultDTO) { handleDropInResult(dropInResult: paymentsDetailsResult) } - + func onDeleteStoredPaymentMethodResult(deleteStoredPaymentMethodResultDTO: DeletedStoredPaymentMethodResultDTO) { dropInSessionStoredPaymentMethodsDelegate?.handleDisableResult(isSuccessfullyRemoved: deleteStoredPaymentMethodResultDTO.isSuccessfullyRemoved) dropInAdvancedFlowStoredPaymentMethodsDelegate?.handleDisableResult(isSuccessfullyRemoved: deleteStoredPaymentMethodResultDTO.isSuccessfullyRemoved) } - - func enableLogging(loggingEnabled: Bool) { + +func enableLogging(loggingEnabled: Bool) { AdyenLogging.isEnabled = loggingEnabled } @@ -139,17 +140,17 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { while let presentedViewController = rootViewController?.presentedViewController { let type = String(describing: type(of: presentedViewController)) // TODO: - We need to discuss how the SDK should react if a DropInNavigationController is already displayed - if (type == "DropInNavigationController") { - return nil; + if type == "DropInNavigationController" { + return nil } else { rootViewController = presentedViewController } } - + return rootViewController } - - private func createAdyenContext(dropInConfiguration: DropInConfigurationDTO) throws -> AdyenContext { + + private func createAdyenContext(dropInConfiguration: DropInConfigurationDTO) throws -> AdyenContext { let environment = mapToEnvironment(environment: dropInConfiguration.environment) let apiContext = try APIContext(environment: environment, clientKey: dropInConfiguration.clientKey) let value = Int(dropInConfiguration.amount.value) @@ -157,7 +158,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { let amount = Adyen.Amount(value: value, currencyCode: currencyCode) return AdyenContext(apiContext: apiContext, payment: Payment(amount: amount, countryCode: dropInConfiguration.countryCode)) } - + private func mapToEnvironment(environment: Environment) -> Adyen.Environment { switch environment { case .test: @@ -174,8 +175,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { return .liveApse } } - - + private func handleDropInResult(dropInResult: DropInResultDTO) { do { switch dropInResult.dropInResultType { @@ -186,51 +186,51 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { case .error: onDropInResultError(dropInResult: dropInResult) } - } catch let error { + } catch { let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: {_ in }) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) finalize(false, "\(error.localizedDescription)") } } - + private func onDropInResultFinished(dropInResult: DropInResultDTO) { let resultCode = ResultCode(rawValue: dropInResult.result ?? "") let success = resultCode == .authorised || resultCode == .received || resultCode == .pending dropInComponent?.finalizeIfNeeded(with: success) { [weak self] in self?.dropInComponent?.viewController.presentingViewController?.dismiss(animated: false, completion: { let paymentResult = PaymentResultDTO(type: PaymentResultEnum.finished, result: PaymentResultModelDTO(resultCode: resultCode?.rawValue)) - self?.checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: {_ in }) + self?.checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) }) } } - + private func onDropInResultAction(dropInResult: DropInResultDTO) throws { let jsonData = try JSONSerialization.data(withJSONObject: dropInResult.actionResponse as Any, options: []) let result = try JSONDecoder().decode(Action.self, from: jsonData) dropInComponent?.handle(result) } - + private func onDropInResultError(dropInResult: DropInResultDTO) { let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: dropInResult.error?.errorMessage) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: {_ in }) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) finalize(false, dropInResult.error?.errorMessage ?? "") } - - private func finalize(_ success: Bool, _ message: String) { + + private func finalize(_ success: Bool, _: String) { dropInComponent?.finalizeIfNeeded(with: success) { [weak self] in guard let self = self else { return } self.viewController?.dismiss(animated: true) } } - + private func removeGiftCardPaymentMethods(paymentMethods: PaymentMethods) -> PaymentMethods { - let storedPaymentMethods = paymentMethods.stored.filter { !($0.type == PaymentMethodType.giftcard)} - let paymentMethods = paymentMethods.regular.filter { !($0.type == PaymentMethodType.giftcard)} + let storedPaymentMethods = paymentMethods.stored.filter { !($0.type == PaymentMethodType.giftcard) } + let paymentMethods = paymentMethods.regular.filter { !($0.type == PaymentMethodType.giftcard) } return PaymentMethods(regular: paymentMethods, stored: storedPaymentMethods) } - + private func sendSessionError(error: Error) { let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription)) - checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } } diff --git a/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift b/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift index 2ffcca6..8068d08 100644 --- a/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift +++ b/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift @@ -1,67 +1,67 @@ import Adyen import AdyenNetworking -class DropInAdvancedFlowDelegate : DropInComponentDelegate { - private let checkoutFlutterApi : CheckoutFlutterApi +class DropInAdvancedFlowDelegate: DropInComponentDelegate { + private let checkoutFlutterApi: CheckoutFlutterApi private let component: DropInComponent - - init(checkoutFlutterApi : CheckoutFlutterApi, component: DropInComponent) { + + init(checkoutFlutterApi: CheckoutFlutterApi, component: DropInComponent) { self.checkoutFlutterApi = checkoutFlutterApi self.component = component } - - func didSubmit(_ data: PaymentComponentData, from component: PaymentComponent, in dropInComponent: AnyDropInComponent) { + + func didSubmit(_ data: PaymentComponentData, from _: PaymentComponent, in _: AnyDropInComponent) { do { let paymentComponentData = PaymentComponentDataResponse(amount: data.amount, paymentMethod: data.paymentMethod.encodable, storePaymentMethod: data.storePaymentMethod, order: data.order, amountToPay: data.order?.remainingAmount, installments: data.installments, shopperName: data.shopperName, emailAddress: data.emailAddress, telephoneNumber: data.telephoneNumber, browserInfo: data.browserInfo, checkoutAttemptId: data.checkoutAttemptId, billingAddress: data.billingAddress, deliveryAddress: data.deliveryAddress, socialSecurityNumber: data.socialSecurityNumber, delegatedAuthenticationData: data.delegatedAuthenticationData) let paymentComponentJson = try JSONEncoder().encode(paymentComponentData) let paymentComponentString = String(data: paymentComponentJson, encoding: .utf8) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel:PlatformCommunicationModel(type: PlatformCommunicationType.paymentComponent, data: paymentComponentString), completion: {_ in }) - } catch let error { - self.sendErrorToFlutterLayer(error: error) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.paymentComponent, data: paymentComponentString), completion: { _ in }) + } catch { + sendErrorToFlutterLayer(error: error) } } - - func didProvide(_ data: ActionComponentData, from component: ActionComponent, in dropInComponent: AnyDropInComponent) { + + func didProvide(_ data: ActionComponentData, from _: ActionComponent, in _: AnyDropInComponent) { do { let actionComponentData = ActionComponentDataModel(details: data.details.encodable, paymentData: data.paymentData) let actionComponentDataJson = try JSONEncoder().encode(actionComponentData) let actionComponentDataString = String(data: actionComponentDataJson, encoding: .utf8) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.additionalDetails, data: actionComponentDataString), completion: {_ in }) - } catch let error { - self.sendErrorToFlutterLayer(error: error) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.additionalDetails, data: actionComponentDataString), completion: { _ in }) + } catch { + sendErrorToFlutterLayer(error: error) } } - - func didComplete(from component: ActionComponent, in dropInComponent: AnyDropInComponent) { + + func didComplete(from _: ActionComponent, in _: AnyDropInComponent) { print("did complete") } - - func didFail(with error: Error, from component: PaymentComponent, in dropInComponent: AnyDropInComponent) { + + func didFail(with error: Error, from _: PaymentComponent, in dropInComponent: AnyDropInComponent) { dropInComponent.viewController.presentedViewController?.dismiss(animated: true, completion: { self.sendErrorToFlutterLayer(error: error) }) } - - func didFail(with error: Error, from component: ActionComponent, in dropInComponent: AnyDropInComponent) { + + func didFail(with error: Error, from _: ActionComponent, in dropInComponent: AnyDropInComponent) { dropInComponent.viewController.presentedViewController?.dismiss(animated: true, completion: { self.sendErrorToFlutterLayer(error: error) }) } - + func didFail(with error: Error, from dropInComponent: Adyen.AnyDropInComponent) { dropInComponent.viewController.dismiss(animated: true, completion: { - switch (error) { + switch error { case ComponentError.cancelled: let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.cancelledByUser, reason: error.localizedDescription)) - self.checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + self.checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) default: self.sendErrorToFlutterLayer(error: error) } }) } - + private func sendErrorToFlutterLayer(error: Error) { let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription)) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } } diff --git a/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift b/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift index 8aaa3e5..ca1f86d 100644 --- a/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift +++ b/ios/Classes/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift @@ -1,28 +1,28 @@ @_spi(AdyenInternal) import Adyen -class DropInAdvancedFlowStoredPaymentMethodsDelegate : StoredPaymentMethodsDelegate { +class DropInAdvancedFlowStoredPaymentMethodsDelegate: StoredPaymentMethodsDelegate { private let checkoutFlutterApi: CheckoutFlutterApi - private let viewController : UIViewController + private let viewController: UIViewController private var completionHandler: ((Bool) -> Void)? - + init(viewController: UIViewController, checkoutFlutterApi: CheckoutFlutterApi) { self.checkoutFlutterApi = checkoutFlutterApi self.viewController = viewController } - - internal func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { + + func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { completionHandler = completion let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.deleteStoredPaymentMethod, data: storedPaymentMethod.identifier) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } - + func handleDisableResult(isSuccessfullyRemoved: Bool) { - if (isSuccessfullyRemoved == false) { + if isSuccessfullyRemoved == false { let errorAlert = TemporaryAlertHelper.buildPaymentMethodDeletionErrorAlert() viewController.adyen.topPresenter.present(errorAlert, animated: true) } - + completionHandler?(isSuccessfullyRemoved) } } diff --git a/ios/Classes/dropInAdvancedFlow/models/ActionComponentDataModel.swift b/ios/Classes/dropInAdvancedFlow/models/ActionComponentDataModel.swift index e5ffda0..9dd3db8 100644 --- a/ios/Classes/dropInAdvancedFlow/models/ActionComponentDataModel.swift +++ b/ios/Classes/dropInAdvancedFlow/models/ActionComponentDataModel.swift @@ -1,9 +1,8 @@ -import Foundation import Adyen +import Foundation + +struct ActionComponentDataModel: Encodable { + let details: AnyEncodable -struct ActionComponentDataModel : Encodable { - - let details: AnyEncodable - - let paymentData: String? + let paymentData: String? } diff --git a/ios/Classes/dropInAdvancedFlow/models/PaymentComponentDataResponse.swift b/ios/Classes/dropInAdvancedFlow/models/PaymentComponentDataResponse.swift index c220f0b..1038ebe 100644 --- a/ios/Classes/dropInAdvancedFlow/models/PaymentComponentDataResponse.swift +++ b/ios/Classes/dropInAdvancedFlow/models/PaymentComponentDataResponse.swift @@ -2,41 +2,40 @@ import Foundation @_spi(AdyenInternal) import Adyen -struct PaymentComponentDataResponse : Encodable { - +struct PaymentComponentDataResponse: Encodable { let amount: Adyen.Amount? - + let paymentMethod: AnyEncodable? - + let storePaymentMethod: Bool? - + let order: PartialPaymentOrder? - + @available(*, deprecated, message: "This property is deprecated. Use the amount property if needed.") let amountToPay: Adyen.Amount? - + let installments: Installments? - + let supportNativeRedirect: Bool = false - + let shopperName: ShopperName? - + let emailAddress: String? - + let telephoneNumber: String? - + let browserInfo: BrowserInfo? - + let checkoutAttemptId: String? - + let billingAddress: PostalAddress? - + let deliveryAddress: PostalAddress? - + let socialSecurityNumber: String? - + let delegatedAuthenticationData: DelegatedAuthenticationData? - + enum CodingKeys: String, CodingKey { case amount, paymentMethod, diff --git a/ios/Classes/dropInSessions/DropInSessionsDelegate.swift b/ios/Classes/dropInSessions/DropInSessionsDelegate.swift index d47f552..856b311 100644 --- a/ios/Classes/dropInSessions/DropInSessionsDelegate.swift +++ b/ios/Classes/dropInSessions/DropInSessionsDelegate.swift @@ -1,38 +1,37 @@ import Adyen import AdyenNetworking -class DropInSessionsDelegate : AdyenSessionDelegate { - - private let viewController : UIViewController? +class DropInSessionsDelegate: AdyenSessionDelegate { + private let viewController: UIViewController? private let checkoutFlutterApi: CheckoutFlutterApi - + init(viewController: UIViewController, checkoutFlutterApi: CheckoutFlutterApi) { self.viewController = viewController self.checkoutFlutterApi = checkoutFlutterApi } - - func didComplete(with result: Adyen.AdyenSessionResult, component: Adyen.Component, session: Adyen.AdyenSession) { + + func didComplete(with result: Adyen.AdyenSessionResult, component _: Adyen.Component, session: Adyen.AdyenSession) { viewController?.dismiss(animated: false, completion: { let paymentResult = PaymentResultModelDTO(sessionId: session.sessionContext.identifier, sessionData: session.sessionContext.data, resultCode: result.resultCode.rawValue) let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.finished, result: paymentResult)) - self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) }) } - - func didFail(with error: Error, from component: Component, session: AdyenSession) { + + func didFail(with error: Error, from _: Component, session _: AdyenSession) { viewController?.dismiss(animated: true, completion: { - switch (error) { + switch error { case ComponentError.cancelled: let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.cancelledByUser, reason: error.localizedDescription)) - self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) default: let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription)) - self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: {_ in }) + self.checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } }) } - - func didOpenExternalApplication(component: ActionComponent, session: AdyenSession) { + + func didOpenExternalApplication(component _: ActionComponent, session _: AdyenSession) { print("external") } } diff --git a/ios/Classes/dropInSessions/DropInSessionsPresentationDelegate.swift b/ios/Classes/dropInSessions/DropInSessionsPresentationDelegate.swift index 74a5eb4..a2bad93 100644 --- a/ios/Classes/dropInSessions/DropInSessionsPresentationDelegate.swift +++ b/ios/Classes/dropInSessions/DropInSessionsPresentationDelegate.swift @@ -1,8 +1,8 @@ import Adyen -class DropInSessionsPresentationDelegate : PresentationDelegate { - func present(component: PresentableComponent) { +class DropInSessionsPresentationDelegate: PresentationDelegate { + func present(component _: PresentableComponent) { print("presentable component") - //This is required later when integrating components + // This is required later when integrating components } } diff --git a/ios/Classes/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift b/ios/Classes/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift index 3c58f8c..6817cdb 100644 --- a/ios/Classes/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift +++ b/ios/Classes/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift @@ -1,29 +1,28 @@ @_spi(AdyenInternal) import Adyen -class DropInSessionsStoredPaymentMethodsDelegate : StoredPaymentMethodsDelegate { +class DropInSessionsStoredPaymentMethodsDelegate: StoredPaymentMethodsDelegate { private let checkoutFlutterApi: CheckoutFlutterApi - private let viewController : UIViewController + private let viewController: UIViewController private var completionHandler: ((Bool) -> Void)? - + init(viewController: UIViewController, checkoutFlutterApi: CheckoutFlutterApi) { self.checkoutFlutterApi = checkoutFlutterApi self.viewController = viewController } - - internal func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { + + func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { completionHandler = completion let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.deleteStoredPaymentMethod, data: storedPaymentMethod.identifier) - checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in}) + checkoutFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) } - + func handleDisableResult(isSuccessfullyRemoved: Bool) { - if (isSuccessfullyRemoved == false) { + if isSuccessfullyRemoved == false { let errorAlert = TemporaryAlertHelper.buildPaymentMethodDeletionErrorAlert() viewController.adyen.topPresenter.present(errorAlert, animated: true) } - + completionHandler?(isSuccessfullyRemoved) } } - diff --git a/ios/Classes/utils/ConfigurationMapper.swift b/ios/Classes/utils/ConfigurationMapper.swift index 6657229..27bf2c2 100644 --- a/ios/Classes/utils/ConfigurationMapper.swift +++ b/ios/Classes/utils/ConfigurationMapper.swift @@ -3,20 +3,19 @@ import Adyen import PassKit class ConfigurationMapper { - func createDropInConfiguration(dropInConfigurationDTO: DropInConfigurationDTO) throws -> DropInComponent.Configuration { let dropInConfiguration = DropInComponent.Configuration(allowsSkippingPaymentList: dropInConfigurationDTO.skipListWhenSinglePaymentMethod, allowPreselectedPaymentView: dropInConfigurationDTO.showPreselectedStoredPaymentMethod) - + dropInConfiguration.paymentMethodsList.allowDisablingStoredPaymentMethods = dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled - + if let cardsConfigurationDTO = dropInConfigurationDTO.cardsConfigurationDTO { let koreanAuthenticationMode = cardsConfigurationDTO.kcpFieldVisibility.toCardFieldVisibility() let socialSecurityNumberMode = cardsConfigurationDTO.socialSecurityNumberFieldVisibility.toCardFieldVisibility() let storedCardConfiguration = createStoredCardConfiguration(showCvcForStoredCard: cardsConfigurationDTO.showCvcForStoredCard) let allowedCardTypes = determineAllowedCardTypes(cardTypes: cardsConfigurationDTO.supportedCardTypes) let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: cardsConfigurationDTO.addressMode) - let cardConfiguration = DropInComponent.Card.init( + let cardConfiguration = DropInComponent.Card( showsHolderNameField: cardsConfigurationDTO.holderNameRequired, showsStorePaymentMethodField: cardsConfigurationDTO.showStorePaymentField, showsSecurityCodeField: cardsConfigurationDTO.showCvc, @@ -26,38 +25,38 @@ class ConfigurationMapper { allowedCardTypes: allowedCardTypes, billingAddress: billingAddressConfiguration ) - + dropInConfiguration.card = cardConfiguration } - + if let appleConfigurationDTO = dropInConfigurationDTO.applePayConfigurationDTO { let appleConfiguration = try buildApplePayConfiguration(applePayConfigurationDTO: appleConfigurationDTO, amount: dropInConfigurationDTO.amount, countryCode: dropInConfigurationDTO.countryCode) dropInConfiguration.applePay = appleConfiguration } - + if let cashAppPayConfigurationDTO = dropInConfigurationDTO.cashAppPayConfigurationDTO { dropInConfiguration.cashAppPay = DropInComponent.CashAppPay(redirectURL: URL(string: cashAppPayConfigurationDTO.returnUrl)!) } - + return dropInConfiguration } - + private func createStoredCardConfiguration(showCvcForStoredCard: Bool) -> StoredCardConfiguration { var storedCardConfiguration = StoredCardConfiguration() storedCardConfiguration.showsSecurityCodeField = showCvcForStoredCard - return storedCardConfiguration; + return storedCardConfiguration } - + private func determineAllowedCardTypes(cardTypes: [String?]?) -> [CardType]? { guard let mappedCardTypes = cardTypes, !mappedCardTypes.isEmpty else { return nil } - - return mappedCardTypes.compactMap{$0}.map { CardType(rawValue: $0.lowercased()) } + + return mappedCardTypes.compactMap { $0 }.map { CardType(rawValue: $0.lowercased()) } } - + private func determineBillingAddressConfiguration(addressMode: AddressMode?) -> BillingAddressConfiguration { - var billingAddressConfiguration = BillingAddressConfiguration.init() + var billingAddressConfiguration = BillingAddressConfiguration() switch addressMode { case .full: billingAddressConfiguration.mode = CardComponent.AddressFormType.full @@ -68,12 +67,12 @@ class ConfigurationMapper { default: billingAddressConfiguration.mode = CardComponent.AddressFormType.none } - + return billingAddressConfiguration } - + private func buildApplePayConfiguration(applePayConfigurationDTO: ApplePayConfigurationDTO, amount: AmountDTO, countryCode: String) throws -> Adyen.ApplePayComponent.Configuration { - //TODO: Adjust pigeon code generation to use Int instead of Int64 + // TODO: Adjust pigeon code generation to use Int instead of Int64 guard let value = Int(exactly: amount.value) else { throw PlatformError(errorDescription: "Cannot map Int64 to Int.") } @@ -81,19 +80,17 @@ class ConfigurationMapper { let formattedAmount = AmountFormatter.decimalAmount(value, currencyCode: currencyCode, localeIdentifier: nil) - - let applePayPayment = try ApplePayPayment.init(countryCode: countryCode, - currencyCode: currencyCode, - summaryItems: [PKPaymentSummaryItem(label: applePayConfigurationDTO.merchantName, amount: formattedAmount)]) - - return ApplePayComponent.Configuration.init(payment: applePayPayment, - merchantIdentifier: applePayConfigurationDTO.merchantId) + + let applePayPayment = try ApplePayPayment(countryCode: countryCode, + currencyCode: currencyCode, + summaryItems: [PKPaymentSummaryItem(label: applePayConfigurationDTO.merchantName, amount: formattedAmount)]) + + return ApplePayComponent.Configuration(payment: applePayPayment, + merchantIdentifier: applePayConfigurationDTO.merchantId) } } - extension FieldVisibility { - func toCardFieldVisibility() -> CardComponent.FieldVisibility { switch self { case .show: diff --git a/ios/Classes/utils/PlatformError.swift b/ios/Classes/utils/PlatformError.swift index edb1191..f13db52 100644 --- a/ios/Classes/utils/PlatformError.swift +++ b/ios/Classes/utils/PlatformError.swift @@ -1,9 +1,8 @@ import Foundation public struct PlatformError: Error, LocalizedError { - public var errorDescription: String? - + public init(errorDescription: String? = nil) { self.errorDescription = errorDescription } diff --git a/ios/Classes/utils/TemporaryAlertHelper.swift b/ios/Classes/utils/TemporaryAlertHelper.swift index 37bfe59..b16c060 100644 --- a/ios/Classes/utils/TemporaryAlertHelper.swift +++ b/ios/Classes/utils/TemporaryAlertHelper.swift @@ -1,9 +1,8 @@ -class TemporaryAlertHelper { - +enum TemporaryAlertHelper { static func buildPaymentMethodDeletionErrorAlert() -> UIAlertController { - //TODO - this should be part of the native SDK and be translated there + // TODO: - this should be part of the native SDK and be translated there let alertController = UIAlertController(title: "Error", message: "Removal of the stored payment method failed. Please try again later.", preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "OK", style: .cancel)) - return alertController; + return alertController } }
descorp
approved these changes
Oct 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Clean up and formatted code