---
title: "transactionTask(_:action:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/transactiontask(_:action:)"
---

# transactionTask(_:action:)

Provides a task to perform before this view appears

## Declaration

```swift
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

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: acquirePresentmentIntentAssertion() prior to showing any proprietary payment UI relinquish() the assertion before invoking the transaction API configuration.invalidate() after presenting the credential Optionally, acquirePresentmentIntentAssertion() to finish up any proprietary payment UI 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

- [PayWithApplePayButton](passkit/paywithapplepaybutton.md)
- [AddPassToWalletButton](passkit/addpasstowalletbutton.md)
- [VerifyIdentityWithWalletButton](passkit/verifyidentitywithwalletbutton.md)
- [addOrderToWalletButtonStyle(_:)](swiftui/view/addordertowalletbuttonstyle(_:).md)
- [addPassToWalletButtonStyle(_:)](swiftui/view/addpasstowalletbuttonstyle(_:).md)
- [onApplePayCouponCodeChange(perform:)](swiftui/view/onapplepaycouponcodechange(perform:).md)
- [onApplePayPaymentMethodChange(perform:)](swiftui/view/onapplepaypaymentmethodchange(perform:).md)
- [onApplePayShippingContactChange(perform:)](swiftui/view/onapplepayshippingcontactchange(perform:).md)
- [onApplePayShippingMethodChange(perform:)](swiftui/view/onapplepayshippingmethodchange(perform:).md)
- [payLaterViewAction(_:)](swiftui/view/paylaterviewaction(_:).md)
- [payLaterViewDisplayStyle(_:)](swiftui/view/paylaterviewdisplaystyle(_:).md)
- [payWithApplePayButtonDisableCardArt()](swiftui/view/paywithapplepaybuttondisablecardart().md)
- [payWithApplePayButtonStyle(_:)](swiftui/view/paywithapplepaybuttonstyle(_:).md)
- [verifyIdentityWithWalletButtonStyle(_:)](swiftui/view/verifyidentitywithwalletbuttonstyle(_:).md)
- [AsyncShareablePassConfiguration](passkit/asyncshareablepassconfiguration.md)
