From 5ae008f12e49c0305eef30bce827662ae4fd23cd Mon Sep 17 00:00:00 2001 From: Kathy Sun Date: Tue, 24 Apr 2018 17:12:01 -0700 Subject: [PATCH] deprecate bitcoin --- .../java/com/stripe/android/model/Source.java | 6 +- .../stripe/android/model/SourceParams.java | 20 ------ .../java/com/stripe/android/StripeTest.java | 69 ------------------- .../android/model/CustomerSourceTest.java | 8 +-- .../stripe/android/model/CustomerTest.java | 8 +-- .../android/model/SourceParamsTest.java | 46 ------------- .../com/stripe/android/model/SourceTest.java | 14 +--- 7 files changed, 12 insertions(+), 159 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/model/Source.java b/stripe/src/main/java/com/stripe/android/model/Source.java index 0ebf1bab36c..605dc4d81c0 100644 --- a/stripe/src/main/java/com/stripe/android/model/Source.java +++ b/stripe/src/main/java/com/stripe/android/model/Source.java @@ -32,7 +32,6 @@ public class Source extends StripeJsonModel implements StripePaymentSource { @Retention(RetentionPolicy.SOURCE) @StringDef({ ALIPAY, - BITCOIN, CARD, THREE_D_SECURE, GIROPAY, @@ -45,7 +44,6 @@ public class Source extends StripeJsonModel implements StripePaymentSource { }) public @interface SourceType { } public static final String ALIPAY = "alipay"; - public static final String BITCOIN = "bitcoin"; public static final String CARD = "card"; public static final String THREE_D_SECURE = "three_d_secure"; public static final String GIROPAY = "giropay"; @@ -543,9 +541,7 @@ static String asSourceStatus(@Nullable String sourceStatus) { @Nullable @SourceType static String asSourceType(@Nullable String sourceType) { - if (BITCOIN.equals(sourceType)) { - return BITCOIN; - } else if (CARD.equals(sourceType)) { + if (CARD.equals(sourceType)) { return CARD; } else if (THREE_D_SECURE.equals(sourceType)) { return THREE_D_SECURE; diff --git a/stripe/src/main/java/com/stripe/android/model/SourceParams.java b/stripe/src/main/java/com/stripe/android/model/SourceParams.java index d4b927b3f27..3142ef59dd9 100644 --- a/stripe/src/main/java/com/stripe/android/model/SourceParams.java +++ b/stripe/src/main/java/com/stripe/android/model/SourceParams.java @@ -204,26 +204,6 @@ public static SourceParams createCustomParams() { return new SourceParams(); } - /** - * Create a set of parameters for a Bitcoin source. - * - * @param amount amount for the transaction - * @param currency currency of the transaction (value is converted to Bitcoin on the server) - * @param email owner email for the account - * @return a {@link SourceParams} object that can be used to create a Bitcoin source - */ - @NonNull - public static SourceParams createBitcoinParams( - @IntRange(from = 0) long amount, - @NonNull String currency, - @NonNull String email) { - return new SourceParams() - .setType(Source.BITCOIN) - .setAmount(amount) - .setCurrency(currency) - .setOwner(createSimpleMap(FIELD_EMAIL, email)); - } - /** * Create a set of parameters for a credit card source. * diff --git a/stripe/src/test/java/com/stripe/android/StripeTest.java b/stripe/src/test/java/com/stripe/android/StripeTest.java index 390c7c92a6d..150d3db89b7 100644 --- a/stripe/src/test/java/com/stripe/android/StripeTest.java +++ b/stripe/src/test/java/com/stripe/android/StripeTest.java @@ -386,75 +386,6 @@ public void createSourceSynchronous_withAlipaySingleUseParams_passesIntegrationT } } - @Test - public void createSourceSynchronous_withBitcoinParams_passesIntegrationTest() { - Stripe stripe = getNonLoggingStripe(mContext); - SourceParams bitcoinParams = SourceParams.createBitcoinParams(1000L, "usd", "abc@def.com"); - Map metamap = new HashMap() {{ - put("site", "google"); - put("mood", "sad"); - }}; - bitcoinParams.setMetaData(metamap); - try { - Source bitcoinSource = - stripe.createSourceSynchronous(bitcoinParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); - assertNotNull(bitcoinSource); - assertNotNull(bitcoinSource.getId()); - assertNotNull(bitcoinSource.getClientSecret()); - assertEquals(Source.BITCOIN, bitcoinSource.getType()); - assertEquals(1000L, bitcoinSource.getAmount().longValue()); - assertNotNull(bitcoinSource.getSourceTypeData()); - assertNotNull(bitcoinSource.getOwner()); - assertNull(bitcoinSource.getSourceTypeModel()); - assertEquals("abc@def.com", bitcoinSource.getOwner().getEmail()); - assertEquals("usd", bitcoinSource.getCurrency()); - JsonTestUtils.assertMapEquals(metamap, bitcoinSource.getMetaData()); - } catch (StripeException stripeEx) { - fail("Unexpected error: " + stripeEx.getLocalizedMessage()); - } - } - - @Test - public void createSourceSynchronous_withCustomBitcoinParams_passesIntegrationTest() { - Stripe stripe = getNonLoggingStripe(mContext); - - // This causes us to go through a different code path for the source creation, - // since the strict "getType" method on bitcoinParams now returns "unknown". - // Using bitcoin to test full integration, since that is a source type that we - // accept. - SourceParams customParams = SourceParams.createCustomParams(); - Map ownerMap = new HashMap<>(); - ownerMap.put("email", "abc@def.com"); - customParams.setTypeRaw("bitcoin") - .setAmount(1000L) - .setCurrency("usd") - .setOwner(ownerMap); - Map metamap = new HashMap() {{ - put("site", "google"); - put("mood", "sad"); - }}; - customParams.setMetaData(metamap); - - try { - Source bitcoinSource = - stripe.createSourceSynchronous(customParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); - assertNotNull(bitcoinSource); - assertNotNull(bitcoinSource.getId()); - assertNotNull(bitcoinSource.getClientSecret()); - // We'll still get a bitcoin type back, because we'll recognize the string. - assertEquals(Source.BITCOIN, bitcoinSource.getType()); - assertEquals(1000L, bitcoinSource.getAmount().longValue()); - assertNotNull(bitcoinSource.getSourceTypeData()); - assertNotNull(bitcoinSource.getOwner()); - assertNull(bitcoinSource.getSourceTypeModel()); - assertEquals("abc@def.com", bitcoinSource.getOwner().getEmail()); - assertEquals("usd", bitcoinSource.getCurrency()); - JsonTestUtils.assertMapEquals(metamap, bitcoinSource.getMetaData()); - } catch (StripeException stripeEx) { - fail("Unexpected error: " + stripeEx.getLocalizedMessage()); - } - } - @Test public void createSourceSynchronous_withBancontactParams_passesIntegrationTest() { Stripe stripe = getNonLoggingStripe(mContext); diff --git a/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java b/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java index 338994d707c..50218c5c69c 100644 --- a/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java +++ b/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java @@ -10,7 +10,7 @@ import org.robolectric.annotation.Config; import static com.stripe.android.model.CardTest.JSON_CARD; -import static com.stripe.android.model.SourceTest.EXAMPLE_BITCOIN_SOURCE; +import static com.stripe.android.model.SourceTest.EXAMPLE_ALIPAY_SOURCE; import static com.stripe.android.model.SourceTest.EXAMPLE_JSON_SOURCE_WITHOUT_NULLS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -112,8 +112,8 @@ public void getSourceType_whenCard_returnsCard() { @Test public void getSourceType_whenSourceThatIsNotCard_returnsSourceType() { - CustomerSource bitcoinSource = CustomerSource.fromString(EXAMPLE_BITCOIN_SOURCE); - assertNotNull(bitcoinSource); - assertEquals(Source.BITCOIN, bitcoinSource.getSourceType()); + CustomerSource alipaySource = CustomerSource.fromString(EXAMPLE_ALIPAY_SOURCE); + assertNotNull(alipaySource); + assertEquals(Source.ALIPAY, alipaySource.getSourceType()); } } diff --git a/stripe/src/test/java/com/stripe/android/model/CustomerTest.java b/stripe/src/test/java/com/stripe/android/model/CustomerTest.java index 7aeafaea4bb..bb99fd6c21a 100644 --- a/stripe/src/test/java/com/stripe/android/model/CustomerTest.java +++ b/stripe/src/test/java/com/stripe/android/model/CustomerTest.java @@ -12,7 +12,7 @@ import static com.stripe.android.model.CardTest.JSON_CARD; import static com.stripe.android.model.CustomerSourceTest.JSON_APPLE_PAY_CARD; -import static com.stripe.android.model.SourceTest.EXAMPLE_BITCOIN_SOURCE; +import static com.stripe.android.model.SourceTest.EXAMPLE_ALIPAY_SOURCE; import static com.stripe.android.model.SourceTest.EXAMPLE_JSON_SOURCE_WITHOUT_NULLS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -120,11 +120,11 @@ private String createTestCustomerObjectWithApplePaySource() { Source sourceCardWithApplePay = Source.fromString(EXAMPLE_JSON_SOURCE_WITHOUT_NULLS); // Note that we don't yet explicitly support bitcoin sources, but this data is // convenient for the test because it is not an apple pay source. - Source bitcoinSource = Source.fromString(EXAMPLE_BITCOIN_SOURCE); + Source alipaySource = Source.fromString(EXAMPLE_ALIPAY_SOURCE); assertNotNull(sourceCardWithApplePay); - assertNotNull(bitcoinSource); + assertNotNull(alipaySource); sourcesArray.put(sourceCardWithApplePay.toJson()); - sourcesArray.put(bitcoinSource.toJson()); + sourcesArray.put(alipaySource.toJson()); sourcesArray.put(testCard.toJson()); sourcesArray.put(manipulatedApplePayCard.toJson()); diff --git a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java index 091384787e3..ea088e00cf3 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java @@ -163,52 +163,6 @@ public void createBancontactParams_toParamMap_createsExpectedMap() { JsonTestUtils.assertMapEquals(expectedMap, params.toParamMap()); } - @Test - public void createBitcoinParams_hasExpectedFields() { - SourceParams params = SourceParams.createBitcoinParams(10L, "usd", "abc@def.ghi"); - - assertEquals(Source.BITCOIN, params.getType()); - assertEquals(Source.USD, params.getCurrency()); - assertNotNull(params.getAmount()); - assertEquals(10L, params.getAmount().longValue()); - assertNotNull(params.getOwner()); - assertEquals(1, params.getOwner().size()); - assertEquals("abc@def.ghi", params.getOwner().get("email")); - } - - @Test - public void createBitcoinParams_toParamMap_hasExpectedFields() { - SourceParams params = SourceParams.createBitcoinParams(10L, "usd", "abc@def.ghi"); - Map expectedMap = new HashMap<>(); - expectedMap.put("type", "bitcoin"); - expectedMap.put("currency", "usd"); - expectedMap.put("amount", 10L); - expectedMap.put("owner", new HashMap() {{ put("email", "abc@def.ghi"); }}); - - JsonTestUtils.assertMapEquals(expectedMap, params.toParamMap()); - } - - @Test - public void createParams_thenAddMetadata_hasExpectedFieldsInMap() { - SourceParams params = SourceParams.createBitcoinParams(10L, "usd", "abc@def.ghi"); - Map metaData = new HashMap<>(); - metaData.put("custom1", "value1"); - metaData.put("custom2", "value2"); - params.setMetaData(metaData); - - Map expectedMap = new HashMap<>(); - expectedMap.put("type", "bitcoin"); - expectedMap.put("currency", "usd"); - expectedMap.put("amount", 10L); - expectedMap.put("owner", new HashMap() {{ put("email", "abc@def.ghi"); }}); - expectedMap.put("metadata", new HashMap() {{ - put("custom1", "value1"); - put("custom2", "value2"); - }}); - - JsonTestUtils.assertMapEquals(expectedMap, params.toParamMap()); - } - @Test public void createCardParams_hasBothExpectedMaps() { SourceParams params = SourceParams.createCardParams(FULL_FIELDS_VISA_CARD); diff --git a/stripe/src/test/java/com/stripe/android/model/SourceTest.java b/stripe/src/test/java/com/stripe/android/model/SourceTest.java index aaf31fe3e6c..ca8dba465cd 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceTest.java @@ -32,7 +32,7 @@ @Config(sdk = 25) public class SourceTest { - static final String EXAMPLE_BITCOIN_SOURCE = "{\n" + + static final String EXAMPLE_ALIPAY_SOURCE = "{\n" + " \"id\": \"src_1AtlSXBZqEXluyI4JgBYTq5W\",\n" + " \"object\": \"source\",\n" + " \"amount\": 1000,\n" + @@ -63,16 +63,8 @@ public class SourceTest { " },\n" + " \"statement_descriptor\": null,\n" + " \"status\": \"pending\",\n" + - " \"type\": \"bitcoin\",\n" + - " \"usage\": \"single_use\",\n" + - " \"bitcoin\": {\n" + - " \"address\": \"test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N\",\n" + - " \"amount\": 2371000,\n" + - " \"amount_charged\": 0,\n" + - " \"amount_received\": 0,\n" + - " \"amount_returned\": 0,\n" + - " \"uri\": \"bitcoin:test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N?amount=0.02371000\"\n" + - " }\n" + + " \"type\": \"alipay\",\n" + + " \"usage\": \"single_use\"\n" + "}"; static final String EXAMPLE_JSON_SOURCE_WITHOUT_NULLS = "{\n"+