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

Deprecate Bitcoin #559

Merged
merged 1 commit into from
Apr 25, 2018
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
6 changes: 1 addition & 5 deletions stripe/src/main/java/com/stripe/android/model/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class Source extends StripeJsonModel implements StripePaymentSource {
@Retention(RetentionPolicy.SOURCE)
@StringDef({
ALIPAY,
BITCOIN,
CARD,
THREE_D_SECURE,
GIROPAY,
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions stripe/src/main/java/com/stripe/android/model/SourceParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
69 changes: 0 additions & 69 deletions stripe/src/test/java/com/stripe/android/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> metamap = new HashMap<String, String>() {{
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<String, Object> ownerMap = new HashMap<>();
ownerMap.put("email", "abc@def.com");
customParams.setTypeRaw("bitcoin")
.setAmount(1000L)
.setCurrency("usd")
.setOwner(ownerMap);
Map<String, String> metamap = new HashMap<String, String>() {{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> expectedMap = new HashMap<>();
expectedMap.put("type", "bitcoin");
expectedMap.put("currency", "usd");
expectedMap.put("amount", 10L);
expectedMap.put("owner", new HashMap<String, Object>() {{ 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<String, String> metaData = new HashMap<>();
metaData.put("custom1", "value1");
metaData.put("custom2", "value2");
params.setMetaData(metaData);

Map<String, Object> expectedMap = new HashMap<>();
expectedMap.put("type", "bitcoin");
expectedMap.put("currency", "usd");
expectedMap.put("amount", 10L);
expectedMap.put("owner", new HashMap<String, Object>() {{ put("email", "abc@def.ghi"); }});
expectedMap.put("metadata", new HashMap<String, Object>() {{
put("custom1", "value1");
put("custom2", "value2");
}});

JsonTestUtils.assertMapEquals(expectedMap, params.toParamMap());
}

@Test
public void createCardParams_hasBothExpectedMaps() {
SourceParams params = SourceParams.createCardParams(FULL_FIELDS_VISA_CARD);
Expand Down
14 changes: 3 additions & 11 deletions stripe/src/test/java/com/stripe/android/model/SourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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"+
Expand Down