Yuno’s Headless iOS SDK lets you create payments and enroll payment methods simultaneously. Note that when using the Headless SDK, you will need to request and send via API all the mandatory fields the payment provider requires to generate payment in their API. Yuno’s Headless SDK enables you to create payments in two different scenarios:Documentation Index
Fetch the complete documentation index at: https://docs.y.uno/llms.txt
Use this file to discover all available pages before exploring further.
- Create a One-Time Use Token using credit card information or alternative payment methods, then create a payment.
- Create a One-Time Use Token using a
vaulted_tokenfrom a previously enrolled payment method to collect relevant information for fraud providers, then create a payment.
Step 1: Include the library in your project
The first step is to install Yuno SDK to your iOS project.Check iOS SDK VersionsTo view all available versions, visit the release page on the Yuno iOS SDK repository.
- Cocoapods: If you do not have a Podfile, follow the CocoaPods guide to create one. After creating the Podfile, you will integrate the Yuno SDK with Cocoapods by adding the line below to your Podfile:
- Swift Package Manager: Set up the Swift package, and then add Yuno SDK as a dependency, as presented in the following code block:
Step 2: Initialize Headless SDK with the public key
To initialize the Headless SDK, you need to import Yuno and provide a valid PUBLIC_API_KEY. If you don’t have your API credentials, access the Developers (Credentials) page to check how to retrieve them from the dashboard. The code block below presents an example of importing and initializing theYuno.
Swift 6 Concurrency RequirementsIf you’re using Swift 6, you’ll need to handle concurrency correctly when using the SDK’s asynchronous methods. See the Swift 6 Concurrency guide for detailed implementation options and best practices.
Step 3: Start the checkout process
Next, you will start the checkout process using theapiClientPayment function, providing the necessary configuration parameters. You need to call this function once your customer selects the payment method. As a result, the SDK will start collecting relevant information for 3DS and fraud prevention tools you have configured in your routing.
Parameters
The following table lists all required parameters and their descriptions.
| Parameter | Description |
|---|---|
countryCode | This parameter determines the country for which the payment process is being configured. The complete list of supported countries and their countryCode is available on the Country coverage page. |
checkout_session | Refers to the current payment’s checkout session created using the Create Checkout Session endpoint. Example: ‘438413b7-4921-41e4-b8f3-28a5a0141638’ |
Step 4: Generate token
After collecting all user information, you can start the payment. First, you need to create a one-time token (OTT) using the functionapiClientPayment.generateToken. As it is an asynchronous function, you can use do/catch to ensure you will correctly handle triggered errors. Below, you will find two examples of different scenarios to create a one-time token:
- Example 1: Create a one-time token utilizing a card as the payment method and including all requisite card information.
- Example 2: Create a one-time token using the
vaulted_tokeninformation.
Example 1
Example 2
apiClientPayment.generateToken function responses for both examples above. The response is a dictionary of type [String: Any].
Example 1
Example 2
Step 5: Create the payment
Once you have completed the steps described before, you can create a payment. The back-to-back payment creation must be carried out using the Create Payment endpoint. The merchant should call their backend to create the payment within Yuno, using the one-time token and the checkout session. The endpoint response includes thesdk_action_required parameter that indicates whether additional actions are needed to complete the payment:
For synchronous payment methods, the payment completes instantly. In this case, sdk_action_required will be false in the API response and the payment process ends. If the payment requires further interaction from the SDK to complete the flow, sdk_action_required will be true; in this case, proceed with Step 6 for instructions.
Step 6: Process asynchronous payments (Optional)
A payment with 3DS may require an additional challenge to check the customer’s identity, as described on the 3DS Card Verification page. If an 3DS verification challenge is necessary, the Create Payment endpoint response will contain:- Status equal to
PENDINGand sub status equal toWAITING_ADDITIONAL_STEP sdk_action_required = true- A
redirect_urldefined inpayment.payment_method.payment_method_detail.card
Get the 3DS challenge URL
To get the 3DS challenge URL, you need to call thegetThreeDSecureChallenge function, providing the checkoutSession. The checkoutSession is only required if you aren’t using the one used to create the payment. Below, you will find an example of using the getThreeDSecureChallenge function. As getThreeDSecureChallenge is an asynchronous function, you can use do/catch to ensure you will correctly handle triggered errors.
getThreeDSecureChallenge function will return the ThreeDSecureChallengeResponse, presented in the next code block:
url will contain a valid URL you need to redirect your customer to complete the challenge.
You are responsible for redirecting your customers to the URL provided by the getThreeDSecureChallenge() function to complete the challenge. Once the customer successfully completes the 3DS challenge, they will be automatically redirected to the callback_url, which you provided when creating the checkout_session with the Create Checkout Session endpoint.
To confirm the challenge was completed, you can open a web view to load the provided URL and listen for the messageFromWeb event. Below is an example code demonstrating how to listen for this event.
COMPLETED or ERROR. The next code block presents examples for each possible option.
COMPLETED
ERROR
Step 7: Handle payment status (Optional)
Some payment methods take users out of your app to complete the transaction. Once the payment is finished, the user is redirected back to your app using a deep link. The SDK uses this deep link to check what happened, checking if the payment was successful, failed, or canceled, and can show a status screen to the user. To handle this, you need to update yourAppDelegate to pass the incoming URL back to the Yuno SDK. This lets the SDK read the result and optionally display the payment status. The following code snippet shows how you can add it to your app:
callback_url during checkout session setup. If it matches, the URL is passed to the Yuno SDK using Yuno.receiveDeeplink(...). The SDK then reads the payment result and, if showStatusView is set to true, shows the appropriate status screen to the user.
Make sure the url.scheme in this code matches the callback_url you provided when creating the checkout_session.
Demo AppIn addition to the code examples provided, you can access the Yuno repository for a complete implementation of Yuno iOS SDKs.