STPPaymentOptionsViewController
public class STPPaymentOptionsViewController: STPCoreViewController,
STPPaymentOptionsInternalViewControllerDelegate, STPAddCardViewControllerDelegate
This view controller presents a list of payment method options to the user,
which they can select between. They can also add credit cards to the list.
It must be displayed inside a UINavigationController
, so you can either
create a UINavigationController
with an STPPaymentOptionsViewController
as the rootViewController
and then present the UINavigationController
,
or push a new STPPaymentOptionsViewController
onto an existing
UINavigationController
‘s stack. You can also have STPPaymentContext
do this
for you automatically, by calling presentPaymentOptionsViewController
or pushPaymentOptionsViewController
on it.
-
Creates a new payment methods view controller.
Declaration
Swift
@objc(initWithPaymentContext:) public convenience init(paymentContext: STPPaymentContext)
Parameters
paymentContext
A payment context to power the view controller’s view. The payment context will in turn use its backend API adapter to fetch the information it needs from your application.
Return Value
an initialized view controller.
-
Initializes a new payment methods view controller without using a payment context.
Declaration
Swift
@objc(initWithConfiguration:theme:customerContext:delegate:) public convenience init( configuration: STPPaymentConfiguration, theme: STPTheme, customerContext: STPCustomerContext, delegate: STPPaymentOptionsViewControllerDelegate )
Parameters
configuration
The configuration to use to determine what types of payment method to offer your user. - seealso: STPPaymentConfiguration.h
theme
The theme to inform the appearance of the UI.
customerContext
The customer context the view controller will use to fetch and modify its Stripe customer
delegate
A delegate that will be notified when the payment methods view controller’s selection changes.
Return Value
an initialized view controller.
-
Note: Instead of providing your own backend API adapter, we recommend using
STPCustomerContext
, which will manage retrieving and updating a Stripe customer for you. - seealso: STPCustomerContext.h Initializes a new payment methods view controller without using a payment context.Declaration
Swift
@objc(initWithConfiguration:theme:apiAdapter:delegate:) public init( configuration: STPPaymentConfiguration, theme: STPTheme, apiAdapter: STPBackendAPIAdapter, delegate: STPPaymentOptionsViewControllerDelegate )
Parameters
configuration
The configuration to use to determine what types of payment method to offer your user.
theme
The theme to inform the appearance of the UI.
apiAdapter
The API adapter to use to retrieve a customer’s stored payment methods and save new ones.
delegate
A delegate that will be notified when the payment methods view controller’s selection changes.
-
If you’ve already collected some information from your user, you can set it here and it’ll be automatically filled out when possible/appropriate in any UI that the payment context creates.
Declaration
Swift
@objc public var prefilledInformation: STPUserInformation?
-
@note This is no longer recommended as of v18.3.0 - the SDK automatically saves the Stripe ID of the last selected payment method using NSUserDefaults and displays it as the default pre-selected option. You can override this behavior by setting this property. The Stripe ID of a payment method to display as the default pre-selected option. @note Setting this after the view controller’s view has loaded has no effect.
Declaration
Swift
@objc public var defaultPaymentMethod: String?
-
A view that will be placed as the footer of the view controller when it is showing a list of saved payment methods to select from. When the footer view needs to be resized, it will be sent a
sizeThatFits:
call. The view should respond correctly to this method in order to be sized and positioned properly.Declaration
Swift
@objc public var paymentOptionsViewControllerFooterView: UIView?
-
A view that will be placed as the footer of the view controller when it is showing the add card view. When the footer view needs to be resized, it will be sent a
sizeThatFits:
call. The view should respond correctly to this method in order to be sized and positioned properly.Declaration
Swift
@objc public var addCardViewControllerFooterView: UIView?
-
The API Client to use to make requests. Defaults to STPAPIClient.shared
Declaration
Swift
@objc public var apiClient: STPAPIClient
-
If you’re pushing
STPPaymentOptionsViewController
onto an existingUINavigationController
‘s stack, you should use this method to dismiss it, since it may have pushed an additional add card view controller onto the navigation controller’s stack.Declaration
Swift
@objc(dismissWithCompletion:) public func dismiss(withCompletion completion: STPVoidBlock?)
Parameters
completion
The callback to run after the view controller is dismissed. You may specify nil for this parameter.
-
Declaration
Swift
@objc public func addCardViewControllerDidCancel( _ addCardViewController: STPAddCardViewController )
-
Declaration
Swift
@objc public func addCardViewController( _ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock )