From ce3d47ad3c24207b88fe2852f0124f2cd09f1285 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 12:09:03 -0800 Subject: [PATCH 1/8] Fix bug calling onKeyUpdate when should not, and better error messages --- .../stripe/android/AbstractEphemeralKey.java | 23 +++++++--- .../stripe/android/EphemeralKeyManager.java | 21 +++++++-- .../android/EphemeralKeyManagerTest.java | 45 +++++++++++++++++++ 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java index 5ccbc3e66fb..7ebd94d371a 100644 --- a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java +++ b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java @@ -216,7 +216,7 @@ String getType() { protected static TEphemeralKey fromString(@Nullable String rawJson, Class ephemeralKeyClass) throws JSONException { if (rawJson == null) { - return null; + throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass+ " null raw key"); } JSONObject object = new JSONObject(rawJson); return fromJson(object, ephemeralKeyClass); @@ -226,21 +226,32 @@ String getType() { protected static TEphemeralKey fromJson(@Nullable JSONObject jsonObject, Class ephemeralKeyClass) { if (jsonObject == null) { - return null; + throw new IllegalArgumentException("Exception instantiating " + + ephemeralKeyClass.getSimpleName() + + " null JSON"); } try { return (TEphemeralKey) ephemeralKeyClass.getConstructor(JSONObject.class).newInstance(jsonObject); } catch (InstantiationException e) { - throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass, e); + throw new IllegalArgumentException("Exception instantiating " + + ephemeralKeyClass.getSimpleName(), e); } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass, e); + throw new IllegalArgumentException("Exception instantiating " + + ephemeralKeyClass.getSimpleName(), e); } catch (InvocationTargetException e) { - throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass, e); + if (e.getTargetException() != null){ + throw new IllegalArgumentException("Improperly formatted JSON for ephemeral key " + + ephemeralKeyClass.getSimpleName() + + " - " + e.getTargetException().getMessage(), + e.getTargetException()); + } + throw new IllegalArgumentException("Improperly formatted JSON for ephemeral key " + + ephemeralKeyClass.getSimpleName(), e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Class " + - ephemeralKeyClass + + ephemeralKeyClass.getSimpleName() + " does not have an accessible (JSONObject) constructor", e); } } diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java index 8d0bc101bb1..0dfe56caa16 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java @@ -58,14 +58,29 @@ private void updateKey( @NonNull String key, @Nullable String actionString, @Nullable Map arguments) { + // Key is coming from the user, so even if it's @NonNull annotated we + // want to double check it + if (key == null) { + mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, + "EphemeralKeyUpdateListener.onKeyUpdate was called " + + "with a null value"); + } try { mEphemeralKey = AbstractEphemeralKey.fromString(key, mEphemeralKeyClass); + mListener.onKeyUpdate(mEphemeralKey, actionString, arguments); } catch (JSONException e) { mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, - "The JSON from the key could not be parsed: " - + e.getLocalizedMessage()); + "EphemeralKeyUpdateListener.onKeyUpdate was passed " + + "a value that could not be JSON parsed: [" + + e.getLocalizedMessage() + "] the raw body from Stripe's response" + + " should be passed"); + } catch (Exception e) { + mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, + "EphemeralKeyUpdateListener.onKeyUpdate was passed " + + "a value that failed to be parsed: [" + + e.getLocalizedMessage() + "] the raw body from Stripe's response" + + " should be passed"); } - mListener.onKeyUpdate(mEphemeralKey, actionString, arguments); } private void updateKeyError(int errorCode, @Nullable String errorMessage) { diff --git a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java index 6475ae06298..03714488852 100644 --- a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java +++ b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java @@ -13,6 +13,7 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; +import java.net.HttpURLConnection; import java.util.Calendar; import java.util.HashMap; import java.util.Map; @@ -250,4 +251,48 @@ public void updateKeyIfNecessary_whenReturnsError_setsExistingKeyToNull() { verifyNoMoreInteractions(mKeyManagerListener); assertNull(keyManager.getEphemeralKey()); } + + @Test + public void triggerCorrectErrorOnInvalidRawKey() { + + mTestEphemeralKeyProvider.setNextRawEphemeralKey("Not_a_JSON"); + EphemeralKeyManager keyManager = new EphemeralKeyManager( + mTestEphemeralKeyProvider, + mKeyManagerListener, + TEST_SECONDS_BUFFER, + null, + CustomerEphemeralKey.class); + + verify(mKeyManagerListener, times(0)).onKeyUpdate( + (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); + verify(mKeyManagerListener, times(1)).onKeyError( + HttpURLConnection.HTTP_INTERNAL_ERROR, + "EphemeralKeyUpdateListener.onKeyUpdate was passed a value that " + + "could not be JSON parsed: [Value Not_a_JSON of type java.lang.String " + + "cannot be converted to JSONObject] the raw body from Stripe's " + + "response should be passed"); + assertNull(keyManager.getEphemeralKey()); + } + + @Test + public void triggerCorrectErrorOnInvalidJsonKey() { + + mTestEphemeralKeyProvider.setNextRawEphemeralKey("{}"); + EphemeralKeyManager keyManager = new EphemeralKeyManager( + mTestEphemeralKeyProvider, + mKeyManagerListener, + TEST_SECONDS_BUFFER, + null, + CustomerEphemeralKey.class); + + verify(mKeyManagerListener, times(0)).onKeyUpdate( + (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); + verify(mKeyManagerListener, times(1)).onKeyError( + HttpURLConnection.HTTP_INTERNAL_ERROR, + "EphemeralKeyUpdateListener.onKeyUpdate was passed a value " + + "that failed to be parsed: [Improperly formatted JSON for ephemeral " + + "key CustomerEphemeralKey - No value for created] the raw body " + + "from Stripe's response should be passed"); + assertNull(keyManager.getEphemeralKey()); + } } From 6dbff0ad64498e6919c5e396c8a1c351cb05a9c8 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 12:56:38 -0800 Subject: [PATCH 2/8] Fix lint --- .../src/main/java/com/stripe/android/AbstractEphemeralKey.java | 3 ++- .../src/main/java/com/stripe/android/EphemeralKeyManager.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java index 7ebd94d371a..605cf959a56 100644 --- a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java +++ b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java @@ -216,7 +216,8 @@ String getType() { protected static TEphemeralKey fromString(@Nullable String rawJson, Class ephemeralKeyClass) throws JSONException { if (rawJson == null) { - throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass+ " null raw key"); + throw new IllegalArgumentException("Exception instantiating " + + ephemeralKeyClass.getSimpleName() + ": null raw key"); } JSONObject object = new JSONObject(rawJson); return fromJson(object, ephemeralKeyClass); diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java index 0dfe56caa16..e809d0b1142 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java @@ -54,6 +54,7 @@ TEphemeralKey getEphemeralKey() { return mEphemeralKey; } + @SuppressWarnings("checkstyle:IllegalCatch") private void updateKey( @NonNull String key, @Nullable String actionString, From 263e12ec77430b36a3b75f7c31622221a5b320ff Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 12:57:12 -0800 Subject: [PATCH 3/8] more explicit variable naming --- .../java/com/stripe/android/EphemeralKeyUpdateListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java index efdb290e5b4..a3625a6d430 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java @@ -11,9 +11,9 @@ public interface EphemeralKeyUpdateListener { /** * Called when a key update request from your server comes back successfully. * - * @param rawKey the raw String returned from Stripe's servers + * @param rawJsonBodyReturnedByStripe the raw String returned from Stripe's servers */ - void onKeyUpdate(@NonNull String rawKey); + void onKeyUpdate(@NonNull String rawJsonBodyReturnedByStripe); /** * Called when a key update request from your server comes back with an error. From 384cbe72509360a0da370a3a19b1a354112097f3 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 13:05:10 -0800 Subject: [PATCH 4/8] Better handling of null ephemeral key case --- .../stripe/android/AbstractEphemeralKey.java | 4 ++-- .../android/EphemeralKeyManagerTest.java | 19 +++++++++++++++++++ .../testharness/TestEphemeralKeyProvider.java | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java index 605cf959a56..5c5db315726 100644 --- a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java +++ b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java @@ -216,8 +216,8 @@ String getType() { protected static TEphemeralKey fromString(@Nullable String rawJson, Class ephemeralKeyClass) throws JSONException { if (rawJson == null) { - throw new IllegalArgumentException("Exception instantiating " + - ephemeralKeyClass.getSimpleName() + ": null raw key"); + throw new IllegalArgumentException("Attempted to instantiate " + + ephemeralKeyClass.getSimpleName() + " with null raw key"); } JSONObject object = new JSONObject(rawJson); return fromJson(object, ephemeralKeyClass); diff --git a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java index 03714488852..68bbafb641d 100644 --- a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java +++ b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java @@ -295,4 +295,23 @@ public void triggerCorrectErrorOnInvalidJsonKey() { "from Stripe's response should be passed"); assertNull(keyManager.getEphemeralKey()); } + + @Test + public void triggerCorrectErrorOnNullKey() { + + mTestEphemeralKeyProvider.setNextRawEphemeralKey(null); + EphemeralKeyManager keyManager = new EphemeralKeyManager( + mTestEphemeralKeyProvider, + mKeyManagerListener, + TEST_SECONDS_BUFFER, + null, + CustomerEphemeralKey.class); + + verify(mKeyManagerListener, times(0)).onKeyUpdate( + (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); + verify(mKeyManagerListener, times(1)).onKeyError( + HttpURLConnection.HTTP_INTERNAL_ERROR, + "EphemeralKeyUpdateListener.onKeyUpdate was called with a null value"); + assertNull(keyManager.getEphemeralKey()); + } } diff --git a/stripe/src/test/java/com/stripe/android/testharness/TestEphemeralKeyProvider.java b/stripe/src/test/java/com/stripe/android/testharness/TestEphemeralKeyProvider.java index 33e74896670..72aee10e0dc 100644 --- a/stripe/src/test/java/com/stripe/android/testharness/TestEphemeralKeyProvider.java +++ b/stripe/src/test/java/com/stripe/android/testharness/TestEphemeralKeyProvider.java @@ -27,6 +27,9 @@ public void createEphemeralKey( keyUpdateListener.onKeyUpdate(mRawEphemeralKey); } else if (mErrorCode != INVALID_ERROR_CODE) { keyUpdateListener.onKeyUpdateFailure(mErrorCode, mErrorMessage); + } else { + // Useful to test edge cases + keyUpdateListener.onKeyUpdate(null); } } From e5f8387097ad3d303f88560bcd6fd303c4ba7d9e Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 13:05:41 -0800 Subject: [PATCH 5/8] Better naming still --- .../java/com/stripe/android/EphemeralKeyUpdateListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java index a3625a6d430..c156d3f09e3 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyUpdateListener.java @@ -11,9 +11,9 @@ public interface EphemeralKeyUpdateListener { /** * Called when a key update request from your server comes back successfully. * - * @param rawJsonBodyReturnedByStripe the raw String returned from Stripe's servers + * @param stripeResponseJson the raw JSON String returned from Stripe's servers */ - void onKeyUpdate(@NonNull String rawJsonBodyReturnedByStripe); + void onKeyUpdate(@NonNull String stripeResponseJson); /** * Called when a key update request from your server comes back with an error. From 2e50eca6830c369d434ca315e11450a57cd7f718 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 13:09:19 -0800 Subject: [PATCH 6/8] Review comments and bug fix --- .../com/stripe/android/EphemeralKeyManager.java | 1 + .../com/stripe/android/EphemeralKeyManagerTest.java | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java index e809d0b1142..4f6b1a0c807 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java @@ -65,6 +65,7 @@ private void updateKey( mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was called " + "with a null value"); + return; } try { mEphemeralKey = AbstractEphemeralKey.fromString(key, mEphemeralKeyClass); diff --git a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java index 68bbafb641d..c54d51bc7ce 100644 --- a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java +++ b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -256,14 +257,14 @@ public void updateKeyIfNecessary_whenReturnsError_setsExistingKeyToNull() { public void triggerCorrectErrorOnInvalidRawKey() { mTestEphemeralKeyProvider.setNextRawEphemeralKey("Not_a_JSON"); - EphemeralKeyManager keyManager = new EphemeralKeyManager( + EphemeralKeyManager keyManager = new EphemeralKeyManager<>( mTestEphemeralKeyProvider, mKeyManagerListener, TEST_SECONDS_BUFFER, null, CustomerEphemeralKey.class); - verify(mKeyManagerListener, times(0)).onKeyUpdate( + verify(mKeyManagerListener, never()).onKeyUpdate( (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); verify(mKeyManagerListener, times(1)).onKeyError( HttpURLConnection.HTTP_INTERNAL_ERROR, @@ -278,14 +279,14 @@ public void triggerCorrectErrorOnInvalidRawKey() { public void triggerCorrectErrorOnInvalidJsonKey() { mTestEphemeralKeyProvider.setNextRawEphemeralKey("{}"); - EphemeralKeyManager keyManager = new EphemeralKeyManager( + EphemeralKeyManager keyManager = new EphemeralKeyManager<>( mTestEphemeralKeyProvider, mKeyManagerListener, TEST_SECONDS_BUFFER, null, CustomerEphemeralKey.class); - verify(mKeyManagerListener, times(0)).onKeyUpdate( + verify(mKeyManagerListener, never()).onKeyUpdate( (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); verify(mKeyManagerListener, times(1)).onKeyError( HttpURLConnection.HTTP_INTERNAL_ERROR, @@ -300,14 +301,14 @@ public void triggerCorrectErrorOnInvalidJsonKey() { public void triggerCorrectErrorOnNullKey() { mTestEphemeralKeyProvider.setNextRawEphemeralKey(null); - EphemeralKeyManager keyManager = new EphemeralKeyManager( + EphemeralKeyManager keyManager = new EphemeralKeyManager<>( mTestEphemeralKeyProvider, mKeyManagerListener, TEST_SECONDS_BUFFER, null, CustomerEphemeralKey.class); - verify(mKeyManagerListener, times(0)).onKeyUpdate( + verify(mKeyManagerListener, never()).onKeyUpdate( (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); verify(mKeyManagerListener, times(1)).onKeyError( HttpURLConnection.HTTP_INTERNAL_ERROR, From 332b2eb869927d3385750443d8517e8cf63fe271 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 13:12:27 -0800 Subject: [PATCH 7/8] Better texts --- .../src/main/java/com/stripe/android/EphemeralKeyManager.java | 4 ++-- .../test/java/com/stripe/android/EphemeralKeyManagerTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java index 4f6b1a0c807..8a26a169193 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java @@ -74,13 +74,13 @@ private void updateKey( mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was passed " + "a value that could not be JSON parsed: [" - + e.getLocalizedMessage() + "] the raw body from Stripe's response" + + + e.getLocalizedMessage() + "]. The raw body from Stripe's response" + " should be passed"); } catch (Exception e) { mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was passed " + "a value that failed to be parsed: [" - + e.getLocalizedMessage() + "] the raw body from Stripe's response" + + + e.getLocalizedMessage() + "]. The raw body from Stripe's response" + " should be passed"); } } diff --git a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java index c54d51bc7ce..a3409bbf693 100644 --- a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java +++ b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java @@ -270,7 +270,7 @@ public void triggerCorrectErrorOnInvalidRawKey() { HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was passed a value that " + "could not be JSON parsed: [Value Not_a_JSON of type java.lang.String " + - "cannot be converted to JSONObject] the raw body from Stripe's " + + "cannot be converted to JSONObject]. The raw body from Stripe's " + "response should be passed"); assertNull(keyManager.getEphemeralKey()); } @@ -292,7 +292,7 @@ public void triggerCorrectErrorOnInvalidJsonKey() { HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was passed a value " + "that failed to be parsed: [Improperly formatted JSON for ephemeral " + - "key CustomerEphemeralKey - No value for created] the raw body " + + "key CustomerEphemeralKey - No value for created]. The raw body " + "from Stripe's response should be passed"); assertNull(keyManager.getEphemeralKey()); } From 8c287d8c6ab1860ce1aec2e617504b5b26e98476 Mon Sep 17 00:00:00 2001 From: Arnaud Cavailhez Date: Wed, 23 Jan 2019 13:34:43 -0800 Subject: [PATCH 8/8] More explicit error message --- .../main/java/com/stripe/android/AbstractEphemeralKey.java | 2 +- .../src/main/java/com/stripe/android/EphemeralKeyManager.java | 2 +- .../test/java/com/stripe/android/EphemeralKeyManagerTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java index 5c5db315726..fee5b1e1ac3 100644 --- a/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java +++ b/stripe/src/main/java/com/stripe/android/AbstractEphemeralKey.java @@ -242,7 +242,7 @@ String getType() { throw new IllegalArgumentException("Exception instantiating " + ephemeralKeyClass.getSimpleName(), e); } catch (InvocationTargetException e) { - if (e.getTargetException() != null){ + if (e.getTargetException() != null) { throw new IllegalArgumentException("Improperly formatted JSON for ephemeral key " + ephemeralKeyClass.getSimpleName() + " - " + e.getTargetException().getMessage(), diff --git a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java index 8a26a169193..b2eab256b52 100644 --- a/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java +++ b/stripe/src/main/java/com/stripe/android/EphemeralKeyManager.java @@ -79,7 +79,7 @@ private void updateKey( } catch (Exception e) { mListener.onKeyError(HttpURLConnection.HTTP_INTERNAL_ERROR, "EphemeralKeyUpdateListener.onKeyUpdate was passed " + - "a value that failed to be parsed: [" + "a JSON String that was invalid: [" + e.getLocalizedMessage() + "]. The raw body from Stripe's response" + " should be passed"); } diff --git a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java index a3409bbf693..934756c04b2 100644 --- a/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java +++ b/stripe/src/test/java/com/stripe/android/EphemeralKeyManagerTest.java @@ -290,8 +290,8 @@ public void triggerCorrectErrorOnInvalidJsonKey() { (CustomerEphemeralKey) isNull(), (String) isNull(), (Map) isNull()); verify(mKeyManagerListener, times(1)).onKeyError( HttpURLConnection.HTTP_INTERNAL_ERROR, - "EphemeralKeyUpdateListener.onKeyUpdate was passed a value " + - "that failed to be parsed: [Improperly formatted JSON for ephemeral " + + "EphemeralKeyUpdateListener.onKeyUpdate was passed a JSON String " + + "that was invalid: [Improperly formatted JSON for ephemeral " + "key CustomerEphemeralKey - No value for created]. The raw body " + "from Stripe's response should be passed"); assertNull(keyManager.getEphemeralKey());