Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal user key auth support to PaymentSheet #4481

Merged
merged 6 commits into from
Dec 17, 2021

Conversation

lng-stripe
Copy link
Contributor

@lng-stripe lng-stripe commented Dec 17, 2021

Summary

Add uk support to PaymentSheet similar to what currently exists in the iOS SDK:

1. Using `uk` requires `Stripe-Livemode` header to be set
2. APIClient has to `retrieve` w/ different params, no client secret with a `uk`
3. APIClient has to `confirm` w/ different params, no client secret with a `uk`
4. PaymentSheet must create PM first, then confirm

Motivation

Parity with iOS SDK.

Testing

  • Added tests
  • Modified tests
  • Manually verified

return ConfirmPaymentIntentParams(
clientSecret = clientSecret,
paymentMethodId = paymentMethodId,
paymentMethodOptions = PaymentMethodOptionsParams.Card(moto = true),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

@@ -105,6 +105,9 @@ data class ApiRequest internal constructor(
internal val idempotencyKey: String? = null
) : Parcelable {

internal val apiKeyIsUserKey: Boolean
get() = apiKey.startsWith("uk_")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

@@ -64,6 +65,13 @@ internal sealed class RequestHeadersFactory {
HEADER_AUTHORIZATION to "Bearer ${options.apiKey}"
).plus(
stripeClientUserAgentHeaderFactory.create(appInfo)
).plus(
if (options.apiKeyIsUserKey) {
val isLiveMode = Os.getenv("Stripe-Livemode") != "false"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

@@ -186,11 +187,25 @@ internal class StripeApiRepository @JvmOverloads internal constructor(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
options: ApiRequest.Options,
expandFields: List<String>
): PaymentIntent? {
return confirmPaymentIntentInternal(
confirmPaymentIntentParams = confirmPaymentIntentParams.maybeForDashboard(options),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

confirmPaymentIntentParams.toParamMap(),
confirmPaymentIntentParams.toParamMap()
// Omit client_secret with user key auth.
.let { if (options.apiKeyIsUserKey) it.minus(PARAM_CLIENT_SECRET) else it },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

@@ -1137,6 +1160,9 @@ internal class StripeApiRepository @JvmOverloads internal constructor(
parser: PaymentMethodPreferenceJsonParser<T>,
analyticsEvent: PaymentAnalyticsEvent
): T? {
// Unsupported for user key sessions.
if (options.apiKeyIsUserKey) return null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS

@lng-stripe lng-stripe marked this pull request as ready for review December 17, 2021 03:52
@michelleb-stripe michelleb-stripe self-assigned this Dec 17, 2021
@lng-stripe lng-stripe merged commit ebd0616 into master Dec 17, 2021
@lng-stripe lng-stripe deleted the lng/payment-sheet-user-key-support branch December 17, 2021 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants