STPApplePayContext
@available(iOSApplicationExtension, unavailable)
@available(macCatalystApplicationExtension, unavailable)
@objc
public class STPApplePayContext : NSObject, PKPaymentAuthorizationControllerDelegate
A helper class that implements Apple Pay. Usage looks like this:
- Initialize this class with a PKPaymentRequest describing the payment request (amount, line items, required shipping info, etc)
- Call presentApplePayOnViewController:completion: to present the Apple Pay sheet and begin the payment process 3 (optional): If you need to respond to the user changing their shipping information/shipping method, implement the optional delegate methods
- When the user taps ‘Buy’, this class uses the PaymentIntent that you supply in the applePayContext:didCreatePaymentMethod:completion: delegate method to complete the payment
- After payment completes/errors and the sheet is dismissed, this class informs you in the applePayContext:didCompleteWithStatus: delegate method
Seealso
https://stripe.com/docs/apple-pay#native for a full guideSeealso
ApplePayExampleViewController for an example-
Initializes this class. @note This may return nil if the request is invalid e.g. the user is restricted by parental controls, or can’t make payments on any of the request’s supported networks
Declaration
Swift
@objc(initWithPaymentRequest:delegate:) public required init?(paymentRequest: PKPaymentRequest, delegate: STPApplePayContextDelegate?)
Parameters
paymentRequest
The payment request to use with Apple Pay.
delegate
The delegate.
-
Presents the Apple Pay sheet from the specified view controller, starting the payment process. @note This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay. @deprecated A presenting UIViewController is no longer needed. Use presentApplePay(completion:) instead.
Declaration
Swift
@available(*, deprecated, renamed: "presentApplePay(completion:﹚", message: "Use `presentApplePay(completion:﹚` instead.") @objc(presentApplePayOnViewController:completion:) public func presentApplePay(on viewController: UIViewController, completion: STPVoidBlock? = nil)
Parameters
viewController
The UIViewController instance to present the Apple Pay sheet on
completion
Called after the Apple Pay sheet is presented
-
Presents the Apple Pay sheet from the key window, starting the payment process. @note This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
Declaration
Swift
@available(iOSApplicationExtension, unavailable, message: "Use `presentApplePay(from:completion:﹚` in App Extensions.") @available(macCatalystApplicationExtension, unavailable, message: "Use `presentApplePay(from:completion:﹚` in App Extensions.") @objc(presentApplePayWithCompletion:) public func presentApplePay(completion: STPVoidBlock? = nil)
Parameters
completion
Called after the Apple Pay sheet is presented
-
Presents the Apple Pay sheet from the specified window, starting the payment process. @note This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
Declaration
Swift
@objc(presentApplePayFromWindow:withCompletion:) public func presentApplePay(from window: UIWindow?, completion: STPVoidBlock? = nil)
Parameters
window
The UIWindow to host the Apple Pay sheet
completion
Called after the Apple Pay sheet is presented
-
The STPAPIClient instance to use to make API requests to Stripe. Defaults to
STPAPIClient.shared
.Declaration
Swift
@objc public var apiClient: STPAPIClient