Contents

PayWithApplePayButton

A type that provides a button to pay with Apple pay.

Declaration

@MainActor @preconcurrency struct PayWithApplePayButton<Fallback> where Fallback : View

Overview

Use this structure as the SwiftUI equivalent to PKPaymentButton. For design guidance, see Human Interface Guidelines > Apple Pay > Using Apple Pay buttons.

This example shows an implementation of the Pay with Apple Pay button.

// Create a payment request.
@State private var paymentRequest = PKPaymentRequest()

// Create a payment authorization change method.
func paymentAuthorizationDidChange(phase: PayWithApplePayButtonPaymentAuthorizationPhase) { ... }

@ViewBuilder var payButton: some View {
    PayWithApplePayButton(
        .plain,
        request: paymentRequest,
        onPaymentAuthorizationChange: paymentAuthorizationDidChange
    ) {
        // Display a fallback view if the payment request fails.
    }
    .frame(width: 250, height: 50)
    .payWithApplePayButtonStyle(.automatic)
}

Topics

Creating the button

See Also

Apple Pay buttons