Starting a Tap to Pay Transaction

Accept a contactless payment on an iPhone by connecting to Tap to Pay and submitting a transaction request through the Stax iOS SDK.

📘

Currently Tap to Pay is in Beta Release. If you would like to participate, please reach out to your Account Manager.


For SDK details, see the SDK README.

Using Tap to Pay on iPhone

Use Tap to Pay on iPhone to accept contactless cards and digital wallets without additional payment hardware.

Requirements

  1. Use an iPhone XS or later running iOS 17.4 or later.
  2. Enable Tap to Pay for your Stax account. Contact your Account Manager to participate in the beta.
  3. Install the Stax iOS SDK and initialize an Omni instance using iOS SDK using a Mobile Reader. Obtain an ephemeral token (a temporary authentication credential) from your backend, and wait for the initialization completion callback before starting reader operations. Keep your long-term API key on your server, not in your app.
  4. Add CloudCommerce.xcframework following the SDK's CloudCommerce setup instructions.
  5. Enable a passcode on the iPhone.
⚠️

Passcode required

An active iPhone passcode is required for Tap to Pay to work; it is not an optional recommendation. Without a passcode, you may receive an error that resembles a connection error. Check the passcode before retrying the connection.

How Tap to Pay processes a payment

Tap to Pay uses TransactionRequest (an object containing the amount and other payment parameters), the same model used for mobile-reader payments. The iPhone's built-in NFC (near-field communication) reader accepts the contactless card or digital wallet.

1. Connect to Tap to Pay

Call connectToTap(completion:error:) on your initialized Omni instance. Wait for its completion callback before taking a payment. If the error callback runs, check the device requirements, passcode, account enablement, and SDK initialization before retrying.

The complete example below performs this connection before submitting the payment request.

2. Take a Tap to Pay transaction

Create an Amount in cents, pass it to TransactionRequest, and call takeTapTransaction(with:completion:error:) after the connection succeeds. For example, Amount(cents: 2500) represents $25.00.

Handle both callbacks: the completion callback returns the transaction, and the error callback reports a failed attempt. Read transaction.id from the returned transaction rather than substituting a dummy ID or copying an unrelated Dashboard value.

3. Run the complete example

Add this helper to a Swift file in your app target. Call processTapPayment(omni:) with the Omni instance you retained after successful SDK initialization. The helper connects to Tap to Pay and requests a $25.00 payment; run it only when you intend to initiate that payment.

import Fattmerchant

func processTapPayment(omni: Omni) {
    guard #available(iOS 17.4, *) else {
        print("Tap to Pay requires iOS 17.4 or later.")
        return
    }

    omni.connectToTap(completion: {
        print("Connected to Tap to Pay!")

        // Amount uses cents, so 2500 represents $25.00.
        let amount = Amount(cents: 2500)
        let request = TransactionRequest(amount: amount)

        omni.takeTapTransaction(with: request, completion: { transaction in
            print("Tap payment successful!")
            // The SDK returns this ID; no Dashboard lookup or placeholder is needed.
            print("Transaction ID: \(transaction.id)")
            print("Amount: \(transaction.total)")
        }, error: { _ in
            // Check the payment status before retrying to avoid a duplicate charge.
            print("Tap payment failed. Check the transaction status before retrying.")
        })
    }, error: { _ in
        print("Failed to connect to Tap to Pay. Check the device requirements, passcode, account enablement, and SDK initialization.")
    })
}

A successful connection and payment print these messages, followed by the actual transaction ID and amount returned by the SDK:

Connected to Tap to Pay!
Tap payment successful!

If the device runs an earlier iOS version, the helper prints Tap to Pay requires iOS 17.4 or later. and does not attempt a connection. A connection failure does not start a payment. If payment processing fails, check the transaction status before retrying to avoid charging the customer twice.

Optional: Add payment metadata

If you use the meta property, assign it to the TransactionRequest before calling takeTapTransaction. The existing metadata keys order_id and customer_name represent your application's order reference and customer name; they are not Stax authentication credentials or Dashboard resource IDs. Supply values from your own application rather than treating example order numbers as Stax IDs.

Optional: Refund a payment

Retrieve the original Transaction from the Stax API, then pass that populated SDK object and your initialized Omni instance to refundPayment(omni:transaction:). Do not construct an empty Transaction() or substitute a fabricated transaction ID. The transaction comes from the API response, so this example does not require a Dashboard lookup.

import Fattmerchant

func refundPayment(omni: Omni, transaction: Transaction) {
    // Use the original transaction retrieved from the Stax API, not an empty object.
    omni.refundMobileReaderTransaction(transaction: transaction, completion: { refundedTransaction in
        print("Refund operation completed.")
        print("Returned transaction: \(refundedTransaction.id)")
    }, error: { _ in
        // Verify the original transaction's status before attempting another refund.
        print("Refund failed. Check the transaction status before retrying.")
    })
}

When the refund completion callback runs, the example prints Refund operation completed. followed by the returned transaction ID. Check the returned transaction before confirming the refund to the customer. If the error callback runs, check the original transaction's status before attempting another refund.


Did this page help you?