Skip to main content
Use PrimerApplePayScope to check Apple Pay availability, customize the button, and initiate payments.

Check availability

PrimerCheckout(
  clientToken: clientToken,
  scope: { checkoutScope in
    if let applePayScope: PrimerApplePayScope = checkoutScope.getPaymentMethodScope(PrimerApplePayScope.self) {
      Task {
        for await state in applePayScope.state {
          if state.isAvailable {
            print("Apple Pay is available")
          } else if let error = state.availabilityError {
            print("Apple Pay unavailable: \(error)")
          }
        }
      }
    }
  }
)

Use the SDK’s Apple Pay button

The scope provides a ready-made Apple Pay button:
if let applePayScope: PrimerApplePayScope = checkoutScope.getPaymentMethodScope(PrimerApplePayScope.self) {
  // Use the SDK button
  let button = applePayScope.PrimerApplePayButton {
    applePayScope.submit()
  }
}

Custom Apple Pay button

Replace the Apple Pay button with your own:
applePayScope.applePayButton = { action in
  AnyView(
    Button(action: action) {
      HStack {
        Image(systemName: "apple.logo")
        Text("Pay")
      }
      .frame(maxWidth: .infinity)
      .frame(height: 50)
      .background(.black)
      .foregroundColor(.white)
      .cornerRadius(10)
    }
  )
}

Full screen replacement

Replace the entire Apple Pay screen:
applePayScope.screen = { scope in
  AnyView(
    VStack(spacing: 20) {
      Text("Quick checkout")
        .font(.title3)
      scope.PrimerApplePayButton {
        scope.submit()
      }

    }
    .padding()
  )
}

See also

PrimerApplePayScope API

Full API reference