From 8bdd235a3e7cba6bcf2fa061467ec9cf96f17181 Mon Sep 17 00:00:00 2001 From: "Bruno R. Nunes" <77990083+brnunes-stripe@users.noreply.github.com> Date: Wed, 19 Jan 2022 19:04:15 -0500 Subject: [PATCH] Relay error message on PaymentResult.Failed (#4512) --- .../paymentsheet/flowcontroller/DefaultFlowController.kt | 4 +--- .../flowcontroller/DefaultFlowControllerTest.kt | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt index c2ee23abdd1..981bb6dbce2 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt @@ -450,9 +450,7 @@ internal class DefaultFlowController @Inject internal constructor( } is PaymentResult.Failed -> { PaymentSheetResult.Failed( - IllegalArgumentException( - "Failed to confirm intent: ${paymentResult.throwable.message}" - ) + paymentResult.throwable ) } else -> { diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt index ec5ceabbae6..9e1654c8dd3 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt @@ -697,13 +697,15 @@ internal class DefaultFlowControllerTest { } @Test - fun `onPaymentResult when error should invoke callback with Failed`() = + fun `onPaymentResult when error should invoke callback with Failed and relay error message`() = runTest { - flowController.onPaymentResult(PaymentResult.Failed(Throwable("error"))) + val errorMessage = "Original error message" + flowController.onPaymentResult(PaymentResult.Failed(Throwable(errorMessage))) verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> - paymentResult is PaymentSheetResult.Failed + paymentResult is PaymentSheetResult.Failed && + errorMessage == paymentResult.error.localizedMessage } ) }