When your user is ready to pay (e.g., they tap the Buy button) call
requestPayment on your payment context. It displays any required UI (such as the Apple Pay dialog) and calls the appropriate methods on its delegate as your user finishes their payment.
This method is called when the customer has successfully selected a payment method. Submit the payment to Stripe using a Payment Intent. Stripe uses this payment object to track and handle all the states of the payment until the payment completes.
On your server, make an endpoint that creates a
PaymentIntent with an amount and currency and returns its client secret to your client.
Always decide how much to charge on the server side, a trusted environment, as opposed to the client. This prevents malicious customers from being able to choose their own prices.
On the client, implement this delegate method to:
- Request a
PaymentIntent from your server.
- Assemble a STPPaymentIntentParams object with the
PaymentIntent client secret from your server and the paymentMethod provided by the delegate method.
- Call the STPPaymentHandler confirmPayment method to confirm the payment, passing the
STPPaymentContext as the authenticationContext.
You must call the provided
completion block with the appropriate
.error, or .
userCancellation) when the customer’s payment is finished.
This method is called after the previous method, when any auxiliary UI that has been displayed (such as the Apple Pay dialog) has been dismissed. You should inspect the returned
status and show an appropriate message to your user. For example:
This method is called in the rare case that the payment context’s initial loading call fails, usually due to lack of internet connectivity. You should dismiss your checkout page when this occurs and invite the user to try again. You can also optionally attempt to try again by calling
retryLoading on the payment context.