From a2ab60cdaf98667e62edde77928f68ea83834a2e Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Fri, 17 Apr 2020 17:53:18 -0700 Subject: [PATCH 1/8] Add stripe account param to confirmPayment --- example/res/layout/payment_auth_activity.xml | 7 +++++ example/res/values/strings.xml | 1 + .../example/activity/PaymentAuthActivity.kt | 28 +++++++++++++------ .../android/PaymentAuthWebViewStarter.kt | 3 +- .../com/stripe/android/PaymentController.kt | 7 +++-- .../com/stripe/android/PaymentRelayStarter.kt | 14 ++++++---- .../main/java/com/stripe/android/Stripe.kt | 8 ++++-- .../stripe/android/StripePaymentController.kt | 24 ++++++++++++---- .../PaymentAuthWebViewActivityViewModel.kt | 3 +- .../view/Stripe3ds2CompletionActivity.kt | 4 ++- 10 files changed, 73 insertions(+), 26 deletions(-) diff --git a/example/res/layout/payment_auth_activity.xml b/example/res/layout/payment_auth_activity.xml index ba9a99ae774..e68ef3d6531 100644 --- a/example/res/layout/payment_auth_activity.xml +++ b/example/res/layout/payment_auth_activity.xml @@ -21,6 +21,13 @@ style="?android:attr/progressBarStyleHorizontal" /> + + SetupIntent status: %s Tapping the button below will create a PaymentIntent then attempt to confirm it. Tapping the button below will create a SetupIntent then attempt to confirm it. + [Optional] Connect account ID Ready to charge? Not selected diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index f8f7575817c..4ee327c8aae 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -71,10 +71,10 @@ class PaymentAuthActivity : AppCompatActivity() { } viewBinding.confirmWith3ds1Button.setOnClickListener { - createPaymentIntent(stripeAccountId, ConfirmationType.ThreeDS1) + createPaymentIntent(getAccount(), ConfirmationType.ThreeDS1) } viewBinding.confirmWith3ds2Button.setOnClickListener { - createPaymentIntent(stripeAccountId, ConfirmationType.ThreeDS2) + createPaymentIntent(getAccount(), ConfirmationType.ThreeDS2) } viewBinding.confirmWithNewCardButton.setOnClickListener { @@ -82,7 +82,7 @@ class PaymentAuthActivity : AppCompatActivity() { keyboardController.hide() createPaymentIntent( - stripeAccountId, + getAccount(), ConfirmationType.NewCard ) } @@ -91,9 +91,19 @@ class PaymentAuthActivity : AppCompatActivity() { viewBinding.setupButton.setOnClickListener { createSetupIntent() } } + private fun getAccount(): String? { + val connectAccount = viewBinding.stripeAccount.text.toString() + return if (connectAccount.isNotBlank()) { + connectAccount + } else { + Settings(this).stripeAccountId + } + } + private fun confirmPaymentIntent( paymentIntentClientSecret: String, - confirmationType: ConfirmationType + confirmationType: ConfirmationType, + stripeAccountId: String? ) { viewBinding.status.append("\n\nStarting payment authentication") stripe.confirmPayment( @@ -109,7 +119,8 @@ class PaymentAuthActivity : AppCompatActivity() { clientSecret = paymentIntentClientSecret, shipping = SHIPPING ) - } + }, + stripeAccountId ) } @@ -162,7 +173,7 @@ class PaymentAuthActivity : AppCompatActivity() { viewBinding.status.setText(R.string.creating_payment_intent) } .subscribe( - { handleCreatePaymentIntentResponse(it, confirmationType) }, + { handleCreatePaymentIntentResponse(it, confirmationType, stripeAccountId) }, { handleError(it) } ) ) @@ -200,14 +211,15 @@ class PaymentAuthActivity : AppCompatActivity() { private fun handleCreatePaymentIntentResponse( responseBody: ResponseBody, - confirmationType: ConfirmationType + confirmationType: ConfirmationType, + stripeAccountId: String? ) { try { val responseData = JSONObject(responseBody.string()) viewBinding.status.append("\n\n" + getString(R.string.payment_intent_status, responseData.getString("status"))) val secret = responseData.getString("secret") - confirmPaymentIntent(secret, confirmationType) + confirmPaymentIntent(secret, confirmationType, stripeAccountId) } catch (e: IOException) { e.printStackTrace() } catch (e: JSONException) { diff --git a/stripe/src/main/java/com/stripe/android/PaymentAuthWebViewStarter.kt b/stripe/src/main/java/com/stripe/android/PaymentAuthWebViewStarter.kt index 3c2939f817a..1ab65cacc18 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentAuthWebViewStarter.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentAuthWebViewStarter.kt @@ -29,7 +29,8 @@ internal class PaymentAuthWebViewStarter internal constructor( val url: String, val returnUrl: String? = null, val enableLogging: Boolean = false, - val toolbarCustomization: StripeToolbarCustomization? = null + val toolbarCustomization: StripeToolbarCustomization? = null, + val stripeAccountId: String? = null ) : Parcelable internal companion object { diff --git a/stripe/src/main/java/com/stripe/android/PaymentController.kt b/stripe/src/main/java/com/stripe/android/PaymentController.kt index 11ab4a71a87..5b1464849e1 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentController.kt @@ -107,7 +107,8 @@ internal interface PaymentController { internal val exception: StripeException? = null, internal val shouldCancelSource: Boolean = false, internal val sourceId: String? = null, - internal val source: Source? = null + internal val source: Source? = null, + internal val stripeAccountId: String? = null ) : Parcelable { @JvmSynthetic fun toBundle(): Bundle { @@ -124,7 +125,8 @@ internal interface PaymentController { exception = parcel.readSerializable() as? StripeException?, shouldCancelSource = parcel.readInt() == 1, sourceId = parcel.readString(), - source = parcel.readParcelable(Source::class.java.classLoader) + source = parcel.readParcelable(Source::class.java.classLoader), + stripeAccountId = parcel.readString() ) } @@ -135,6 +137,7 @@ internal interface PaymentController { parcel.writeInt(1.takeIf { shouldCancelSource } ?: 0) parcel.writeString(sourceId) parcel.writeParcelable(source, flags) + parcel.writeString(stripeAccountId) } private const val EXTRA = "extra_args" diff --git a/stripe/src/main/java/com/stripe/android/PaymentRelayStarter.kt b/stripe/src/main/java/com/stripe/android/PaymentRelayStarter.kt index efb723e69bf..cc0e971ea86 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentRelayStarter.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentRelayStarter.kt @@ -28,7 +28,8 @@ internal interface PaymentRelayStarter : AuthActivityStarter { @JvmSynthetic - internal fun create(stripeIntent: StripeIntent): Args { - return Args(stripeIntent = stripeIntent) + internal fun create(stripeIntent: StripeIntent, stripeAccountId: String? = null): Args { + return Args(stripeIntent = stripeIntent, stripeAccountId = stripeAccountId) } @JvmSynthetic @@ -64,7 +66,8 @@ internal interface PaymentRelayStarter : AuthActivityStarter // authentication type is not supported - bypassAuth(host, stripeIntent) + bypassAuth(host, stripeIntent, requestOptions.stripeAccount) } } StripeIntent.NextActionType.RedirectToUrl -> { @@ -437,22 +438,27 @@ internal class StripePaymentController internal constructor( getRequestCode(stripeIntent), stripeIntent.clientSecret.orEmpty(), redirectData?.url.toString(), + requestOptions.stripeAccount, redirectData?.returnUrl, enableLogging = enableLogging ) } else -> // next action type is not supported, so bypass authentication - bypassAuth(host, stripeIntent) + bypassAuth(host, stripeIntent, requestOptions.stripeAccount) } } else { // no action required, so bypass authentication - bypassAuth(host, stripeIntent) + bypassAuth(host, stripeIntent, requestOptions.stripeAccount) } } - private fun bypassAuth(host: AuthActivityStarter.Host, stripeIntent: StripeIntent) { + private fun bypassAuth( + host: AuthActivityStarter.Host, + stripeIntent: StripeIntent, + stripeAccountId: String? + ) { PaymentRelayStarter.create(host, getRequestCode(stripeIntent)) - .start(PaymentRelayStarter.Args.create(stripeIntent)) + .start(PaymentRelayStarter.Args.create(stripeIntent, stripeAccountId)) } private fun bypassAuth(host: AuthActivityStarter.Host, source: Source) { @@ -480,6 +486,10 @@ internal class StripePaymentController internal constructor( Stripe3ds2CompletionActivity.EXTRA_CLIENT_SECRET, stripeIntent.clientSecret ) + .putExtra( + Stripe3ds2CompletionActivity.EXTRA_STRIPE_ACCOUNT, + requestOptions.stripeAccount + ) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT), challengeCompletionRequestCode = getRequestCode(stripeIntent) ) @@ -609,6 +619,7 @@ internal class StripePaymentController internal constructor( getRequestCode(stripeIntent), stripeIntent.clientSecret.orEmpty(), result.fallbackRedirectUrl, + requestOptions.stripeAccount, enableLogging = enableLogging ) } else { @@ -927,13 +938,14 @@ internal class StripePaymentController internal constructor( requestCode: Int, clientSecret: String, authUrl: String, + stripeAccount: String?, returnUrl: String? = null, enableLogging: Boolean = false ) { Logger.getInstance(enableLogging).debug("PaymentAuthWebViewStarter#start()") val starter = PaymentAuthWebViewStarter(host, requestCode) starter.start( - PaymentAuthWebViewStarter.Args(clientSecret, authUrl, returnUrl, enableLogging) + PaymentAuthWebViewStarter.Args(clientSecret, authUrl, returnUrl, enableLogging, stripeAccountId = stripeAccount) ) } diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentAuthWebViewActivityViewModel.kt b/stripe/src/main/java/com/stripe/android/view/PaymentAuthWebViewActivityViewModel.kt index 98870ef2bae..b0cb1609d1f 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentAuthWebViewActivityViewModel.kt +++ b/stripe/src/main/java/com/stripe/android/view/PaymentAuthWebViewActivityViewModel.kt @@ -34,7 +34,8 @@ internal class PaymentAuthWebViewActivityViewModel( get() { return PaymentController.Result( clientSecret = args.clientSecret, - sourceId = Uri.parse(args.url).lastPathSegment.orEmpty() + sourceId = Uri.parse(args.url).lastPathSegment.orEmpty(), + stripeAccountId = args.stripeAccountId ) } diff --git a/stripe/src/main/java/com/stripe/android/view/Stripe3ds2CompletionActivity.kt b/stripe/src/main/java/com/stripe/android/view/Stripe3ds2CompletionActivity.kt index a98d3650ce9..c33caffd0cc 100644 --- a/stripe/src/main/java/com/stripe/android/view/Stripe3ds2CompletionActivity.kt +++ b/stripe/src/main/java/com/stripe/android/view/Stripe3ds2CompletionActivity.kt @@ -41,7 +41,8 @@ class Stripe3ds2CompletionActivity : AppCompatActivity() { super.onCreate(savedInstanceState) val result = PaymentController.Result( clientSecret = intent.getStringExtra(EXTRA_CLIENT_SECRET), - flowOutcome = flowOutcome + flowOutcome = flowOutcome, + stripeAccountId = intent.getStringExtra(EXTRA_STRIPE_ACCOUNT) ) LocalBroadcastManager.getInstance(this) @@ -56,6 +57,7 @@ class Stripe3ds2CompletionActivity : AppCompatActivity() { internal companion object { const val EXTRA_CLIENT_SECRET = "extra_client_secret" + const val EXTRA_STRIPE_ACCOUNT = "extra_stripe_account" private const val UNKNOWN_FLOW_OUTCOME = -1 } } From 9ed4428c8e51ae26ff367365eee8d52582918259 Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Mon, 20 Apr 2020 11:52:52 -0700 Subject: [PATCH 2/8] Convert getAccount to property --- .../example/activity/PaymentAuthActivity.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index 4ee327c8aae..6c13289b191 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -71,10 +71,10 @@ class PaymentAuthActivity : AppCompatActivity() { } viewBinding.confirmWith3ds1Button.setOnClickListener { - createPaymentIntent(getAccount(), ConfirmationType.ThreeDS1) + createPaymentIntent(account, ConfirmationType.ThreeDS1) } viewBinding.confirmWith3ds2Button.setOnClickListener { - createPaymentIntent(getAccount(), ConfirmationType.ThreeDS2) + createPaymentIntent(account, ConfirmationType.ThreeDS2) } viewBinding.confirmWithNewCardButton.setOnClickListener { @@ -82,7 +82,7 @@ class PaymentAuthActivity : AppCompatActivity() { keyboardController.hide() createPaymentIntent( - getAccount(), + account, ConfirmationType.NewCard ) } @@ -91,14 +91,15 @@ class PaymentAuthActivity : AppCompatActivity() { viewBinding.setupButton.setOnClickListener { createSetupIntent() } } - private fun getAccount(): String? { - val connectAccount = viewBinding.stripeAccount.text.toString() - return if (connectAccount.isNotBlank()) { - connectAccount - } else { - Settings(this).stripeAccountId + private val account: String? + get() { + val connectAccount = viewBinding.stripeAccount.text.toString() + return if (connectAccount.isNotBlank()) { + connectAccount + } else { + Settings(this).stripeAccountId + } } - } private fun confirmPaymentIntent( paymentIntentClientSecret: String, From 148c404d4b42db4b5918db2ca2f8236bcb230b30 Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Mon, 20 Apr 2020 11:55:17 -0700 Subject: [PATCH 3/8] Add stripeAccountId param to confirmPayment fragment version --- stripe/src/main/java/com/stripe/android/Stripe.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stripe/src/main/java/com/stripe/android/Stripe.kt b/stripe/src/main/java/com/stripe/android/Stripe.kt index 8db6468bb13..59d417e0fc9 100644 --- a/stripe/src/main/java/com/stripe/android/Stripe.kt +++ b/stripe/src/main/java/com/stripe/android/Stripe.kt @@ -154,11 +154,15 @@ class Stripe internal constructor( * * @param fragment the `Fragment` that is launching the payment authentication flow * @param confirmPaymentIntentParams [ConfirmPaymentIntentParams] used to confirm the [PaymentIntent] + * @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. */ + @JvmOverloads @UiThread fun confirmPayment( fragment: Fragment, - confirmPaymentIntentParams: ConfirmPaymentIntentParams + confirmPaymentIntentParams: ConfirmPaymentIntentParams, + stripeAccountId: String? = this.stripeAccountId ) { paymentController.startConfirmAndAuth( AuthActivityStarter.Host.create(fragment), From 1963b3ec47f7cff32615885e33018b090c7a1a2a Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Mon, 20 Apr 2020 12:01:13 -0700 Subject: [PATCH 4/8] Construct ApiRequest.Options inside handlePaymentResult --- .../main/java/com/stripe/android/PaymentController.kt | 1 - stripe/src/main/java/com/stripe/android/Stripe.kt | 9 +-------- .../java/com/stripe/android/StripePaymentController.kt | 8 ++++++-- .../java/com/stripe/android/StripePaymentAuthTest.kt | 4 +--- .../com/stripe/android/StripePaymentControllerTest.kt | 4 ++-- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/PaymentController.kt b/stripe/src/main/java/com/stripe/android/PaymentController.kt index 5b1464849e1..7bfa7682e07 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentController.kt @@ -57,7 +57,6 @@ internal interface PaymentController { */ fun handlePaymentResult( data: Intent, - requestOptions: ApiRequest.Options, callback: ApiResultCallback ) diff --git a/stripe/src/main/java/com/stripe/android/Stripe.kt b/stripe/src/main/java/com/stripe/android/Stripe.kt index 59d417e0fc9..4558bcab868 100644 --- a/stripe/src/main/java/com/stripe/android/Stripe.kt +++ b/stripe/src/main/java/com/stripe/android/Stripe.kt @@ -288,14 +288,7 @@ class Stripe internal constructor( callback: ApiResultCallback ): Boolean { return if (data != null && paymentController.shouldHandlePaymentResult(requestCode, data)) { - paymentController.handlePaymentResult( - data, - ApiRequest.Options( - apiKey = publishableKey, - stripeAccount = PaymentController.Result.fromIntent(data)?.stripeAccountId - ), - callback - ) + paymentController.handlePaymentResult(data, callback) true } else { false diff --git a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt index 87ba0484030..40e443593b8 100644 --- a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt @@ -42,7 +42,7 @@ import kotlinx.coroutines.Dispatchers */ internal class StripePaymentController internal constructor( context: Context, - publishableKey: String, + private val publishableKey: String, private val stripeRepository: StripeRepository, private val enableLogging: Boolean = false, private val messageVersionRegistry: MessageVersionRegistry = @@ -195,7 +195,6 @@ internal class StripePaymentController internal constructor( */ override fun handlePaymentResult( data: Intent, - requestOptions: ApiRequest.Options, callback: ApiResultCallback ) { val result = PaymentController.Result.fromIntent(data) ?: PaymentController.Result() @@ -209,6 +208,11 @@ internal class StripePaymentController internal constructor( val sourceId = result.sourceId.orEmpty() @StripeIntentResult.Outcome val flowOutcome = result.flowOutcome + val requestOptions = ApiRequest.Options( + apiKey = publishableKey, + stripeAccount = result.stripeAccountId + ) + stripeRepository.retrieveIntent( getClientSecret(data), requestOptions, diff --git a/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt b/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt index f53c510a01d..e88aef0ebb4 100644 --- a/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt @@ -103,9 +103,7 @@ class StripePaymentAuthTest { stripe.onPaymentResult(StripePaymentController.PAYMENT_REQUEST_CODE, data, callback = paymentCallback) - verify(paymentController).handlePaymentResult(data, - ApiRequest.Options(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY), - paymentCallback) + verify(paymentController).handlePaymentResult(data, paymentCallback) } @Test diff --git a/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt b/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt index 032ba48b714..88455fbf80b 100644 --- a/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt @@ -513,7 +513,7 @@ class StripePaymentControllerTest { ).toBundle() ) - controller.handlePaymentResult(intent, REQUEST_OPTIONS, paymentAuthResultCallback) + controller.handlePaymentResult(intent, paymentAuthResultCallback) verify(paymentAuthResultCallback).onError(exception) verify(paymentAuthResultCallback, never()) .onSuccess(anyOrNull()) @@ -657,7 +657,7 @@ class StripePaymentControllerTest { ) createController(stripeRepository) - .handlePaymentResult(intent, REQUEST_OPTIONS, paymentAuthResultCallback) + .handlePaymentResult(intent, paymentAuthResultCallback) verify(stripeRepository).retrieveIntent( eq(clientSecret), From 675d3db0e35e445fa43ea756b0d6be033e2da2e5 Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Mon, 20 Apr 2020 15:29:44 -0700 Subject: [PATCH 5/8] Add stripe account param to confirmSetupIntent --- .../example/activity/PaymentAuthActivity.kt | 6 +++--- .../java/com/stripe/android/PaymentController.kt | 1 - stripe/src/main/java/com/stripe/android/Stripe.kt | 15 ++++++--------- .../com/stripe/android/StripePaymentController.kt | 6 +++++- .../com/stripe/android/StripePaymentAuthTest.kt | 4 +--- .../stripe/android/StripePaymentControllerTest.kt | 4 ++-- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index 6c13289b191..8387e255426 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -106,7 +106,7 @@ class PaymentAuthActivity : AppCompatActivity() { confirmationType: ConfirmationType, stripeAccountId: String? ) { - viewBinding.status.append("\n\nStarting payment authentication") + viewBinding.status.append("\n\nStarting payment authentication for $stripeAccountId") stripe.confirmPayment( this, when (confirmationType) { @@ -126,8 +126,8 @@ class PaymentAuthActivity : AppCompatActivity() { } private fun confirmSetupIntent(setupIntentClientSecret: String) { - viewBinding.status.append("\n\nStarting setup intent authentication") - stripe.confirmSetupIntent(this, create3ds2SetupIntentParams(setupIntentClientSecret)) + viewBinding.status.append("\n\nStarting setup intent authentication for $account") + stripe.confirmSetupIntent(this, create3ds2SetupIntentParams(setupIntentClientSecret), account) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/stripe/src/main/java/com/stripe/android/PaymentController.kt b/stripe/src/main/java/com/stripe/android/PaymentController.kt index 7bfa7682e07..81b85b6ebe1 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentController.kt @@ -71,7 +71,6 @@ internal interface PaymentController { */ fun handleSetupResult( data: Intent, - requestOptions: ApiRequest.Options, callback: ApiResultCallback ) diff --git a/stripe/src/main/java/com/stripe/android/Stripe.kt b/stripe/src/main/java/com/stripe/android/Stripe.kt index 4558bcab868..cac3029363d 100644 --- a/stripe/src/main/java/com/stripe/android/Stripe.kt +++ b/stripe/src/main/java/com/stripe/android/Stripe.kt @@ -363,10 +363,14 @@ class Stripe internal constructor( * Confirm and, if necessary, authenticate a [SetupIntent]. * * @param activity the `Activity` that is launching the payment authentication flow + * @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. */ + @JvmOverloads fun confirmSetupIntent( activity: Activity, - confirmSetupIntentParams: ConfirmSetupIntentParams + confirmSetupIntentParams: ConfirmSetupIntentParams, + stripeAccountId: String? = this.stripeAccountId ) { paymentController.startConfirmAndAuth( AuthActivityStarter.Host.create(activity), @@ -509,14 +513,7 @@ class Stripe internal constructor( callback: ApiResultCallback ): Boolean { return if (data != null && paymentController.shouldHandleSetupResult(requestCode, data)) { - paymentController.handleSetupResult( - data, - ApiRequest.Options( - apiKey = publishableKey, - stripeAccount = stripeAccountId - ), - callback - ) + paymentController.handleSetupResult(data, callback) true } else { false diff --git a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt index 40e443593b8..838aa6cc4f0 100644 --- a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt @@ -234,7 +234,6 @@ internal class StripePaymentController internal constructor( */ override fun handleSetupResult( data: Intent, - requestOptions: ApiRequest.Options, callback: ApiResultCallback ) { val result = PaymentController.Result.fromIntent(data) ?: PaymentController.Result() @@ -248,6 +247,11 @@ internal class StripePaymentController internal constructor( val sourceId = result.sourceId.orEmpty() @StripeIntentResult.Outcome val flowOutcome = result.flowOutcome + val requestOptions = ApiRequest.Options( + apiKey = publishableKey, + stripeAccount = result.stripeAccountId + ) + stripeRepository.retrieveIntent( getClientSecret(data), requestOptions, diff --git a/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt b/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt index e88aef0ebb4..95c41a06e3d 100644 --- a/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripePaymentAuthTest.kt @@ -116,9 +116,7 @@ class StripePaymentAuthTest { stripe.onSetupResult(StripePaymentController.SETUP_REQUEST_CODE, data, callback = setupCallback) - verify(paymentController).handleSetupResult(data, - ApiRequest.Options(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY), - setupCallback) + verify(paymentController).handleSetupResult(data, setupCallback) } private fun createStripe(): Stripe { diff --git a/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt b/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt index 88455fbf80b..77febcdd792 100644 --- a/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripePaymentControllerTest.kt @@ -528,7 +528,7 @@ class StripePaymentControllerTest { ).toBundle() ) - controller.handleSetupResult(intent, REQUEST_OPTIONS, setupAuthResultCallback) + controller.handleSetupResult(intent, setupAuthResultCallback) verify(setupAuthResultCallback).onError(exception) verify(setupAuthResultCallback, never()) @@ -546,7 +546,7 @@ class StripePaymentControllerTest { ).toBundle() ) - controller.handleSetupResult(intent, REQUEST_OPTIONS, setupAuthResultCallback) + controller.handleSetupResult(intent, setupAuthResultCallback) verify(setupAuthResultCallback).onSuccess(setupIntentResultArgumentCaptor.capture()) val result = setupIntentResultArgumentCaptor.firstValue From 2406bb73511ddaddcfc7c88a6ec23b2c517b79b9 Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Tue, 21 Apr 2020 11:52:20 -0700 Subject: [PATCH 6/8] Don't print account if null --- .../java/com/stripe/example/activity/PaymentAuthActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index 8387e255426..1a97f024973 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -106,7 +106,7 @@ class PaymentAuthActivity : AppCompatActivity() { confirmationType: ConfirmationType, stripeAccountId: String? ) { - viewBinding.status.append("\n\nStarting payment authentication for $stripeAccountId") + viewBinding.status.append("\n\nStarting payment authentication${stripeAccountId?.let { " for $it" }.orEmpty()}") stripe.confirmPayment( this, when (confirmationType) { @@ -126,7 +126,7 @@ class PaymentAuthActivity : AppCompatActivity() { } private fun confirmSetupIntent(setupIntentClientSecret: String) { - viewBinding.status.append("\n\nStarting setup intent authentication for $account") + viewBinding.status.append("\n\nStarting setup intent authentication for${account?.let { " for $it" }.orEmpty()}") stripe.confirmSetupIntent(this, create3ds2SetupIntentParams(setupIntentClientSecret), account) } From a2a9e97bba007c5010af2fccd47013f1de6be073 Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Tue, 21 Apr 2020 15:11:06 -0700 Subject: [PATCH 7/8] Revert changes to example app --- example/res/layout/payment_auth_activity.xml | 7 ----- example/res/values/strings.xml | 1 - .../example/activity/PaymentAuthActivity.kt | 29 +++++-------------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/example/res/layout/payment_auth_activity.xml b/example/res/layout/payment_auth_activity.xml index e68ef3d6531..ba9a99ae774 100644 --- a/example/res/layout/payment_auth_activity.xml +++ b/example/res/layout/payment_auth_activity.xml @@ -21,13 +21,6 @@ style="?android:attr/progressBarStyleHorizontal" /> - - SetupIntent status: %s Tapping the button below will create a PaymentIntent then attempt to confirm it. Tapping the button below will create a SetupIntent then attempt to confirm it. - [Optional] Connect account ID Ready to charge? Not selected diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index 6c13289b191..f8f7575817c 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -71,10 +71,10 @@ class PaymentAuthActivity : AppCompatActivity() { } viewBinding.confirmWith3ds1Button.setOnClickListener { - createPaymentIntent(account, ConfirmationType.ThreeDS1) + createPaymentIntent(stripeAccountId, ConfirmationType.ThreeDS1) } viewBinding.confirmWith3ds2Button.setOnClickListener { - createPaymentIntent(account, ConfirmationType.ThreeDS2) + createPaymentIntent(stripeAccountId, ConfirmationType.ThreeDS2) } viewBinding.confirmWithNewCardButton.setOnClickListener { @@ -82,7 +82,7 @@ class PaymentAuthActivity : AppCompatActivity() { keyboardController.hide() createPaymentIntent( - account, + stripeAccountId, ConfirmationType.NewCard ) } @@ -91,20 +91,9 @@ class PaymentAuthActivity : AppCompatActivity() { viewBinding.setupButton.setOnClickListener { createSetupIntent() } } - private val account: String? - get() { - val connectAccount = viewBinding.stripeAccount.text.toString() - return if (connectAccount.isNotBlank()) { - connectAccount - } else { - Settings(this).stripeAccountId - } - } - private fun confirmPaymentIntent( paymentIntentClientSecret: String, - confirmationType: ConfirmationType, - stripeAccountId: String? + confirmationType: ConfirmationType ) { viewBinding.status.append("\n\nStarting payment authentication") stripe.confirmPayment( @@ -120,8 +109,7 @@ class PaymentAuthActivity : AppCompatActivity() { clientSecret = paymentIntentClientSecret, shipping = SHIPPING ) - }, - stripeAccountId + } ) } @@ -174,7 +162,7 @@ class PaymentAuthActivity : AppCompatActivity() { viewBinding.status.setText(R.string.creating_payment_intent) } .subscribe( - { handleCreatePaymentIntentResponse(it, confirmationType, stripeAccountId) }, + { handleCreatePaymentIntentResponse(it, confirmationType) }, { handleError(it) } ) ) @@ -212,15 +200,14 @@ class PaymentAuthActivity : AppCompatActivity() { private fun handleCreatePaymentIntentResponse( responseBody: ResponseBody, - confirmationType: ConfirmationType, - stripeAccountId: String? + confirmationType: ConfirmationType ) { try { val responseData = JSONObject(responseBody.string()) viewBinding.status.append("\n\n" + getString(R.string.payment_intent_status, responseData.getString("status"))) val secret = responseData.getString("secret") - confirmPaymentIntent(secret, confirmationType, stripeAccountId) + confirmPaymentIntent(secret, confirmationType) } catch (e: IOException) { e.printStackTrace() } catch (e: JSONException) { From 1028b34a38a3a62025785d7d8373829408d8518d Mon Sep 17 00:00:00 2001 From: Samuel Maskell Date: Tue, 21 Apr 2020 15:13:36 -0700 Subject: [PATCH 8/8] Revert changes to example app --- .../java/com/stripe/example/activity/PaymentAuthActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt index 856760b7080..f8f7575817c 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentAuthActivity.kt @@ -95,7 +95,7 @@ class PaymentAuthActivity : AppCompatActivity() { paymentIntentClientSecret: String, confirmationType: ConfirmationType ) { - viewBinding.status.append("\n\nStarting payment authentication${stripeAccountId?.let { " for $it" }.orEmpty()}") + viewBinding.status.append("\n\nStarting payment authentication") stripe.confirmPayment( this, when (confirmationType) { @@ -114,8 +114,8 @@ class PaymentAuthActivity : AppCompatActivity() { } private fun confirmSetupIntent(setupIntentClientSecret: String) { - viewBinding.status.append("\n\nStarting setup intent authentication for${account?.let { " for $it" }.orEmpty()}") - stripe.confirmSetupIntent(this, create3ds2SetupIntentParams(setupIntentClientSecret), account) + viewBinding.status.append("\n\nStarting setup intent authentication") + stripe.confirmSetupIntent(this, create3ds2SetupIntentParams(setupIntentClientSecret)) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {