ContactlessPaymentSession
public final actor ContactlessPaymentSession
Class to manage and perform contactless payment transaction.
Since
7.0.0-
Constructor to initialize
ContactlessPaymentSession.Declaration
Swift
public convenience init() -
requestAuthorization()AsynchronousRequest authorization from user to allow NFC usage.
This prompts the permission dialog during first time application launch. On subsequent call, this API check the current authorization granted by end user.
When end user allows the authorization, the application is shown in list of default contactless application. Otherwise, application is not shown in the list.
Throws:
nfcPermissionNotAccepted- user does not allow the authorization.systemEligibilityFailed- Device not eligible for contactless payment.unknown(_:)- Unknown error encountered during transaction.
Declaration
Swift
@available(iOS 17.4, *) public func requestAuthorization() async throws -
startEmulation()AsynchronousStart the card emulation and presents a modal user interface to user.
This API is available after
authenticationCompleted. Developer could call this API onauthenticationCompletedorposConnected, depending on the user experience preferred. After this API is called, a modal user presentation is shown, i.e. no further UI modification, except thesetAlertMessage(_:).Throws:
deviceEnvironmentUnsafe(_:)if device environment is unsafe.unknown(_:)if error on starting card emulation.
Declaration
Swift
@available(iOS 17.4, *) nonisolated public func startEmulation() async throws -
startPayment(with:Asynchronous) Starts a contactless payment flow using the provided input data.
This method prepares and initiates a contactless transaction based on the
ContactlessPaymentInputDataprovided. Depending on the configuration, the wallet transaction data can be supplied either as an ephemeral value or retrieved from secure storage.Throws
Throws:
schemeNotSupportedif the provided digital card id does not belong to MasterCard v2 scheme.
Note
Available on iOS 17.4 and later.
See also
WalletTransactionDatafor details on configuring wallet transaction values.Application should call
eventStreamto handle other events.Declaration
Swift
@available(iOS 17.4, *) public func startPayment(with contactlessPaymentInputData: ContactlessPaymentInputData) async throwsParameters
contactlessPaymentInputDataThe input data that specifies how wallet transaction data should be sourced and which digital card to use for the transaction. If providing transaction data (either directly or from storage), the
digitalCardIdmust belong to the MasterCard scheme.- If
.ephemeral, the method uses the providedWalletTransactionData. Anilvalue may be passed in its associated value. - If
.storage, the method retrieves the associated digital card and loads its stored wallet transaction data.
-
startPayment(withDigitalCardID:Asynchronous) Start contactless payment transaction.
The digital card ID provided will be remained as default card at the end of the payment
Application should call
eventStreamto handle each event.Declaration
Swift
@available(iOS 17.4, *) public func startPayment(withDigitalCardID digitalCardID: String? = nil) asyncParameters
digitalCardIDDigital card ID used. Otherwise, it use default card.
-
cancel()AsynchronousCancel ongoing contactless payment transaction.
Declaration
Swift
@available(iOS 17.4, *) public func cancel() async -
An asynchronous sequence of events from contactless payment transaction.
Declaration
Swift
public var eventStream: AsyncStream<Event> -
setAlertMessage(_:Asynchronous) A message to show on the NFC action sheet.
Application should set the message for following events:
authenticationCompleted- start of transaction.posConnected- device is tapped to NFC reader.posDisconnected- device is disconnected from NFC reader.
Declaration
Swift
@available(iOS 17.4, *) nonisolated public func setAlertMessage(_ alertMessage: String) async -
The device eligibility whether it supports contactless payment.
See moreDeclaration
Swift
public enum Eligibility : Sendable -
Errors encounterd for contactless payment session.
See moreDeclaration
Swift
public enum Error : Swift.Error -
Events produced during contactless payment session.
See moreDeclaration
Swift
public enum Event : Sendable -
Struct to manage the authentication flow.
See moreDeclaration
Swift
public struct AuthenticateAction : Sendable
ContactlessPaymentSession Actor Reference