STPApplePayContext

@interface STPApplePayContext : NSObject

A helper class that implements Apple Pay.

Usage looks like this:

  1. Initialize this class with a PKPaymentRequest describing the payment request (amount, line items, required shipping info, etc)
  2. 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
  3. When the user taps ‘Buy’, this class uses the PaymentIntent that you supply in the applePayContext:didCreatePaymentMethod:completion: delegate method to complete the payment
  4. After payment completes/errors and the sheet is dismissed, this class informs you in the applePayContext:didCompleteWithStatus: delegate method

See

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

    Objective-C

    - (nullable instancetype)
    initWithPaymentRequest:(nonnull PKPaymentRequest *)paymentRequest
                  delegate:(nonnull id<STPApplePayContextDelegate>)delegate;

    Swift

    init?(paymentRequest: PKPaymentRequest, delegate: STPApplePayContextDelegate)

    Parameters

    paymentRequest

    The payment request to use with Apple Pay.

    delegate

    The delegate.

  • Unavailable

    Use initWithPaymentRequest:delegate: instead.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Unavailable

    Use initWithPaymentRequest:delegate: instead.

    Declaration

    Objective-C

    + (nonnull instancetype) new;
  • Presents the Apple Pay sheet, 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

    Objective-C

    - (void)presentApplePayOnViewController:
                (nonnull UIViewController *)viewController
                                 completion:(nullable STPVoidBlock)completion;

    Swift

    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

  • The STPAPIClient instance to use to make API requests to Stripe. Defaults to [STPAPIClient sharedClient].

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) STPAPIClient *apiClient;

    Swift

    var apiClient: STPAPIClient! { get set }