STPPaymentOptionsViewControllerDelegate
@protocol STPPaymentOptionsViewControllerDelegate <NSObject>
An STPPaymentOptionsViewControllerDelegate
responds when a user selects a
payment option from (or cancels) an STPPaymentOptionsViewController
. In both
of these instances, you should dismiss the view controller (either by popping
it off the navigation stack, or dismissing it).
-
This is called when the view controller encounters an error fetching the user’s payment options from its API adapter. You should dismiss the view controller when this is called.
Declaration
Objective-C
- (void)paymentOptionsViewController:(nonnull STPPaymentOptionsViewController *) paymentOptionsViewController didFailToLoadWithError:(nonnull NSError *)error;
Swift
func paymentOptionsViewController(_ paymentOptionsViewController: STPPaymentOptionsViewController, didFailToLoadWithError error: Error)
Parameters
paymentOptionsViewController
the view controller in question
error
the error that occurred
-
This is called when the user selects or adds a payment method, so it will often be called immediately after calling
paymentOptionsViewController:didSelectPaymentOption:
. You should dismiss the view controller when this is called.Declaration
Objective-C
- (void)paymentOptionsViewControllerDidFinish: (nonnull STPPaymentOptionsViewController *)paymentOptionsViewController;
Swift
func paymentOptionsViewControllerDidFinish(_ paymentOptionsViewController: STPPaymentOptionsViewController)
Parameters
paymentOptionsViewController
the view controller that has finished
-
This is called when the user taps “cancel”. You should dismiss the view controller when this is called.
Declaration
Objective-C
- (void)paymentOptionsViewControllerDidCancel: (nonnull STPPaymentOptionsViewController *)paymentOptionsViewController;
Swift
func paymentOptionsViewControllerDidCancel(_ paymentOptionsViewController: STPPaymentOptionsViewController)
Parameters
paymentOptionsViewController
the view controller that has finished
-
This is called when the user either makes a selection, or adds a new card. This will be triggered after the view controller loads with the user’s current selection (if they have one) and then subsequently when they change their choice. You should use this callback to update any necessary UI in your app that displays the user’s currently selected payment method. You should not dismiss the view controller at this point, instead do this in
paymentOptionsViewControllerDidFinish:
.STPPaymentOptionsViewController
will also call the necessary methods on your API adapter, so you don’t need to call them directly during this method.Declaration
Objective-C
- (void)paymentOptionsViewController:(nonnull STPPaymentOptionsViewController *) paymentOptionsViewController didSelectPaymentOption: (nonnull id<STPPaymentOption>)paymentOption;
Swift
optional func paymentOptionsViewController(_ paymentOptionsViewController: STPPaymentOptionsViewController, didSelect paymentOption: STPPaymentOption)
Parameters
paymentOptionsViewController
the view controller in question
paymentOption
the selected payment method