Creating a payment using Sources with the iOS SDK is a multi-step process:
- Create an STPSource object that represents your customer’s payment method.
- Check if further action is required from your customer.
If no further action is required:
- Confirm the source is ready to use.
- Create a charge request on your backend using the source.
If further action is required:
- Present the user with any information they may need to authorize the charge.
- On your backend, listen to Stripe webhooks to create a charge with the source.
- In your app, display the appropriate confirmation to your customer based on the source’s status.
Redirect your customer to authorize a source
For sources that require redirecting your customer to authorize the payment, you need to specify a return URL when you create the source. This allows your customer to be redirected back to your app after they authorize the payment. For this return URL, you can either use a custom URL scheme or a universal link supported by your app. For more information on registering and handling URLs in your app, refer to the Apple documentation:
To handle redirecting your customer to the URL in the source object’s
redirect.url parameter, we recommend using
STPRedirectContext, which you can use to open the URL in
SFSafariViewController, if available, or mobile Safari otherwise. To use
STPRedirectContext, you’ll need to first set up your app delegate to forward URLs to the Stripe SDK.
STPRedirectContext’s completion block is called after your customer returns to your app. At this point, the user may or may not have completed the authorization process. You can use webhooks on your own server to receive notification of a change in status of the source’s chargeable state. See best practices for more information on how to build a confirmation screen when using sources.
If you’d like more help, check out the example app that demonstrates creating a payment using several different payment methods.