STPPaymentMethodsViewControllerDelegate
@protocol STPPaymentMethodsViewControllerDelegate <NSObject>
An STPPaymentMethodsViewControllerDelegate
responds when a user selects a
payment method from (or cancels) an STPPaymentMethodsViewController
. 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 methods from its API adapter. You should dismiss the view controller when this is called.
Declaration
Objective-C
- (void)paymentMethodsViewController:(nonnull STPPaymentMethodsViewController *) paymentMethodsViewController didFailToLoadWithError:(nonnull NSError *)error;
Swift
func paymentMethodsViewController(_ paymentMethodsViewController: STPPaymentMethodsViewController, didFailToLoadWithError error: Error)
Parameters
paymentMethodsViewController
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
paymentMethodsViewController:didSelectPaymentMethod:
. You should dismiss the view controller when this is called.Declaration
Objective-C
- (void)paymentMethodsViewControllerDidFinish: (nonnull STPPaymentMethodsViewController *)paymentMethodsViewController;
Swift
func paymentMethodsViewControllerDidFinish(_ paymentMethodsViewController: STPPaymentMethodsViewController)
Parameters
paymentMethodsViewController
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)paymentMethodsViewControllerDidCancel: (nonnull STPPaymentMethodsViewController *)paymentMethodsViewController;
Swift
func paymentMethodsViewControllerDidCancel(_ paymentMethodsViewController: STPPaymentMethodsViewController)
Parameters
paymentMethodsViewController
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
paymentMethodsViewControllerDidFinish:
.STPPaymentMethodsViewController
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)paymentMethodsViewController:(nonnull STPPaymentMethodsViewController *) paymentMethodsViewController didSelectPaymentMethod: (nonnull id<STPPaymentMethod>)paymentMethod;
Swift
optional func paymentMethodsViewController(_ paymentMethodsViewController: STPPaymentMethodsViewController, didSelect paymentMethod: STPPaymentMethod)
Parameters
paymentMethodsViewController
the view controller in question
paymentMethod
the selected payment method