From 75aa3258635c6495ef87365b37f80623d21afc7f Mon Sep 17 00:00:00 2001 From: "Bruno R. Nunes" Date: Wed, 19 Jan 2022 17:32:35 -0300 Subject: [PATCH 1/3] Relay error message on PaymentResult.Failed --- .../paymentsheet/flowcontroller/DefaultFlowController.kt | 4 +--- .../flowcontroller/DefaultFlowControllerTest.kt | 6 ++++-- 2 files changed, 5 insertions(+), 5 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..ad47e591442 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 = "Localized error message" + flowController.onPaymentResult(PaymentResult.Failed(Throwable(errorMessage))) verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> paymentResult is PaymentSheetResult.Failed + && errorMessage.equals(paymentResult.error.localizedMessage) } ) } From 43b0aa60c59bc4c9297b4da8b439fcb3d09152dc Mon Sep 17 00:00:00 2001 From: "Bruno R. Nunes" Date: Wed, 19 Jan 2022 17:38:59 -0300 Subject: [PATCH 2/3] Original error message --- .../paymentsheet/flowcontroller/DefaultFlowControllerTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ad47e591442..9fda7c3a39f 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 @@ -699,7 +699,7 @@ internal class DefaultFlowControllerTest { @Test fun `onPaymentResult when error should invoke callback with Failed and relay error message`() = runTest { - val errorMessage = "Localized error message" + val errorMessage = "Original error message" flowController.onPaymentResult(PaymentResult.Failed(Throwable(errorMessage))) verify(paymentResultCallback).onPaymentSheetResult( From 63ec01c287ad7ccfdfaf37080f44f2d0da81a210 Mon Sep 17 00:00:00 2001 From: "Bruno R. Nunes" Date: Wed, 19 Jan 2022 19:11:30 -0300 Subject: [PATCH 3/3] && --- .../paymentsheet/flowcontroller/DefaultFlowControllerTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9fda7c3a39f..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 @@ -704,8 +704,8 @@ internal class DefaultFlowControllerTest { verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> - paymentResult is PaymentSheetResult.Failed - && errorMessage.equals(paymentResult.error.localizedMessage) + paymentResult is PaymentSheetResult.Failed && + errorMessage == paymentResult.error.localizedMessage } ) }