When using automatic confirmation, create the PaymentIntent at the beginning of the checkout process. When using manual confirmation, create the PaymentIntent after collecting payment information from the customer using Elements or our iOS and Android SDKs. For a detailed comparison on the automatic and manual confirmation flows, see accepting one-time payments.
Step 3: Authenticate the payment if necessary
Pass the confirmed Payment Intent client secret from the previous step to STPPaymentHandler handleNextActionForPayment. If the customer must perform 3D Secure authentication to complete the payment, STPPaymentHandler presents view controllers using the STPAuthenticationContext passed in and walks them through that process. See Supporting 3D Secure Authentication on iOS to learn more.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
MyAPIClient.createAndConfirmPaymentIntent(paymentMethodId: paymentMethodId) { result in guardcase .success(let paymentIntentClientSecret) = result else { // Handle error return } STPPaymentHandler.shared().handleNextAction(forPayment: paymentIntentClientSecret, with: self, returnURL: nil) { (status, paymentIntent, error) in switch (status) { case .succeeded: // ...Continued in Step 4 case .canceled: // Handle cancel case .failed: // Handle error } } }
Use the Setup Intents API to authenticate a customer’s card without making an initial payment. This flow works best for businesses that want to onboard customers without charging them right away:
Step 4: Submit the card details to Stripe from the client
Pass the STPSetupIntentParams object to the confirmSetupIntent method on a STPPaymentHandler sharedManager. If the customer must perform additional steps to complete the payment, such as authentication, STPPaymentHandler presents view controllers using the STPAuthenticationContext passed in and walks them through that process. See Supporting 3D Secure Authentication on iOS to learn more.
1 2 3 4 5 6 7 8 9 10 11 12 13
let setupIntentParams = STPSetupIntentParams(clientSecret: clientSecret) setupIntentParams.paymentMethodId = paymentMethodId let paymentManager = STPPaymentHandler.shared() paymentManager.confirmSetupIntent(setupIntentParams, authenticationContext: self, completion { (status, setupIntent, error) in switch (status) { case .succeeded: // Setup succeeded case .canceled: // Handle cancel case .failed: // Handle error } })
- (BOOL)_canPresentWithAuthenticationContext:(id<STPAuthenticationContext>)authenticationContext { UIViewController *presentingViewController = authenticationContext.authenticationPresentingViewController; // Is presentingViewController non-nil and in the window? if (presentingViewController == nil || presentingViewController.view.window == nil) { returnNO; } // Is it the Apple Pay VC? if ([presentingViewController isKindOfClass:[PKPaymentAuthorizationViewController class]]) { // We can't present over Apple Pay, user must implement prepareAuthenticationContextForPresentation: to dismiss it. return [authenticationContext respondsToSelector:@selector(prepareAuthenticationContextForPresentation:)]; } // Is it already presenting something? if (presentingViewController.presentedViewController == nil) { returnYES; } else { // Hopefully the user implemented prepareAuthenticationContextForPresentation: to dismiss it. return [authenticationContext respondsToSelector:@selector(prepareAuthenticationContextForPresentation:)]; } }
Use stripe SDK
STPSetupIntentConfirmParams.useStripeSDK
A boolean number to indicate whether you intend to use the Stripe SDK’s functionality to handle any SetupIntent next actions. If set to false, STPSetupIntent.nextAction will only ever contain a redirect url that can be opened in a webview or mobile browser. When set to true, the nextAction may contain information that the Stripe SDK can use to perform native authentication within your app.
1 2
let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: clientSecret) setupIntentParams.useStripeSDK = NSNumber(booleanLiteral: true)