diff --git a/stripe/src/main/java/com/stripe/android/Stripe.kt b/stripe/src/main/java/com/stripe/android/Stripe.kt index a5460123f34..94d95583b16 100644 --- a/stripe/src/main/java/com/stripe/android/Stripe.kt +++ b/stripe/src/main/java/com/stripe/android/Stripe.kt @@ -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 - ) { - 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. * diff --git a/stripe/src/main/java/com/stripe/android/model/BankAccount.kt b/stripe/src/main/java/com/stripe/android/model/BankAccount.kt index cbcab6e3ca9..a5e30c51249 100644 --- a/stripe/src/main/java/com/stripe/android/model/BankAccount.kt +++ b/stripe/src/main/java/com/stripe/android/model/BankAccount.kt @@ -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. * @@ -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) @@ -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 { - return BankAccountTokenParams( - country = countryCode.orEmpty(), - currency = currency.orEmpty(), - accountNumber = accountNumber.orEmpty(), - routingNumber = routingNumber, - accountHolderName = accountHolderName, - accountHolderType = BankAccountTokenParams.Type.fromCode(accountHolderType) - ).toParamMap() - } } diff --git a/stripe/src/main/java/com/stripe/android/model/parsers/BankAccountJsonParser.kt b/stripe/src/main/java/com/stripe/android/model/parsers/BankAccountJsonParser.kt index 0040fbca06d..465843ee6c6 100644 --- a/stripe/src/main/java/com/stripe/android/model/parsers/BankAccountJsonParser.kt +++ b/stripe/src/main/java/com/stripe/android/model/parsers/BankAccountJsonParser.kt @@ -9,7 +9,6 @@ internal class BankAccountJsonParser : ModelJsonParser { 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) diff --git a/stripe/src/main/java/com/stripe/android/view/ActivityStarter.kt b/stripe/src/main/java/com/stripe/android/view/ActivityStarter.kt index c93a7f10bf7..6e563155378 100644 --- a/stripe/src/main/java/com/stripe/android/view/ActivityStarter.kt +++ b/stripe/src/main/java/com/stripe/android/view/ActivityStarter.kt @@ -45,11 +45,6 @@ abstract class ActivityStarter { + //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 @@ -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() @@ -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()); } @@ -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()); } @@ -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()); @@ -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()); } @@ -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 @@ -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()); diff --git a/stripe/src/test/java/com/stripe/android/model/BankAccountTest.kt b/stripe/src/test/java/com/stripe/android/model/BankAccountTest.kt deleted file mode 100644 index c87a6125feb..00000000000 --- a/stripe/src/test/java/com/stripe/android/model/BankAccountTest.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.stripe.android.model - -import java.util.UUID -import kotlin.test.Test -import kotlin.test.assertEquals - -/** - * Test class for [BankAccount]. - */ -class BankAccountTest { - - @Test - fun parseSampleAccount_returnsExpectedValue() { - val expectedAccount = BankAccount( - id = "ba_19d8Fh2eZvKYlo2C9qw8RwpV", - accountHolderName = "Jane Austen", - accountHolderType = BankAccount.BankAccountType.INDIVIDUAL, - bankName = "STRIPE TEST BANK", - countryCode = "US", - currency = "usd", - fingerprint = "1JWtPxqbdX5Gamtc", - last4 = "6789", - routingNumber = "110000000", - status = BankAccount.Status.New - ) - assertEquals(expectedAccount, BankAccountFixtures.BANK_ACCOUNT) - } - - @Test - fun createBankTokenParams_hasExpectedEntries() { - val bankAccount = BankAccount(BANK_ACCOUNT_NUMBER, "US", - "usd", BANK_ROUTING_NUMBER) - val bankAccountMap = getBankAccountTokenParamData(bankAccount) - assertEquals(BANK_ACCOUNT_NUMBER, bankAccountMap["account_number"]) - assertEquals(BANK_ROUTING_NUMBER, bankAccountMap["routing_number"]) - assertEquals("US", bankAccountMap["country"]) - assertEquals("usd", bankAccountMap["currency"]) - } - - @Test - fun paramsFromBankAccount_mapsCorrectFields() { - val bankAccount = BankAccount( - accountNumber = BANK_ACCOUNT_NUMBER, - countryCode = "US", - currency = "usd", - routingNumber = BANK_ROUTING_NUMBER, - accountHolderType = BankAccount.BankAccountType.INDIVIDUAL, - accountHolderName = BANK_ACCOUNT_HOLDER_NAME - ) - val bankAccountMap = getBankAccountTokenParamData(bankAccount) - assertEquals(BANK_ACCOUNT_NUMBER, bankAccountMap["account_number"]) - assertEquals(BANK_ROUTING_NUMBER, bankAccountMap["routing_number"]) - assertEquals("US", bankAccountMap["country"]) - assertEquals("usd", bankAccountMap["currency"]) - assertEquals(BANK_ACCOUNT_HOLDER_NAME, bankAccountMap["account_holder_name"]) - assertEquals(BankAccount.BankAccountType.INDIVIDUAL, bankAccountMap["account_holder_type"]) - } - - private fun getBankAccountTokenParamData(bankAccount: BankAccount): Map { - val params = bankAccount.toParamMap().plus(GUID_PARAMS) - return params["bank_account"] as Map - } - - private companion object { - private const val BANK_ACCOUNT_NUMBER = "000123456789" - private const val BANK_ROUTING_NUMBER = "110000000" - private const val BANK_ACCOUNT_HOLDER_NAME = "Lily Thomas" - - private val GUID_PARAMS = mapOf( - "guid" to UUID.randomUUID().toString(), - "muid" to UUID.randomUUID().toString() - ) - } -} diff --git a/stripe/src/test/java/com/stripe/android/model/BankAccountTokenParamsTest.kt b/stripe/src/test/java/com/stripe/android/model/BankAccountTokenParamsTest.kt index b6b48ea9705..f54cf2352f8 100644 --- a/stripe/src/test/java/com/stripe/android/model/BankAccountTokenParamsTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/BankAccountTokenParamsTest.kt @@ -1,27 +1,33 @@ package com.stripe.android.model +import com.google.common.truth.Truth.assertThat import kotlin.test.Test -import kotlin.test.assertEquals class BankAccountTokenParamsTest { @Test fun toParamMap_createsExpectedMap() { - val bankAccountTokenParams = BankAccountTokenParams( + val params = BankAccountTokenParams( accountNumber = BANK_ACCOUNT_NUMBER, country = "US", currency = "usd", routingNumber = BANK_ROUTING_NUMBER, accountHolderType = BankAccountTokenParams.Type.Individual, accountHolderName = BANK_ACCOUNT_HOLDER_NAME - ) - val bankAccountMap = - bankAccountTokenParams.toParamMap()[Token.TokenType.BANK_ACCOUNT] as Map - assertEquals(BANK_ACCOUNT_NUMBER, bankAccountMap["account_number"]) - assertEquals(BANK_ROUTING_NUMBER, bankAccountMap["routing_number"]) - assertEquals("US", bankAccountMap["country"]) - assertEquals("usd", bankAccountMap["currency"]) - assertEquals(BANK_ACCOUNT_HOLDER_NAME, bankAccountMap["account_holder_name"]) - assertEquals(BankAccountTokenParams.Type.Individual.code, bankAccountMap["account_holder_type"]) + ).toParamMap() + + assertThat(params) + .isEqualTo( + mapOf( + "bank_account" to mapOf( + "account_number" to BANK_ACCOUNT_NUMBER, + "routing_number" to BANK_ROUTING_NUMBER, + "country" to "US", + "currency" to "usd", + "account_holder_name" to BANK_ACCOUNT_HOLDER_NAME, + "account_holder_type" to BankAccountTokenParams.Type.Individual.code + ) + ) + ) } private companion object {