- iOS
- Android
- Flutter
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
- iOS
- Android
- Flutter
lite’s SDKs offer three ways to collect a payment method. A tokenization session supports two of them on iOS:
How it works
- iOS
- Android
- Flutter
- Your server creates a tokenization session with the lite API and gets back its
client_secret. - Your app starts the SDK with that
client_secret. - The customer enters a card in the secure fields, or authorizes Apple Pay.
- The SDK encrypts the card and saves it with lite. Nothing is charged.
- Your app receives the instrument and sends its
idto your server. - Your server fetches the instrument from lite, decides what to do, and optionally charges it.
Before you begin
- iOS
- Android
- Flutter
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.
1. Install the SDK
- iOS
- Android
- Flutter
In Xcode, select File → Add Package Dependencies, enter the package URL, and add the If you manage dependencies in Then import it where you save cards:
LiteSDK product to your app target:Package.swift: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, withtype: "tokenization" and the customer’s id (at least 3 characters).
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
- iOS
- Android
- Flutter
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
- iOS
- Android
- Flutter
Secure fields (cards)
Place the secure fields in your layout and add your own Save card button. Enable it onlite.isComplete, which is true once the card in the fields is complete.tokenizesaves the card and never charges it. PassstoreForFuture: trueonly 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 aVStackorScrollView, not aListorLazyVStack, which clear the typed card when it scrolls away. - Each field’s
onChangereportsvalid,focused,brandanderror, and never the card data. - Calling
tokenizeagain 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.
merchant_identifier. Follow Apple Pay in the Checkout SDK guide. Test it on a physical device.5. Handle the tokenization result
- iOS
- Android
- Flutter
Both On success,
tokenize() and the Apple Pay button return a TokenizeResult: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.
6. Charge the instrument (optional)
- iOS
- Android
- Flutter
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 aLite 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 asunscheduled, 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
- iOS
- Android
- Flutter
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
- iOS
- Android
- Flutter
- Save cards with Apple Pay. On a tokenization session,
LiteApplePayButtonsaves the card when you passonTokenize.lite.isApplePayEnabledInSessionis nowtrueon a tokenization session with Apple Pay active. - Breaking: renamed instrument fields.
card.fundingis nowcard.fundingSource,card.issueris nowcard.issuerName, andcard.binis nowcard.issuerBin, read from the API’sissuer_bin. New:instrument.agreementId.