Skip to content

Commit

Permalink
Remove deprecated code related to BankAccount and ActivityStarter (#2544
Browse files Browse the repository at this point in the history
)

Use `BankAccountTokenParams` instead of `BankAccount` to create a
bank account token.

Remove `ActivityStarter#startForResult()`
  • Loading branch information
mshafrir-stripe authored Jun 4, 2020
1 parent c311ef4 commit bcdf99a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 310 deletions.
68 changes: 0 additions & 68 deletions stripe/src/main/java/com/stripe/android/Stripe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1122,74 +1122,6 @@ class Stripe internal constructor(
)
}

/**
* Create a [BankAccount] token asynchronously.
*
* See [Create a bank account token](https://stripe.com/docs/api/tokens/create_bank_account).
* `POST /v1/tokens`
*
* @param bankAccount the [BankAccount] used to create this token
* @param idempotencyKey optional, see [Idempotent Requests](https://stripe.com/docs/api/idempotent_requests)
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param callback a [ApiResultCallback] to receive the result or error
*/
@Deprecated("Use BankAccountTokenParams")
@UiThread
@JvmOverloads
fun createBankAccountToken(
bankAccount: BankAccount,
idempotencyKey: String? = null,
stripeAccountId: String? = this.stripeAccountId,
callback: ApiResultCallback<Token>
) {
createToken(
bankAccount,
stripeAccountId,
idempotencyKey,
callback
)
}

/**
* Blocking method to create a [Token] for a [BankAccount]. Do not call this on
* the UI thread or your app will crash.
*
* See [Create a bank account token](https://stripe.com/docs/api/tokens/create_bank_account).
* `POST /v1/tokens`
*
* @param bankAccount the [BankAccount] to use for this token
* @param idempotencyKey optional, see [Idempotent Requests](https://stripe.com/docs/api/idempotent_requests)
*
* @return a [Token] that can be used for this [BankAccount]
*
* @throws AuthenticationException failure to properly authenticate yourself (check your key)
* @throws InvalidRequestException your request has invalid parameters
* @throws APIConnectionException failure to connect to Stripe's API
* @throws CardException should not be thrown with this type of token, but is theoretically
* possible given the underlying methods called
* @throws APIException any other type of problem (for instance, a temporary issue with
* Stripe's servers
*/
@Deprecated("Use BankAccountTokenParams")
@Throws(AuthenticationException::class, InvalidRequestException::class,
APIConnectionException::class, CardException::class, APIException::class)
@WorkerThread
@JvmOverloads
fun createBankAccountTokenSynchronous(
bankAccount: BankAccount,
idempotencyKey: String? = null
): Token? {
return stripeRepository.createToken(
bankAccount,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId,
idempotencyKey = idempotencyKey
)
)
}

/**
* Create a PII token asynchronously.
*
Expand Down
88 changes: 1 addition & 87 deletions stripe/src/main/java/com/stripe/android/model/BankAccount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ data class BankAccount internal constructor(
*/
val id: String? = null,

@Deprecated("Use BankAccountTokenParams")
val accountNumber: String? = null,

/**
* The name of the person or business that owns the bank account.
*
Expand Down Expand Up @@ -96,7 +93,7 @@ data class BankAccount internal constructor(
* [status](https://stripe.com/docs/api/customer_bank_accounts/object#customer_bank_account_object-status)
*/
val status: Status? = null
) : StripeModel, TokenParams(Token.TokenType.BANK_ACCOUNT) {
) : StripeModel {

@Retention(AnnotationRetention.SOURCE)
@StringDef(BankAccountType.COMPANY, BankAccountType.INDIVIDUAL)
Expand All @@ -120,87 +117,4 @@ data class BankAccount internal constructor(
}
}
}

/**
* [Create a bank account token](https://stripe.com/docs/api/tokens/create_bank_account)
*
* @param accountNumber The account number for the bank account, in string form.
* Must be a checking account.
* @param countryCode The country in which the bank account is located.
* @param currency The currency the bank account is in. This must be a country/currency pairing
* that Stripe supports.
* @param routingNumber Optional. The routing number, sort code, or other country-appropriate
* institution number for the bank account. For US bank accounts, this is required and should
* be the ACH routing number, not the wire routing number. If you are providing an IBAN for
* `account_number`, this field is not required.
* @param accountHolderName Optional. The name of the person or business that owns the bank
* account. This field is required when attaching the bank account to a `Customer` object.
* @param accountHolderType Optional. The type of entity that holds the account. This can be
* either `individual` or `company`. This field is required when attaching the bank account to
* a `Customer` object.
*/
@Deprecated("Use BankAccountTokenParams")
@JvmOverloads
constructor(
accountNumber: String,
@Size(2) countryCode: String,
@Size(3) currency: String,
routingNumber: String? = null,
accountHolderName: String? = null,
@BankAccountType accountHolderType: String? = null
) : this(
accountNumber = accountNumber,
accountHolderName = accountHolderName,
accountHolderType = accountHolderType,
countryCode = countryCode,
currency = currency,
routingNumber = routingNumber,
fingerprint = null
)

/**
* Constructor with no account number used internally to initialize an object
* from JSON returned from the server.
*
* @param accountHolderName the account holder's name
* @param accountHolderType the [BankAccountType]
* @param bankName the name of the bank
* @param countryCode the two-letter country code of the country in which the account was opened
* @param currency the three-letter currency code
* @param fingerprint the account fingerprint
* @param last4 the last four digits of the account number
* @param routingNumber the routing number of the bank
*/
@Deprecated("For internal use only")
constructor(
accountHolderName: String?,
@BankAccountType accountHolderType: String?,
bankName: String?,
@Size(2) countryCode: String?,
@Size(3) currency: String?,
fingerprint: String?,
last4: String?,
routingNumber: String?
) : this(
id = null,
accountHolderName = accountHolderName,
accountHolderType = accountHolderType,
bankName = bankName,
countryCode = countryCode,
currency = currency,
fingerprint = fingerprint,
last4 = last4,
routingNumber = routingNumber
)

override fun toParamMap(): Map<String, Any> {
return BankAccountTokenParams(
country = countryCode.orEmpty(),
currency = currency.orEmpty(),
accountNumber = accountNumber.orEmpty(),
routingNumber = routingNumber,
accountHolderName = accountHolderName,
accountHolderType = BankAccountTokenParams.Type.fromCode(accountHolderType)
).toParamMap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ internal class BankAccountJsonParser : ModelJsonParser<BankAccount> {
override fun parse(json: JSONObject): BankAccount {
return BankAccount(
id = StripeJsonUtils.optString(json, FIELD_ID),
accountNumber = null,
accountHolderName = StripeJsonUtils.optString(json, FIELD_ACCOUNT_HOLDER_NAME),
accountHolderType = asBankAccountType(
StripeJsonUtils.optString(json, FIELD_ACCOUNT_HOLDER_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ abstract class ActivityStarter<TargetActivityType : Activity, ArgsType : Activit
requestCode = requestCode
)

@Deprecated("startForResult() requires an args parameter")
fun startForResult() {
startForResult(defaultArgs)
}

fun startForResult(args: ArgsType) {
val intent = Intent(activity, targetClass)
.putExtra(Args.EXTRA, args)
Expand Down
89 changes: 25 additions & 64 deletions stripe/src/test/java/com/stripe/android/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

import org.junit.Before;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -113,33 +112,23 @@ public void testApiVersion() {

@Test
public void constructorShouldFailWithNullPublishableKey() {
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() {
//noinspection ConstantConditions
new Stripe(context, null);
}
assertThrows(IllegalArgumentException.class, () -> {
//noinspection ConstantConditions
new Stripe(context, null);
});
}

@Test
public void constructorShouldFailWithEmptyPublishableKey() {
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() {
new Stripe(context, "");
}
});
assertThrows(IllegalArgumentException.class, () -> new Stripe(context, ""));
}

@Test
public void constructorShouldFailWithSecretKey() {
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() {
new Stripe(context, ApiKeyFixtures.FAKE_SECRET_KEY);
}
});
assertThrows(
IllegalArgumentException.class,
() -> new Stripe(context, ApiKeyFixtures.FAKE_SECRET_KEY))
;
}

@Test
Expand Down Expand Up @@ -389,13 +378,10 @@ public void createSourceSynchronous_withWeChatPayParams_onUnactivatedAccount_thr
"wx65997d6307c3827d",
"WIDGET STORE"
);
final InvalidRequestException ex = assertThrows(InvalidRequestException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
stripe.createSourceSynchronous(weChatPaySourceParams);
}
});
final InvalidRequestException ex = assertThrows(
InvalidRequestException.class,
() -> stripe.createSourceSynchronous(weChatPaySourceParams)
);
assertEquals(
"payment_method_unactivated",
Objects.requireNonNull(ex.getStripeError()).getCode()
Expand Down Expand Up @@ -889,13 +875,9 @@ public void createVisaCheckoutParams_whenUnactivated_throwsException() {
final SourceParams sourceParams = SourceParams.createVisaCheckoutParams(
UUID.randomUUID().toString()
);
final InvalidRequestException ex = assertThrows(InvalidRequestException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
defaultStripe.createSourceSynchronous(sourceParams);
}
}
final InvalidRequestException ex = assertThrows(
InvalidRequestException.class,
() -> defaultStripe.createSourceSynchronous(sourceParams)
);
assertEquals("visa_checkout must be activated before use.", ex.getMessage());
}
Expand All @@ -906,13 +888,9 @@ public void createMasterpassParams_whenUnactivated_throwsException() {
UUID.randomUUID().toString(),
UUID.randomUUID().toString()
);
final InvalidRequestException ex = assertThrows(InvalidRequestException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
defaultStripe.createSourceSynchronous(sourceParams);
}
}
final InvalidRequestException ex = assertThrows(
InvalidRequestException.class,
() -> defaultStripe.createSourceSynchronous(sourceParams)
);
assertEquals("masterpass must be activated before use.", ex.getMessage());
}
Expand Down Expand Up @@ -1053,12 +1031,7 @@ public void createTokenSynchronous_withValidDataAndBadKey_throwsAuthenticationEx
final Stripe stripe = createStripe(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY);
final AuthenticationException authenticationException = assertThrows(
AuthenticationException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
stripe.createCardTokenSynchronous(CARD);
}
}
() -> stripe.createCardTokenSynchronous(CARD)
);
assertEquals("Invalid API Key provided: " + ApiKeyFixtures.FAKE_PUBLISHABLE_KEY,
authenticationException.getMessage());
Expand All @@ -1070,12 +1043,7 @@ public void createTokenSynchronous_withInvalidCardNumber_throwsCardException() {
final Card card = Card.create("42424242", 12, 2050, "123");
final CardException cardException = assertThrows(
CardException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
defaultStripe.createCardTokenSynchronous(card);
}
}
() -> defaultStripe.createCardTokenSynchronous(card)
);
assertEquals("Your card number is incorrect.", cardException.getMessage());
}
Expand All @@ -1084,12 +1052,10 @@ public void run() throws Throwable {
public void retrievePaymentIntent_withInvalidClientSecret_shouldThrowException() {
Locale.setDefault(Locale.GERMANY);

assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
defaultStripe.retrievePaymentIntentSynchronous("invalid");
}
});
assertThrows(
IllegalArgumentException.class,
() -> defaultStripe.retrievePaymentIntentSynchronous("invalid")
);
}

@Test
Expand All @@ -1098,12 +1064,7 @@ public void createTokenSynchronous_withExpiredCard_throwsCardException() {
final Card card = Card.create("4242424242424242", 11, 2015, "123");
final CardException cardException = assertThrows(
CardException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
defaultStripe.createCardTokenSynchronous(card);
}
}
() -> defaultStripe.createCardTokenSynchronous(card)
);
assertEquals("Your card's expiration year is invalid.",
cardException.getMessage());
Expand Down
Loading

0 comments on commit bcdf99a

Please sign in to comment.