Skip to content

Commit

Permalink
Remove publishable key from CustomerRepository (#7146)
Browse files Browse the repository at this point in the history
* Remove publishable key from CustomerRepository
  • Loading branch information
jameswoo-stripe authored and fionnbarrett-stripe committed Aug 17, 2023
1 parent fae7ef2 commit ca96453
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.stripe.android.testing

import com.stripe.android.cards.Bin
import com.stripe.android.core.exception.APIException
import com.stripe.android.core.model.StripeFile
import com.stripe.android.core.model.StripeFileParams
import com.stripe.android.core.networking.ApiRequest
Expand Down Expand Up @@ -153,31 +152,25 @@ abstract class AbsFakeStripeRepository : StripeRepository {
TODO("Not yet implemented")
}

@Throws(APIException::class)
override suspend fun attachPaymentMethod(
customerId: String,
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
): Result<PaymentMethod> {
TODO("Not yet implemented")
}

@Throws(APIException::class)
override suspend fun detachPaymentMethod(
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
): Result<PaymentMethod> {
TODO("Not yet implemented")
}

@Throws(APIException::class)
override suspend fun getPaymentMethods(
listPaymentMethodsParams: ListPaymentMethodsParams,
publishableKey: String,
productUsageTokens: Set<String>,
requestOptions: ApiRequest.Options
): Result<List<PaymentMethod>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ internal class CustomerSessionOperationExecutor(
is EphemeralOperation.Customer.AttachPaymentMethod -> {
val result = stripeRepository.attachPaymentMethod(
customerId = ephemeralKey.objectId,
publishableKey = publishableKey,
productUsageTokens = operation.productUsage,
paymentMethodId = operation.paymentMethodId,
requestOptions = ApiRequest.Options(ephemeralKey.secret, stripeAccountId),
Expand All @@ -93,7 +92,6 @@ internal class CustomerSessionOperationExecutor(
}
is EphemeralOperation.Customer.DetachPaymentMethod -> {
val result = stripeRepository.detachPaymentMethod(
publishableKey = publishableKey,
productUsageTokens = operation.productUsage,
paymentMethodId = operation.paymentMethodId,
requestOptions = ApiRequest.Options(ephemeralKey.secret, stripeAccountId),
Expand All @@ -120,7 +118,6 @@ internal class CustomerSessionOperationExecutor(
endingBefore = operation.endingBefore,
startingAfter = operation.startingAfter,
),
publishableKey = publishableKey,
productUsageTokens = operation.productUsage,
requestOptions = ApiRequest.Options(ephemeralKey.secret, stripeAccountId),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ class StripeApiRepository @JvmOverloads internal constructor(
*/
override suspend fun attachPaymentMethod(
customerId: String,
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
Expand Down Expand Up @@ -665,7 +664,6 @@ class StripeApiRepository @JvmOverloads internal constructor(
CardException::class
)
override suspend fun detachPaymentMethod(
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
Expand All @@ -690,7 +688,6 @@ class StripeApiRepository @JvmOverloads internal constructor(
*/
override suspend fun getPaymentMethods(
listPaymentMethodsParams: ListPaymentMethodsParams,
publishableKey: String,
productUsageTokens: Set<String>,
requestOptions: ApiRequest.Options
): Result<List<PaymentMethod>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ interface StripeRepository {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
suspend fun attachPaymentMethod(
customerId: String,
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
): Result<PaymentMethod>

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
suspend fun detachPaymentMethod(
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
Expand All @@ -162,7 +160,6 @@ interface StripeRepository {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
suspend fun getPaymentMethods(
listPaymentMethodsParams: ListPaymentMethodsParams,
publishableKey: String,
productUsageTokens: Set<String>,
requestOptions: ApiRequest.Options
): Result<List<PaymentMethod>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ internal class CustomerSessionOperationExecutorTest {
object : AbsFakeStripeRepository() {
override suspend fun attachPaymentMethod(
customerId: String,
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
Expand Down Expand Up @@ -79,7 +78,6 @@ internal class CustomerSessionOperationExecutorTest {
object : AbsFakeStripeRepository() {
override suspend fun attachPaymentMethod(
customerId: String,
publishableKey: String,
productUsageTokens: Set<String>,
paymentMethodId: String,
requestOptions: ApiRequest.Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,26 @@ internal class CustomerSessionTest {

whenever(
stripeRepository.attachPaymentMethod(
any(),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any(),
any()
customerId = any(),
productUsageTokens = any(),
paymentMethodId = any(),
requestOptions = any()
)
).thenReturn(Result.success(PAYMENT_METHOD))

whenever(
stripeRepository.detachPaymentMethod(
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any(),
any()
productUsageTokens = any(),
paymentMethodId = any(),
requestOptions = any()
)
).thenReturn(Result.success(PAYMENT_METHOD))

whenever(
stripeRepository.getPaymentMethods(
any(),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any()
listPaymentMethodsParams = any(),
productUsageTokens = any(),
requestOptions = any()
)
).thenReturn(Result.success(listOf(PAYMENT_METHOD)))

Expand Down Expand Up @@ -165,11 +162,10 @@ internal class CustomerSessionTest {
idleLooper()

verify(stripeRepository).attachPaymentMethod(
any(),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
eq(DEFAULT_PRODUCT_USAGE),
any(),
any()
customerId = any(),
productUsageTokens = eq(DEFAULT_PRODUCT_USAGE),
paymentMethodId = any(),
requestOptions = any()
)
}

Expand Down Expand Up @@ -569,11 +565,10 @@ internal class CustomerSessionTest {

assertNotNull(FIRST_CUSTOMER.id)
verify(stripeRepository).attachPaymentMethod(
eq(FIRST_CUSTOMER.id.orEmpty()),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
eq(expectedProductUsage),
eq("pm_abc123"),
requestOptionsArgumentCaptor.capture()
customerId = eq(FIRST_CUSTOMER.id.orEmpty()),
productUsageTokens = eq(expectedProductUsage),
paymentMethodId = eq("pm_abc123"),
requestOptions = requestOptionsArgumentCaptor.capture()
)
assertEquals(
EphemeralKeyFixtures.FIRST.secret,
Expand Down Expand Up @@ -640,10 +635,9 @@ internal class CustomerSessionTest {

assertNotNull(FIRST_CUSTOMER.id)
verify(stripeRepository).detachPaymentMethod(
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
eq(expectedProductUsage),
eq("pm_abc123"),
requestOptionsArgumentCaptor.capture()
productUsageTokens = eq(expectedProductUsage),
paymentMethodId = eq("pm_abc123"),
requestOptions = requestOptionsArgumentCaptor.capture()
)
assertEquals(
EphemeralKeyFixtures.FIRST.secret,
Expand Down Expand Up @@ -705,15 +699,14 @@ internal class CustomerSessionTest {

assertNotNull(FIRST_CUSTOMER.id)
verify(stripeRepository).getPaymentMethods(
eq(
listPaymentMethodsParams = eq(
ListPaymentMethodsParams(
customerId = FIRST_CUSTOMER.id.orEmpty(),
paymentMethodType = PaymentMethod.Type.Card
)
),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
eq(expectedProductUsage),
requestOptionsArgumentCaptor.capture()
productUsageTokens = eq(expectedProductUsage),
requestOptions = requestOptionsArgumentCaptor.capture()
)
assertEquals(
EphemeralKeyFixtures.FIRST.secret,
Expand Down Expand Up @@ -765,33 +758,30 @@ internal class CustomerSessionTest {

whenever(
stripeRepository.attachPaymentMethod(
any(),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any(),
any()
customerId = any(),
productUsageTokens = any(),
paymentMethodId = any(),
requestOptions = any()
)
).thenReturn(
Result.failure(APIException(statusCode = 404, message = "The payment method is invalid"))
)

whenever(
stripeRepository.detachPaymentMethod(
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any(),
any()
productUsageTokens = any(),
paymentMethodId = any(),
requestOptions = any()
)
).thenReturn(
Result.failure(APIException(statusCode = 404, message = "The payment method does not exist"))
)

whenever(
stripeRepository.getPaymentMethods(
any(),
eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY),
any(),
any()
listPaymentMethodsParams = any(),
productUsageTokens = any(),
requestOptions = any()
)
).thenReturn(
Result.failure(APIException(statusCode = 404, message = "The payment method does not exist"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,13 +1031,12 @@ internal class StripeApiRepositoryTest {
val stripeApiRepository = create()
val paymentMethods = stripeApiRepository
.getPaymentMethods(
ListPaymentMethodsParams(
listPaymentMethodsParams = ListPaymentMethodsParams(
"cus_123",
PaymentMethod.Type.Card
),
DEFAULT_OPTIONS.apiKey,
emptySet(),
ApiRequest.Options(ApiKeyFixtures.FAKE_EPHEMERAL_KEY)
productUsageTokens = emptySet(),
requestOptions = ApiRequest.Options(ApiKeyFixtures.FAKE_EPHEMERAL_KEY)
).getOrThrow()
assertThat(paymentMethods)
.hasSize(3)
Expand Down Expand Up @@ -1089,13 +1088,12 @@ internal class StripeApiRepositoryTest {
val stripeApiRepository = create()
val paymentMethods = stripeApiRepository
.getPaymentMethods(
ListPaymentMethodsParams(
listPaymentMethodsParams = ListPaymentMethodsParams(
"cus_123",
PaymentMethod.Type.Card
),
DEFAULT_OPTIONS.apiKey,
emptySet(),
ApiRequest.Options(ApiKeyFixtures.FAKE_EPHEMERAL_KEY)
productUsageTokens = emptySet(),
requestOptions = ApiRequest.Options(ApiKeyFixtures.FAKE_EPHEMERAL_KEY)
).getOrThrow()
assertThat(paymentMethods)
.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.stripe.android.paymentsheet.injection.IS_FLOW_CONTROLLER
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.ui.core.forms.resources.LpmRepository
import dagger.Binds
import dagger.Lazy
import dagger.Module
import dagger.Provides
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.stripe.android.paymentsheet.repositories.CustomerRepository
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Lazy
import dagger.Module
import dagger.Provides
import java.util.Calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ internal class CustomerApiRepository @Inject constructor(
customerId = customerConfig.id,
paymentMethodType = paymentMethodType,
),
publishableKey = lazyPaymentConfig.get().publishableKey,
productUsageTokens = productUsageTokens,
requestOptions = ApiRequest.Options(
apiKey = customerConfig.ephemeralKeySecret,
Expand Down Expand Up @@ -91,7 +90,6 @@ internal class CustomerApiRepository @Inject constructor(
paymentMethodId: String
): Result<PaymentMethod> =
stripeRepository.detachPaymentMethod(
publishableKey = lazyPaymentConfig.get().publishableKey,
productUsageTokens = productUsageTokens,
paymentMethodId = paymentMethodId,
requestOptions = ApiRequest.Options(
Expand All @@ -108,7 +106,6 @@ internal class CustomerApiRepository @Inject constructor(
): Result<PaymentMethod> =
stripeRepository.attachPaymentMethod(
customerId = customerConfig.id,
publishableKey = lazyPaymentConfig.get().publishableKey,
productUsageTokens = productUsageTokens,
paymentMethodId = paymentMethodId,
requestOptions = ApiRequest.Options(
Expand Down
Loading

0 comments on commit ca96453

Please sign in to comment.