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
CredentialTransactionis invalidated. - action:
A closure that will be called when
isPerformingTransactionistrue. It provides aCredentialTransactioninstance 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:
acquirePresentmentIntentAssertion()prior to showing any proprietary payment UIrelinquish()the assertion before invoking the transaction APIconfiguration.invalidate()after presenting the credentialOptionally,
acquirePresentmentIntentAssertion()to finish up any proprietary payment UIrelinquish()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
PayWithApplePayButtonAddPassToWalletButtonVerifyIdentityWithWalletButtonaddOrderToWalletButtonStyle(_:)addPassToWalletButtonStyle(_:)onApplePayCouponCodeChange(perform:)onApplePayPaymentMethodChange(perform:)onApplePayShippingContactChange(perform:)onApplePayShippingMethodChange(perform:)payLaterViewAction(_:)payLaterViewDisplayStyle(_:)payWithApplePayButtonStyle(_:)verifyIdentityWithWalletButtonStyle(_:)AsyncShareablePassConfiguration