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 e745bc19..564bf341 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 @@ -1,6 +1,7 @@ package com.adyen.adyen_checkout.dropInAdvancedFlow import DeletedStoredPaymentMethodResultDTO +import DropInErrorDTO import DropInResultDTO import DropInResultType import android.content.Intent @@ -132,7 +133,7 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner { ) DropInResultType.ERROR -> DropInServiceResult.Error( - errorDialog = null, + errorDialog = buildErrorDialog(dropInResultDTO.error), reason = dropInResultDTO.error?.reason, dismissDropIn = dropInResultDTO.error?.dismissDropIn ?: false ) @@ -158,6 +159,14 @@ class AdvancedFlowDropInService : DropInService(), LifecycleOwner { } } + private fun buildErrorDialog(dropInError: DropInErrorDTO?): ErrorDialog? { + return if (dropInError?.dismissDropIn == true) { + null + } else { + ErrorDialog(message = dropInError?.errorMessage) + } + } + override fun onBind(intent: Intent?): IBinder { dispatcher.onServicePreSuperOnBind() return super.onBind(intent) diff --git a/example/lib/config.dart b/example/lib/config.dart index 35ed1332..72e9ee67 100644 --- a/example/lib/config.dart +++ b/example/lib/config.dart @@ -17,8 +17,8 @@ class Config { //Environment constants static const String merchantAccount = "TestMerchantCheckout"; static const String merchantName = "Test Merchant"; - static const String countryCode = "US"; - static const String shopperLocale = "us_US"; + static const String countryCode = "NL"; + static const String shopperLocale = "nl_NL"; static const String shopperReference = "Test reference"; static const Environment environment = Environment.test; static const String baseUrl = "checkout-test.adyen.com"; @@ -26,5 +26,5 @@ class Config { static const String iOSReturnUrl = "ui-host://payments"; //Example data - static Amount amount = Amount(currency: "USD", value: 2100); + static Amount amount = Amount(currency: "EUR", value: 2100); } diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 5d84e4d6..5e339423 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -177,20 +177,14 @@ class CheckoutPlatformApi: CheckoutPlatformInterface { } private func handleDropInResult(dropInResult: DropInResultDTO) { - do { switch dropInResult.dropInResultType { case .finished: onDropInResultFinished(dropInResult: dropInResult) case .action: - try onDropInResultAction(dropInResult: dropInResult) + onDropInResultAction(dropInResult: dropInResult) case .error: onDropInResultError(dropInResult: dropInResult) } - } catch { - let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) - checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) - finalize(false, "\(error.localizedDescription)") - } } private func onDropInResultFinished(dropInResult: DropInResultDTO) { @@ -204,16 +198,35 @@ class CheckoutPlatformApi: CheckoutPlatformInterface { } } - 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 onDropInResultAction(dropInResult: DropInResultDTO) { + do { + let jsonData = try JSONSerialization.data(withJSONObject: dropInResult.actionResponse as Any, options: []) + let result = try JSONDecoder().decode(Action.self, from: jsonData) + dropInComponent?.handle(result) + } catch { + let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) + finalize(false, "\(error.localizedDescription)") + } } 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 }) - finalize(false, dropInResult.error?.errorMessage ?? "") + dropInComponent?.stopLoading() + + if (dropInResult.error?.dismissDropIn == true) { + let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: dropInResult.error?.errorMessage) + checkoutFlutterApi.onDropInAdvancedFlowPlatformCommunication(platformCommunicationModel: PlatformCommunicationModel(type: PlatformCommunicationType.result, paymentResult: paymentResult), completion: { _ in }) + finalize(false, dropInResult.error?.errorMessage ?? "") + } else { + dropInComponent?.finalizeIfNeeded(with: false, completion: {}) + let localizationParameters = (dropInComponent as? Localizable)?.localizationParameters + let title = localizedString(.errorTitle, localizationParameters) + let alertController = UIAlertController(title: title, + message: dropInResult.error?.errorMessage, + preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: localizedString(.dismissButton, localizationParameters), style: .cancel)) + viewController?.adyen.topPresenter.present(alertController, animated: true) + } } private func finalize(_ success: Bool, _: String) { diff --git a/lib/src/adyen_checkout.dart b/lib/src/adyen_checkout.dart index ac30c783..251564d3 100644 --- a/lib/src/adyen_checkout.dart +++ b/lib/src/adyen_checkout.dart @@ -199,12 +199,14 @@ class AdyenCheckout implements AdyenCheckoutInterface { DropInResultDTO dropInResult = _mapToDropInResult(paymentsResult); AdyenCheckoutPlatformInterface.instance.onPaymentsResult(dropInResult); } catch (error) { - _adyenLogger.print(error.toString()); + String errorMessage = error.toString(); + _adyenLogger.print("Failure in postPayments, $errorMessage"); AdyenCheckoutPlatformInterface.instance.onPaymentsResult(DropInResultDTO( dropInResultType: DropInResultType.error, error: DropInErrorDTO( - reason: "Failure executing postPayments, ${error.toString()}", - dismissDropIn: true, + errorMessage: errorMessage, + reason: "Failure in postPayments, $errorMessage", + dismissDropIn: false, ), )); } @@ -226,13 +228,15 @@ class AdyenCheckout implements AdyenCheckoutInterface { AdyenCheckoutPlatformInterface.instance .onPaymentsDetailsResult(dropInResult); } catch (error) { - _adyenLogger.print(error.toString()); + String errorMessage = error.toString(); + _adyenLogger.print("Failure in postPaymentsDetails, $errorMessage"); AdyenCheckoutPlatformInterface.instance .onPaymentsDetailsResult(DropInResultDTO( dropInResultType: DropInResultType.error, error: DropInErrorDTO( - reason: "Failure executing postPaymentsDetails, ${error.toString()}", - dismissDropIn: true, + errorMessage: errorMessage, + reason: "Failure in postPaymentsDetails, $errorMessage}", + dismissDropIn: false, ), )); }