Skip to content

Commit

Permalink
Emit specific exception when Google Pay is cancelled
Browse files Browse the repository at this point in the history
COAND-1068
  • Loading branch information
OscarSpruit committed Feb 11, 2025
1 parent 1ddd057 commit 8de903f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion checkout-core/api/checkout-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public final class com/adyen/checkout/core/exception/BadModelException : com/ady
public fun <init> (Ljava/lang/Class;Ljava/lang/Throwable;)V
}

public final class com/adyen/checkout/core/exception/CancellationException : com/adyen/checkout/core/exception/CheckoutException {
public class com/adyen/checkout/core/exception/CancellationException : com/adyen/checkout/core/exception/CheckoutException {
public fun <init> (Ljava/lang/String;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ package com.adyen.checkout.core.exception
/**
* This exception indicates that the payment flow was manually cancelled by the user.
*/
class CancellationException(errorMessage: String) : CheckoutException(errorMessage)
open class CancellationException(errorMessage: String) : CheckoutException(errorMessage)
4 changes: 4 additions & 0 deletions googlepay/api/googlepay.api
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public final class com/adyen/checkout/googlepay/GooglePayButtonType : java/lang/
public static fun values ()[Lcom/adyen/checkout/googlepay/GooglePayButtonType;
}

public final class com/adyen/checkout/googlepay/GooglePayCancellationException : com/adyen/checkout/core/exception/CancellationException {
public fun <init> (Ljava/lang/String;)V
}

public final class com/adyen/checkout/googlepay/GooglePayComponent : androidx/lifecycle/ViewModel, com/adyen/checkout/action/core/internal/ActionHandlingComponent, com/adyen/checkout/components/core/internal/ActivityResultHandlingComponent, com/adyen/checkout/components/core/internal/ButtonComponent, com/adyen/checkout/components/core/internal/PaymentComponent, com/adyen/checkout/ui/core/internal/ui/ViewableComponent {
public static final field Companion Lcom/adyen/checkout/googlepay/GooglePayComponent$Companion;
public static final field PAYMENT_METHOD_TYPES Ljava/util/List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2025 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by oscars on 11/2/2025.
*/

package com.adyen.checkout.googlepay

import com.adyen.checkout.core.exception.CancellationException

/**
* This exception indicates that the payment flow was manually cancelled by the user.
*/
class GooglePayCancellationException(errorMessage: String) : CancellationException(errorMessage)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.adyen.checkout.core.exception.ComponentException
import com.adyen.checkout.core.internal.data.model.ModelUtils
import com.adyen.checkout.core.internal.util.adyenLog
import com.adyen.checkout.googlepay.GooglePayButtonParameters
import com.adyen.checkout.googlepay.GooglePayCancellationException
import com.adyen.checkout.googlepay.GooglePayComponentState
import com.adyen.checkout.googlepay.GooglePayUnavailableException
import com.adyen.checkout.googlepay.internal.data.model.GooglePayPaymentMethodModel
Expand Down Expand Up @@ -225,7 +226,7 @@ internal class DefaultGooglePayDelegate(

CommonStatusCodes.CANCELED -> {
adyenLog(AdyenLogLevel.INFO) { "GooglePay payment canceled" }
exceptionChannel.trySend(ComponentException("GooglePay payment canceled"))
exceptionChannel.trySend(GooglePayCancellationException("GooglePay payment canceled"))
}

AutoResolveHelper.RESULT_ERROR -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParam
import com.adyen.checkout.core.Environment
import com.adyen.checkout.core.exception.CheckoutException
import com.adyen.checkout.core.exception.ComponentException
import com.adyen.checkout.googlepay.GooglePayCancellationException
import com.adyen.checkout.googlepay.GooglePayComponentState
import com.adyen.checkout.googlepay.GooglePayConfiguration
import com.adyen.checkout.googlepay.GooglePayUnavailableException
Expand Down Expand Up @@ -349,6 +350,7 @@ internal class DefaultGooglePayDelegateTest(
fun `when handling payment result, then success or error is emitted`(
result: ApiTaskResult<PaymentData>,
isSuccess: Boolean,
exceptionClass: Class<Exception>?,
) = runTest {
val componentStateFlow = delegate.componentStateFlow.test(testScheduler)
val exceptionFlow = delegate.exceptionFlow.test(testScheduler)
Expand All @@ -358,7 +360,7 @@ internal class DefaultGooglePayDelegateTest(
if (isSuccess) {
assertEquals(result.result, componentStateFlow.latestValue.paymentData)
} else {
assertInstanceOf(ComponentException::class.java, exceptionFlow.latestValue)
assertInstanceOf(exceptionClass, exceptionFlow.latestValue)
}
}

Expand Down Expand Up @@ -424,12 +426,16 @@ internal class DefaultGooglePayDelegateTest(

@JvmStatic
fun paymentResultSource() = listOf(
arguments(ApiTaskResult(TEST_PAYMENT_DATA, Status.RESULT_SUCCESS), true),
arguments(ApiTaskResult(null, Status.RESULT_SUCCESS), false),
arguments(ApiTaskResult(null, Status.RESULT_CANCELED), false),
arguments(ApiTaskResult(null, Status.RESULT_INTERNAL_ERROR), false),
arguments(ApiTaskResult(null, Status.RESULT_INTERRUPTED), false),
arguments(ApiTaskResult(null, Status(AutoResolveHelper.RESULT_ERROR)), false),
arguments(ApiTaskResult(TEST_PAYMENT_DATA, Status.RESULT_SUCCESS), true, null),
arguments(ApiTaskResult(null, Status.RESULT_SUCCESS), false, ComponentException::class.java),
arguments(ApiTaskResult(null, Status.RESULT_CANCELED), false, GooglePayCancellationException::class.java),
arguments(ApiTaskResult(null, Status.RESULT_INTERNAL_ERROR), false, ComponentException::class.java),
arguments(ApiTaskResult(null, Status.RESULT_INTERRUPTED), false, ComponentException::class.java),
arguments(
ApiTaskResult(null, Status(AutoResolveHelper.RESULT_ERROR)),
false,
ComponentException::class.java,
),
)

@JvmStatic
Expand Down

0 comments on commit 8de903f

Please sign in to comment.