Skip to content

Commit e94aab3

Browse files
committed
Remove IntentConfirmationInterceptor interface from CustomerSheetSetupIntentInterceptor
1 parent 698a519 commit e94aab3

File tree

4 files changed

+41
-103
lines changed

4 files changed

+41
-103
lines changed

paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/intent/CustomerSheetConfirmationInterceptor.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ internal class CustomerSheetConfirmationInterceptor @AssistedInject constructor(
6161

6262
setupIntentInterceptor.intercept(
6363
intent = intent,
64-
confirmationOption = PaymentMethodConfirmationOption.Saved(
65-
paymentMethod = paymentMethod,
66-
optionsParams = null,
67-
),
68-
shippingValues = null,
64+
paymentMethod = paymentMethod,
6965
)
7066
}
7167
IntegrationMetadata.CustomerSheet.AttachmentStyle.CreateAttach -> {

paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/intent/CustomerSheetSetupIntentInterceptor.kt

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,35 @@ import com.stripe.android.customersheet.data.CustomerSheetIntentDataSource
88
import com.stripe.android.customersheet.data.fold
99
import com.stripe.android.customersheet.util.CustomerSheetHacks
1010
import com.stripe.android.model.ClientAttributionMetadata
11-
import com.stripe.android.model.ConfirmPaymentIntentParams
12-
import com.stripe.android.model.StripeIntent
11+
import com.stripe.android.model.PaymentMethod
12+
import com.stripe.android.model.SetupIntent
1313
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition
1414
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler
1515
import com.stripe.android.paymentelement.confirmation.PaymentMethodConfirmationOption
1616
import javax.inject.Inject
1717

18-
internal class CustomerSheetSetupIntentInterceptor(
18+
internal interface CustomerSheetSetupIntentInterceptor {
19+
suspend fun intercept(
20+
intent: SetupIntent,
21+
paymentMethod: PaymentMethod
22+
): ConfirmationDefinition.Action<IntentConfirmationDefinition.Args>
23+
24+
interface Factory {
25+
fun create(
26+
clientAttributionMetadata: ClientAttributionMetadata
27+
): CustomerSheetSetupIntentInterceptor
28+
}
29+
}
30+
31+
internal class DefaultCustomerSheetSetupIntentInterceptor(
1932
private val intentDataSourceProvider: Single<CustomerSheetIntentDataSource>,
2033
private val intentFirstConfirmationInterceptorFactory: IntentFirstConfirmationInterceptor.Factory,
2134
private val logger: Logger,
2235
private val clientAttributionMetadata: ClientAttributionMetadata,
23-
) : IntentConfirmationInterceptor {
36+
) : CustomerSheetSetupIntentInterceptor {
2437
override suspend fun intercept(
25-
intent: StripeIntent,
26-
confirmationOption: PaymentMethodConfirmationOption.Saved,
27-
shippingValues: ConfirmPaymentIntentParams.Shipping?
38+
intent: SetupIntent,
39+
paymentMethod: PaymentMethod
2840
): ConfirmationDefinition.Action<IntentConfirmationDefinition.Args> {
2941
return intentDataSourceProvider.await()
3042
.retrieveSetupIntentClientSecret()
@@ -35,15 +47,15 @@ internal class CustomerSheetSetupIntentInterceptor(
3547
.intercept(
3648
intent = intent,
3749
confirmationOption = PaymentMethodConfirmationOption.Saved(
38-
paymentMethod = confirmationOption.paymentMethod,
50+
paymentMethod = paymentMethod,
3951
optionsParams = null,
4052
),
4153
shippingValues = null,
4254
)
4355
},
4456
onFailure = { cause, displayMessage ->
4557
logger.error(
46-
msg = "Failed to attach payment method to SetupIntent: ${confirmationOption.paymentMethod}",
58+
msg = "Failed to attach payment method to SetupIntent: $paymentMethod",
4759
t = cause,
4860
)
4961

@@ -55,28 +67,6 @@ internal class CustomerSheetSetupIntentInterceptor(
5567
}
5668
)
5769
}
58-
59-
override suspend fun intercept(
60-
intent: StripeIntent,
61-
confirmationOption: PaymentMethodConfirmationOption.New,
62-
shippingValues: ConfirmPaymentIntentParams.Shipping?
63-
): ConfirmationDefinition.Action<IntentConfirmationDefinition.Args> {
64-
val error = IllegalStateException(
65-
"Cannot use CustomerSheetSetupIntentInterceptor with new payment methods!"
66-
)
67-
68-
return ConfirmationDefinition.Action.Fail(
69-
errorType = ConfirmationHandler.Result.Failed.ErrorType.Internal,
70-
cause = error,
71-
message = error.stripeErrorMessage()
72-
)
73-
}
74-
75-
interface Factory {
76-
fun create(
77-
clientAttributionMetadata: ClientAttributionMetadata
78-
): IntentConfirmationInterceptor
79-
}
8070
}
8171

8272
internal class DefaultCustomerSheetSetupIntentInterceptorFactory @Inject constructor(
@@ -86,7 +76,7 @@ internal class DefaultCustomerSheetSetupIntentInterceptorFactory @Inject constru
8676
override fun create(
8777
clientAttributionMetadata: ClientAttributionMetadata
8878
): CustomerSheetSetupIntentInterceptor {
89-
return CustomerSheetSetupIntentInterceptor(
79+
return DefaultCustomerSheetSetupIntentInterceptor(
9080
intentDataSourceProvider = CustomerSheetHacks.intentDataSource,
9181
intentFirstConfirmationInterceptorFactory = intentFirstConfirmationInterceptorFactory,
9282
logger = logger,

paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/intent/CustomerSheetConfirmationInterceptorTest.kt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import com.stripe.android.customersheet.FakeStripeRepository
1111
import com.stripe.android.isInstanceOf
1212
import com.stripe.android.lpmfoundations.paymentmethod.IntegrationMetadata
1313
import com.stripe.android.model.ClientAttributionMetadata
14-
import com.stripe.android.model.ConfirmPaymentIntentParams
1514
import com.stripe.android.model.PaymentIntentCreationFlow
1615
import com.stripe.android.model.PaymentMethod
1716
import com.stripe.android.model.PaymentMethodCreateParamsFixtures
1817
import com.stripe.android.model.PaymentMethodFixtures
1918
import com.stripe.android.model.PaymentMethodSelectionFlow
2019
import com.stripe.android.model.SetupIntent
21-
import com.stripe.android.model.StripeIntent
2220
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition
2321
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler
2422
import com.stripe.android.paymentelement.confirmation.PaymentMethodConfirmationOption
@@ -178,7 +176,7 @@ class CustomerSheetConfirmationInterceptorTest {
178176

179177
val interceptCall = createSetupIntentInterceptCalls.awaitItem()
180178
assertThat(interceptCall.intent).isEqualTo(setupIntent)
181-
assertThat(interceptCall.confirmationOption.paymentMethod).isEqualTo(paymentMethod)
179+
assertThat(interceptCall.paymentMethod).isEqualTo(paymentMethod)
182180
}
183181

184182
@Test
@@ -351,7 +349,7 @@ class CustomerSheetConfirmationInterceptorTest {
351349
block: suspend Scenario.() -> Unit,
352350
) = runTest {
353351
val stripeRepository = FakeStripeRepository(paymentMethodCreationResult)
354-
val setupIntentInterceptor = FakeIntentConfirmationInterceptor(setupInterceptAction)
352+
val setupIntentInterceptor = FakeCustomerSheetSetupIntentConfirmationInterceptor(setupInterceptAction)
355353
val attachPaymentMethodInterceptor = FakeCustomerSheetAttachPaymentMethodInterceptor(attachInterceptAction)
356354
val setupIntentInterceptorFactory = FakeSetupIntentInterceptorFactory(setupIntentInterceptor)
357355
val attachPaymentMethodInterceptorFactory =
@@ -387,7 +385,8 @@ class CustomerSheetConfirmationInterceptorTest {
387385
val interceptor: CustomerSheetConfirmationInterceptor,
388386
val createSetupIntentInterceptorFactoryCalls: Turbine<FakeSetupIntentInterceptorFactory.CreateCall>,
389387
val createAttachPaymentMethodInterceptorFactoryCalls: Turbine<Unit>,
390-
val createSetupIntentInterceptCalls: Turbine<FakeIntentConfirmationInterceptor.InterceptCall>,
388+
val createSetupIntentInterceptCalls:
389+
Turbine<FakeCustomerSheetSetupIntentConfirmationInterceptor.InterceptCall>,
391390
val createAttachPaymentMethodInterceptCalls:
392391
Turbine<FakeCustomerSheetAttachPaymentMethodInterceptor.InterceptCall>,
393392
)
@@ -412,53 +411,44 @@ class CustomerSheetConfirmationInterceptorTest {
412411
}
413412

414413
class InterceptCall(
415-
val intent: StripeIntent,
414+
val intent: SetupIntent,
416415
val paymentMethod: PaymentMethod,
417416
)
418417
}
419418

420-
private class FakeIntentConfirmationInterceptor(
419+
private class FakeCustomerSheetSetupIntentConfirmationInterceptor(
421420
private val interceptAction: ConfirmationDefinition.Action<IntentConfirmationDefinition.Args>,
422-
) : IntentConfirmationInterceptor {
421+
) : CustomerSheetSetupIntentInterceptor {
423422
val interceptCalls = Turbine<InterceptCall>()
424423

425424
override suspend fun intercept(
426-
intent: StripeIntent,
427-
confirmationOption: PaymentMethodConfirmationOption.New,
428-
shippingValues: ConfirmPaymentIntentParams.Shipping?
429-
): ConfirmationDefinition.Action<IntentConfirmationDefinition.Args> {
430-
throw IllegalStateException("Should call new payment method path in interceptor tests")
431-
}
432-
433-
override suspend fun intercept(
434-
intent: StripeIntent,
435-
confirmationOption: PaymentMethodConfirmationOption.Saved,
436-
shippingValues: ConfirmPaymentIntentParams.Shipping?
425+
intent: SetupIntent,
426+
paymentMethod: PaymentMethod,
437427
): ConfirmationDefinition.Action<IntentConfirmationDefinition.Args> {
438428
interceptCalls.add(
439429
InterceptCall(
440430
intent = intent,
441-
confirmationOption = confirmationOption,
431+
paymentMethod = paymentMethod,
442432
)
443433
)
444434

445435
return interceptAction
446436
}
447437

448438
class InterceptCall(
449-
val intent: StripeIntent,
450-
val confirmationOption: PaymentMethodConfirmationOption.Saved,
439+
val intent: SetupIntent,
440+
val paymentMethod: PaymentMethod,
451441
)
452442
}
453443

454444
private class FakeSetupIntentInterceptorFactory(
455-
private val interceptor: IntentConfirmationInterceptor
445+
private val interceptor: CustomerSheetSetupIntentInterceptor
456446
) : CustomerSheetSetupIntentInterceptor.Factory {
457447
val createCalls = Turbine<CreateCall>()
458448

459449
override fun create(
460450
clientAttributionMetadata: ClientAttributionMetadata
461-
): IntentConfirmationInterceptor {
451+
): CustomerSheetSetupIntentInterceptor {
462452
createCalls.add(CreateCall(clientAttributionMetadata))
463453

464454
return interceptor

paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/intent/CustomerSheetSetupIntentInterceptorTest.kt

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.stripe.android.model.PaymentMethodFixtures
1414
import com.stripe.android.model.PaymentMethodSelectionFlow
1515
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition
1616
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler
17-
import com.stripe.android.paymentelement.confirmation.PaymentMethodConfirmationOption
1817
import com.stripe.android.testing.FakeLogger
1918
import com.stripe.android.testing.SetupIntentFactory
2019
import kotlinx.coroutines.test.runTest
@@ -35,31 +34,6 @@ class CustomerSheetSetupIntentInterceptorTest {
3534
apiKey = "pk_test_123",
3635
)
3736

38-
@Test
39-
fun `Rejects new payment method confirmation`() = runTest {
40-
val interceptor = createInterceptor()
41-
42-
val result = interceptor.intercept(
43-
intent = SetupIntentFactory.create(),
44-
confirmationOption = PaymentMethodConfirmationOption.New(
45-
createParams = com.stripe.android.model.PaymentMethodCreateParamsFixtures.DEFAULT_CARD,
46-
optionsParams = null,
47-
extraParams = null,
48-
shouldSave = false,
49-
),
50-
shippingValues = null,
51-
)
52-
53-
assertThat(result).isInstanceOf<ConfirmationDefinition.Action.Fail<IntentConfirmationDefinition.Args>>()
54-
55-
val failAction = result as ConfirmationDefinition.Action.Fail
56-
57-
assertThat(failAction.errorType).isEqualTo(ConfirmationHandler.Result.Failed.ErrorType.Internal)
58-
assertThat(failAction.cause).isInstanceOf<IllegalStateException>()
59-
assertThat(failAction.cause.message)
60-
.isEqualTo("Cannot use CustomerSheetSetupIntentInterceptor with new payment methods!")
61-
}
62-
6337
@Test
6438
fun `Successfully creates and confirms setup intent`() = runTest {
6539
val paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD
@@ -77,11 +51,7 @@ class CustomerSheetSetupIntentInterceptorTest {
7751

7852
val result = interceptor.intercept(
7953
intent = setupIntent,
80-
confirmationOption = PaymentMethodConfirmationOption.Saved(
81-
paymentMethod = paymentMethod,
82-
optionsParams = null,
83-
),
84-
shippingValues = null,
54+
paymentMethod = paymentMethod,
8555
)
8656

8757
assertThat(result).isInstanceOf<ConfirmationDefinition.Action.Launch<*>>()
@@ -107,11 +77,7 @@ class CustomerSheetSetupIntentInterceptorTest {
10777

10878
val result = interceptor.intercept(
10979
intent = SetupIntentFactory.create(),
110-
confirmationOption = PaymentMethodConfirmationOption.Saved(
111-
paymentMethod = paymentMethod,
112-
optionsParams = null,
113-
),
114-
shippingValues = null,
80+
paymentMethod = paymentMethod,
11581
)
11682

11783
assertThat(result).isInstanceOf<ConfirmationDefinition.Action.Fail<IntentConfirmationDefinition.Args>>()
@@ -144,11 +110,7 @@ class CustomerSheetSetupIntentInterceptorTest {
144110

145111
interceptor.intercept(
146112
intent = SetupIntentFactory.create(),
147-
confirmationOption = PaymentMethodConfirmationOption.Saved(
148-
paymentMethod = paymentMethod,
149-
optionsParams = null,
150-
),
151-
shippingValues = null,
113+
paymentMethod = paymentMethod,
152114
)
153115

154116
assertThat(logger.errorLogs).hasSize(1)
@@ -159,7 +121,7 @@ class CustomerSheetSetupIntentInterceptorTest {
159121
intentDataSource: CustomerSheetIntentDataSource = FakeCustomerSheetIntentDataSource(),
160122
logger: Logger = FakeLogger(),
161123
): CustomerSheetSetupIntentInterceptor {
162-
return CustomerSheetSetupIntentInterceptor(
124+
return DefaultCustomerSheetSetupIntentInterceptor(
163125
intentDataSourceProvider = { intentDataSource },
164126
intentFirstConfirmationInterceptorFactory = FakeIntentFirstConfirmationInterceptorFactory(requestOptions),
165127
logger = logger,

0 commit comments

Comments
 (0)