Contents

transactionTask(_:action:)

Provides a task to perform before this view appears

Declaration

nonisolated func transactionTask(_ configuration: CredentialTransaction.Configuration?, action: @escaping (CredentialTransaction) async -> Void) -> some View

Parameters

  • configuration:

    A configuration containing information about the transaction task. When the task is completed or an error is encountered while performing the task, the system invalidates this configuration, and the CredentialTransaction is invalidated.

  • action:

    A closure that will be called when isPerformingTransaction is true. It provides a CredentialTransaction instance that can be used to perform transactions.

Discussion

This task provides an instance of a CredentialTransaction to be used to perform transactions.

A typical client should use the APIs in the following sequence:

  1. acquirePresentmentIntentAssertion() prior to showing any proprietary payment UI

  2. relinquish() the assertion before invoking the transaction API

  3. configuration.invalidate() after presenting the credential

  4. Optionally, acquirePresentmentIntentAssertion() to finish up any proprietary payment UI

  5. relinquish() the assertion

For example:

 struct TransactionView: View {
     @State private var configuration: CredentialTransaction.Configuration?
     private var assertion: PresentmentIntentAssertion // acquirePresentmentIntentAssertion() before transitioning into this view (step 1)
     private var activeSession: CredentialSession
     private var selectedCredential: Credential

     var body: some View {
         VStack {
             Button("Perform Transaction") {
                 guard let configuration else {
                    configuration = activeSession.configuration()
                    return
                 }

                 configuration.invalidate() // step 3
                 // Optional
                 assertion = try await session.acquirePresentmentIntentAssertion() // step 4
                 // handle any proprietary UI
                 try await assertion.relinquish() // step 5
                 // Optional end
             }
             .transactionTask(configuration) { transaction in
                 do {
                     try await assertion.relinquish() // step 2
                     try await transaction.performTransaction(using: selectedCredential)
                 } catch {
                     // code to handle error
                 }
             }
         }
     }
 }

See Also

Accessing Apple Pay and Wallet