Skip to main content
Version: 0.2.0 (lite-ios)The Instruments SDK saves a customer’s card without taking a payment. You get back an instrument: an id you can pay with later, plus the card’s scheme, issuing bank, issuing country and funding source. Use it when your price or eligibility depends on the card, for example a discount for one scheme or different terms for domestic cards, or when you want to keep a card on file before the first payment.It is part of the same LiteSDK package as the Checkout SDK. Card details are entered in lite’s secure fields and encrypted on the device: your code and your server never see them.

Secure fields, elements and the payment sheet

lite’s SDKs offer three ways to collect a payment method. A tokenization session supports two of them on iOS:

How it works

  1. Your server creates a tokenization session with the lite API and gets back its client_secret.
  2. Your app starts the SDK with that client_secret.
  3. The customer enters a card in the secure fields, or authorizes Apple Pay.
  4. The SDK encrypts the card and saves it with lite. Nothing is charged.
  5. Your app receives the instrument and sends its id to your server.
  6. Your server fetches the instrument from lite, decides what to do, and optionally charges it.

Before you begin

You need:
  • A lite account with a terminal that has cards enabled. To save cards with Apple Pay, enable Apple Pay on the same terminal. A tokenization session offers only the payment methods enabled there.
  • lite API keys, kept on your server.
  • A backend endpoint that creates tokenization sessions.
  • Xcode 15 or later, and an app targeting iOS 15 or later.
Never put your lite API keys in your app. Your server creates the session and sends only its client_secret to the app.

1. Install the SDK

In Xcode, select File → Add Package Dependencies, enter the package URL, and add the LiteSDK product to your app target:
If you manage dependencies in Package.swift:
Then import it where you save cards:

2. Create a tokenization session

A tokenization session is a checkout session that saves one card instead of taking a payment. Your server creates it with your API key, the same way as a payment session, with type: "tokenization" and the customer’s id (at least 3 characters).
Check that type is tokenization and customer.id is the customer you’re serving. Send the client_secret to the app exactly as you received it: it’s a signed token (a JWT), not an ID, and the SDK fails to start with any other value. A tokenization session takes no payment fields. Sending amount, currency, order, redirect_urls, splits, capture_mode, processing_type, three_ds_required or metadata returns a 400. Send only type, customer, and optionally terminal_id and expiry. The fields the Create a checkout session reference marks required apply to payment sessions only. terminal_id is optional and sets the card networks and wallets the session offers. Without it, the session uses your default online terminal. To use another, send its ID: open the terminal under Acceptance → Online in the dashboard, and the ID is the last part of the page address. Create the session when the customer reaches the card step, not when the app launches. It expires after expiry seconds, or after 15 minutes if you leave expiry out.

3. Pass the client secret to the SDK

The client_secret is a short-lived credential for this one session. It lets the SDK read the session and save one card on it. It cannot read other sessions, and it cannot pay. Return it from your server to the app. Keep the session id on your server.Do not log the client_secret.Create one Lite for the screen that saves the card, and start it with the secret:
lite.phase becomes .ready once the session is loaded, or .failed(message) if the secret is expired or rejected. lite.session?.isTokenization is true for a tokenization session.

4. Collect the card

Secure fields (cards)

Place the secure fields in your layout and add your own Save card button. Enable it on lite.isComplete, which is true once the card in the fields is complete.
  • tokenize saves the card and never charges it. Pass storeForFuture: true only with the customer’s consent to keep the card for later payments. Without it, the instrument is for a single payment.
  • Place at most one field of each type for a Lite. Keep the fields in a VStack or ScrollView, not a List or LazyVStack, which clear the typed card when it scrolls away.
  • Each field’s onChange reports valid, focused, brand and error, and never the card data.
  • Calling tokenize again while a save is running returns the same result.

Elements: Apple Pay

On a tokenization session, LiteApplePayButton saves the card the customer authorizes instead of paying. The sheet reads Save card with nothing due, and nothing is charged. Give the button an onTokenize. It receives the same result as tokenize(), after the sheet closes:
  • Without onTokenize, the button does not show on a tokenization session.
  • The button shows only when the session enables Apple Pay and the device can pay with it.
  • The button never asks lite to keep the card for later payments: the instrument it saves is for a single payment. To keep a card on file, use the secure fields with tokenize(storeForFuture: true).
  • If the customer closes the Apple Pay sheet without authorizing, the button calls nothing.
  • If the customer tries again in the same sheet after a failure, you get only the last attempt’s result.
Apple Pay needs your app to carry the Apple Pay entitlement, with the Merchant ID that matches the session’s merchant_identifier. Follow Apple Pay in the Checkout SDK guide. Test it on a physical device.

5. Handle the tokenization result

Both tokenize() and the Apple Pay button return a TokenizeResult:
On success, result.instrument is a LiteInstrument:Any card detail lite doesn’t know is nil. If you pass storeForFuture: true and the customer already has this card stored, lite returns the instrument they already have, with its id.On failure, result.errorCode says why, and result.apiErrorCode carries lite’s own code when there is one:A session saves one card, whether from the secure fields or Apple Pay. A refused attempt doesn’t use the session up, so the customer can retry until it expires.
Make decisions on your server. The instrument reached your app through the customer’s device. Send only its id to your server, fetch the instrument from lite there, and check that its holder_id is the customer you’re serving before you rely on its card details.

6. Charge the instrument (optional)

Saving a card authorizes nothing, so the card can still be declined when you charge it. A card saved without storeForFuture: true is for one payment: charge it within about 20 minutes. There are two ways to charge an instrument.

With the Checkout SDK

Use this when the customer confirms the final price in your app. Your server creates a normal payment session for the same customer with the final amount. Start a Lite with that session’s client_secret and pay with the instrument id. The customer doesn’t enter the card again.
result is the Checkout SDK’s payment result: see Handle the result.

With the Payments API

A card saved with this SDK is stored as unscheduled, with no consent record, so charge it only with the customer present: in the app, with the Checkout SDK, as in the previous section. To charge a customer who isn’t there, store the card with an agreement through the instruments API, then charge it from your server with POST /payments.

7. Clean up

When the customer leaves the screen without saving, or to start again with a new session, reset the SDK:
reset() cancels any running save and clears the session and the typed card. To save another card, create a new tokenization session and call start again.

What’s new in 0.2.0

  • Save cards with Apple Pay. On a tokenization session, LiteApplePayButton saves the card when you pass onTokenize. lite.isApplePayEnabledInSession is now true on a tokenization session with Apple Pay active.
  • Breaking: renamed instrument fields. card.funding is now card.fundingSource, card.issuer is now card.issuerName, and card.bin is now card.issuerBin, read from the API’s issuer_bin. New: instrument.agreementId.