STPPaymentHandler
public class STPPaymentHandler : NSObject
extension STPPaymentHandler: SFSafariViewControllerDelegate
STPPaymentHandler
is a utility class that confirms PaymentIntents/SetupIntents and handles any authentication required, such as 3DS1/3DS2 for Strong Customer Authentication.
It can present authentication UI on top of your app or redirect users out of your app (to e.g. their banking app).
-
The error domain for errors in
STPPaymentHandler
.Declaration
Swift
@objc public static let errorDomain: String
-
The globally shared instance of
STPPaymentHandler
.Declaration
Swift
@objc public static let sharedHandler: STPPaymentHandler
-
The globally shared instance of
STPPaymentHandler
.Declaration
Swift
@objc public class func shared() -> STPPaymentHandler
-
By default
sharedHandler
initializes with STPAPIClient.shared.Declaration
Swift
public var apiClient: STPAPIClient
-
By default
sharedHandler
initializes with STPAPIClient.shared.Declaration
Swift
@available(swift, deprecated: 0.0.1, renamed: "apiClient") @objc(apiClient) public var _objc_apiClient: _stpobjc_STPAPIClient { get set }
-
Customizable settings to use when performing 3DS2 authentication. Note: Configure this before calling any methods. Defaults to
STPThreeDSCustomizationSettings()
.Declaration
Swift
@objc public var threeDSCustomizationSettings: STPThreeDSCustomizationSettings
-
When this flag is enabled, STPPaymentHandler will confirm certain PaymentMethods using Safari instead of SFSafariViewController. If you’d like to use this in your own testing or Continuous Integration platform, please see the IntegrationTester app for usage examples.
Note: This flag is only intended for development, and only impacts payments made with testmode keys. Setting this to
true
with a livemode key will fail.Declaration
Swift
@objc public var simulateAppToAppRedirect: Bool { get set }
-
Confirms the PaymentIntent with the provided parameters and handles any
nextAction
required to authenticate the PaymentIntent. Call this method if you are using automatic confirmation. - seealso:https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=customDeclaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) @objc(confirmPayment:withAuthenticationContext:completion:) public func confirmPayment( _ paymentParams: STPPaymentIntentParams, with authenticationContext: STPAuthenticationContext, completion: @escaping STPPaymentHandlerActionPaymentIntentCompletionBlock )
Parameters
paymentParams
The params used to confirm the PaymentIntent. Note that this method overrides the value of
paymentParams.useStripeSDK
to@YES
.authenticationContext
The authentication context used to authenticate the payment.
completion
The completion block. If the status returned is
STPPaymentHandlerActionStatusSucceeded
, the PaymentIntent status is not necessarily STPPaymentIntentStatusSucceeded (e.g. some bank payment methods take days before the PaymentIntent succeeds). -
Handles any
nextAction
required to authenticate the PaymentIntent. Call this method if you are using manual confirmation. - seealso: https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=customDeclaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) @objc(handleNextActionForPayment:withAuthenticationContext:returnURL:completion:) public func handleNextAction( forPayment paymentIntentClientSecret: String, with authenticationContext: STPAuthenticationContext, returnURL: String?, completion: @escaping STPPaymentHandlerActionPaymentIntentCompletionBlock )
Parameters
paymentIntentClientSecret
The client secret of the PaymentIntent to handle next actions for.
authenticationContext
The authentication context used to authenticate the payment.
returnURL
An optional URL to redirect your customer back to after they authenticate or cancel in a webview. This should match the returnURL you specified during PaymentIntent confirmation.
completion
The completion block. If the status returned is
STPPaymentHandlerActionStatusSucceeded
, the PaymentIntent status will always be either STPPaymentIntentStatusSucceeded, or STPPaymentIntentStatusRequiresConfirmation, or STPPaymentIntentStatusRequiresCapture if you are using manual capture. In the latter two cases, confirm or capture the PaymentIntent on your backend to complete the payment. -
Confirms the SetupIntent with the provided parameters and handles any
nextAction
required to authenticate the SetupIntent.Declaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) @objc(confirmSetupIntent:withAuthenticationContext:completion:) public func confirmSetupIntent( _ setupIntentConfirmParams: STPSetupIntentConfirmParams, with authenticationContext: STPAuthenticationContext, completion: @escaping STPPaymentHandlerActionSetupIntentCompletionBlock )
Parameters
setupIntentConfirmParams
The params used to confirm the SetupIntent. Note that this method overrides the value of
setupIntentConfirmParams.useStripeSDK
to@YES
.authenticationContext
The authentication context used to authenticate the SetupIntent.
completion
The completion block. If the status returned is
STPPaymentHandlerActionStatusSucceeded
, the SetupIntent status will always be STPSetupIntentStatusSucceeded. -
Handles any
nextAction
required to authenticate the SetupIntent. Call this method if you are confirming the SetupIntent on your backend and get a status of requires_action.Declaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) @objc(handleNextActionForSetupIntent:withAuthenticationContext:returnURL:completion:) public func handleNextAction( forSetupIntent setupIntentClientSecret: String, with authenticationContext: STPAuthenticationContext, returnURL: String?, completion: @escaping STPPaymentHandlerActionSetupIntentCompletionBlock )
Parameters
setupIntentClientSecret
The client secret of the SetupIntent to handle next actions for.
authenticationContext
The authentication context used to authenticate the SetupIntent.
returnURL
An optional URL to redirect your customer back to after they authenticate or cancel in a webview. This should match the returnURL you specified during SetupIntent confirmation.
completion
The completion block. If the status returned is
STPPaymentHandlerActionStatusSucceeded
, the SetupIntent status will always be STPSetupIntentStatusSucceeded.