Skip to content
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

Cleanup StripeException subclasses #2189

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class IssuingCardPinService @VisibleForTesting internal constructor(
)
listener.onIssuingCardPinRetrieved(pin)
} catch (e: InvalidRequestException) {
when (e.errorCode) {
when (e.stripeError?.code) {
"expired" -> {
listener.onError(
CardPinActionError.ONE_TIME_CODE_EXPIRED,
Expand Down Expand Up @@ -237,7 +237,7 @@ class IssuingCardPinService @VisibleForTesting internal constructor(
)
listener.onIssuingCardPinUpdated()
} catch (e: InvalidRequestException) {
when (e.errorCode) {
when (e.stripeError?.code) {
"expired" -> {
listener.onError(
CardPinActionError.ONE_TIME_CODE_EXPIRED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ internal class QueryStringFactory {
"" -> throw InvalidRequestException(
message = "You cannot set '$keyPrefix' to an empty string. We interpret empty strings as " +
"null in requests. You may set '$keyPrefix' to null to delete the property.",
param = keyPrefix
stripeError = StripeError(
param = keyPrefix
)
)
null -> {
listOf(Parameter(keyPrefix, ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package com.stripe.android.exception
import com.stripe.android.StripeError

/**
* An [Exception] indicating that invalid parameters were used in a request.
* A [StripeException] indicating that invalid parameters were used in a request.
*/
open class InvalidRequestException(
class InvalidRequestException(
stripeError: StripeError? = null,
requestId: String? = null,
statusCode: Int = 0,
message: String? = stripeError?.message,
val param: String? = stripeError?.param,
cause: Throwable? = null
) : StripeException(
stripeError,
requestId,
statusCode,
cause,
message
) {
val errorCode: String? = stripeError?.code
val errorDeclineCode: String? = stripeError?.declineCode
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import com.stripe.android.StripeError
* An [Exception] indicating that too many requests have hit the API too quickly.
*/
class RateLimitException(
stripeError: StripeError,
requestId: String? = null
) : InvalidRequestException(
stripeError = stripeError,
requestId = requestId,
statusCode = 429
stripeError: StripeError? = null,
requestId: String? = null,
message: String? = stripeError?.message,
cause: Throwable? = null
) : StripeException(
stripeError,
requestId,
429,
cause,
message
)
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ class StripeApiRepositoryTest {
)
}

assertEquals("source", invalidRequestException.param)
assertEquals("resource_missing", invalidRequestException.errorCode)
assertEquals("source", invalidRequestException.stripeError?.param)
assertEquals("resource_missing", invalidRequestException.stripeError?.code)
}

@Test
Expand All @@ -284,8 +284,8 @@ class StripeApiRepositoryTest {
)
}
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, invalidRequestException.statusCode)
assertEquals("source", invalidRequestException.param)
assertEquals("resource_missing", invalidRequestException.errorCode)
assertEquals("source", invalidRequestException.stripeError?.param)
assertEquals("resource_missing", invalidRequestException.stripeError?.code)
}

@Test
Expand Down Expand Up @@ -665,7 +665,7 @@ class StripeApiRepositoryTest {
"This PaymentIntent could be not be fulfilled via this session because a different payment method was attached to it. Another session could be attempting to fulfill this PaymentIntent. Please complete that session or try again.",
exception.message
)
assertEquals("payment_intent_unexpected_state", exception.errorCode)
assertEquals("payment_intent_unexpected_state", exception.stripeError?.code)
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/test/java/com/stripe/android/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public void run() throws Throwable {
stripe.createSourceSynchronous(weChatPaySourceParams);
}
});
assertEquals("payment_method_unactivated", ex.getErrorCode());
assertEquals("payment_method_unactivated", ex.getStripeError().getCode());
assertEquals(
"This payment method (wechat) is not activated for your account. You can only create testmode wechat payment methods. You can learn more about this here https://support.stripe.com/questions/i-am-having-trouble-activating-a-payment-method",
ex.getMessage()
Expand Down