STPApplePayContextDelegate

Objective-C

@protocol STPApplePayContextDelegate <NSObject>

Swift

protocol STPApplePayContextDelegate : NSObjectProtocol

Implement the required methods of this delegate to supply a PaymentIntent to STPApplePayContext and be notified of the completion of the Apple Pay payment.

You may also implement the optional delegate methods to handle shipping methods and shipping address changes e.g. to verify you can ship to the address, or update the payment amount.

  • Called after the customer has authorized Apple Pay. Implement this method to call the completion block with the client secret of a PaymentIntent representing the payment.

    Declaration

    Objective-C

    - (void)applePayContext:(nonnull STPApplePayContext *)context
        didCreatePaymentMethod:(nonnull STPPaymentMethod *)paymentMethod
            paymentInformation:(nonnull PKPayment *)paymentInformation
                    completion:
                        (nonnull STPIntentClientSecretCompletionBlock)completion;

    Swift

    func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock)

    Parameters

    paymentMethod

    The PaymentMethod that represents the customer’s Apple Pay payment method. If you create the PaymentIntent with confirmation_method=manual, pass paymentMethod.stripeId as the payment_method and confirm=true. Otherwise, you can ignore this parameter.

    paymentInformation

    The underlying PKPayment created by Apple Pay. If you create the PaymentIntent with confirmation_method=manual, you can collect shipping information using its shippingContact and shippingMethod properties.

    completion

    Call this with the PaymentIntent’s client secret, or the error that occurred creating the PaymentIntent.

  • Called after the Apple Pay sheet is dismissed with the result of the payment.

    Your implementation could stop a spinner and display a receipt view or error to the customer, for example.

    Declaration

    Objective-C

    - (void)applePayContext:(nonnull STPApplePayContext *)context
        didCompleteWithStatus:(STPPaymentStatus)status
                        error:(nullable NSError *)error;

    Swift

    func applePayContext(_ context: STPApplePayContext, didCompleteWith status: STPPaymentStatus, error: Error?)

    Parameters

    status

    The status of the payment

    error

    The error that occurred, if any.

  • Called when the user selects a new shipping method. The delegate should determine shipping costs based on the shipping method and either the shipping address supplied in the original PKPaymentRequest or the address fragment provided by the last call to paymentAuthorizationViewController: didSelectShippingContact:completion:.

    You must invoke the completion block with an updated array of PKPaymentSummaryItem objects.

    Declaration

    Objective-C

    - (void)applePayContext:(nonnull STPApplePayContext *)context
        didSelectShippingMethod:(nonnull PKShippingMethod *)shippingMethod
                        handler:(nonnull void (^)(
                                    PKPaymentRequestShippingMethodUpdate *_Nonnull))
                                    handler;

    Swift

    optional func applePayContext(_ context: STPApplePayContext, didSelect shippingMethod: PKShippingMethod, handler: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void)
  • Called when the user has selected a new shipping address. You should inspect the address and must invoke the completion block with an updated array of PKPaymentSummaryItem objects.

    Note

    To maintain privacy, the shipping information is anonymized. For example, in the United States it only includes the city, state, and zip code. This provides enough information to calculate shipping costs, without revealing sensitive information until the user actually approves the purchase. Receive full shipping information in the paymentInformation passed to applePayContext:didCreatePaymentMethod:paymentInformation:completion:

    Declaration

    Objective-C

    - (void)applePayContext:(nonnull STPApplePayContext *)context
        didSelectShippingContact:(nonnull PKContact *)contact
                         handler:
                             (nonnull void (^)(PKPaymentRequestShippingContactUpdate
                                                   *_Nonnull))handler;

    Swift

    optional func applePayContext(_ context: STPApplePayContext, didSelectShippingContact contact: PKContact, handler: @escaping (PKPaymentRequestShippingContactUpdate) -> Void)