Skip to content

[Feature] Expose STPPaymentHandler Initializer to configure APIClient dynamically #5241

@woohyunjin06

Description

@woohyunjin06

Is your feature request related to a problem? Please describe.

Our app supports multiple regions, and each region requires a different Stripe publishableKey.
To support this, we need to configure STPAPIClient dynamically at runtime.

In the case of Apple Pay, we’re able to set STPApplePayContext.apiClient after initialization.

let context = STPApplePayContext(
  paymentRequest: paymentRequest,
  delegate: delegate
)
context?.apiClient = STPAPIClient(publishableKey: publishableKey)

However, during the confirm setup intent flow, we need to inject a new STPAPIClient with a different publishableKey into STPPaymentHandler.
The problem is that STPPaymentHandler does not expose a public initializer, so we can’t pass in a custom API client.

We’re using @_spi(STP) import Stripe to access the internal initializer, which works — but is it OK to use in production for now?

Describe the solution you'd like

We’d like the initializer for STPPaymentHandler that accepts a custom STPAPIClient to be made public

Describe alternatives you've considered

  • Relying on @_spi(STP) access
  • Mutating STPPaymentHandler.shared().apiClient, which is unsafe in concurrent scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:improvementtriagedIssue has been reviewed by Stripe and is being tracked internally

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions