Yuno’s Headless SDK lets you create payments. 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:
- Create a One-Time Use Token using credit card information, then create a payment.
- Create a One-Time Use Token using a
vaulted_tokenfrom a previously enrolled credit card, then create a payment.
Step 1: Include the library in your project
Before proceeding with the Headless SDK implementation, see the SDK Integration Overview for detailed instructions on how to properly integrate the SDK into your project. The integration guide provides three flexible methods:- Direct HTML script inclusion
- Dynamic JavaScript injection
- NPM module installation
TypeScript LibraryIf you are using TypeScript, Yuno provides a library that you can use to see all available methods in the Yuno Web SDK.
Step 2: Initialize Headless SDK with the public key
In your JavaScript application, create an instance of theYuno class by providing a valid PUBLIC_API_KEY.
CredentialsSee the credentials page for more information: /reference/getting-started/authentication
Step 3: Start the checkout process
Next, you will start the checkout process using theapiClientPayment function, providing the necessary configuration parameters.
Parameters
Configure the payment with the following options: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 try/catch to ensure you will correctly handle triggered errors. The following examples show different scenarios to create the 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.
Benefits of Using a Vaulted TokenWhen you use a vaulted token with the SDK, all the fraud information from the providers you configured in your card routing is collected and attached to the one-time token. In addition, you can add installment information and a security code if the provider requires it.
Example 1
Parameters for Example 1
Example 2
Parameters for Example 2
The following code block shows the
apiClientPayment.generateToken function responses for both examples above:
Example 1
Example 2
Step 5: Create the Payment
After receiving the one-time token, you can create the payment using the Create Payment endpoint to get the final payment result. You will inform the one-time token received in Step 4 through the request’spayment_method.token parameter. The following code block shows a request example for creating a payment:
sdk_action_required parameter that defines if additional actions are necessary to conclude the payment:
- If your customer selects a synchronous payment method, the payment is completed instantly. In this scenario, the field
sdk_action_requiredin the API response will befalse, and the payment process concludes at this step. - When an additional interaction of the SDK is needed to complete the payment flow,
sdk_action_requiredwill betrue. If this is the case, you need to follow the instructions from Step 6.
Step 6: Get the 3DS challenge URL
As described on the 3DS Card Verification page, a payment with 3DS may require an additional challenge to check the customer’s identity. If an additional verification step is necessary related to a 3DS verification challenge, the response to the Create Payment endpoint will have the following information:- A
THREE_D_SECUREtransaction type. - Status equal to
PENDINGand sub status equal toWAITING_ADDITIONAL_STEP. - The
sdk_action_requiredset astrue.
getThreeDSecureChallenge function, providing the checkoutSession used to create the payment.
url will return null.
In a web browser, you can open the URL in a new tab or an IFrame. To open the URL in an iframe, you must set the param embedded = true. If not, you can omit this parameter, whose default value is false. The following code block shows an example of displaying the 3DS challenge content in an IFrame:
redirect_url 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 complete the Headless SDK payment flow, you need to use Yuno Webhooks, which will promptly notify you about the outcome of the 3DS challenge and the final payment status. Using webhooks ensures that you receive real-time updates on the progress of the payment transaction. In addition to the webhooks, you can retrieve the payment information using the Retrieve Payment by ID endpoint.
Step 7: Get payment actions
Sometimes the payment may require an extra action to continue the payment flow. To determine what action is needed, you should call thegetContinuePaymentAction method, providing the checkoutSession used to create the payment.
getContinuePaymentAction method returns a ContinuePaymentAction object that describes the specific action required to continue the payment flow, depending on the provider and the specific step required.
ContinuePaymentAction response structure
The response contains information about the type of action required and the necessary data to perform that action:
ContinuePaymentAction Fields
Provider Types and Actions
The following enums define the supported payment providers and possible actions:Provider Types and Actions
Handling different action types
Based on theaction field in the response, you should handle each type of action accordingly:
REDIRECT_URL Action
When the action is REDIRECT_URL, you should redirect the user to the URL provided in data.redirect.init_url:
Other Action Types
Each action type requires specific handling based on the data provided:- PAYMENT_CODE: Display the payment code and reference to the user
- IMAGE: Show a QR code or other image to the user
- OTP: Present an OTP input form to the user
- SDK_PROVIDER: Initialize the specific provider’s SDK
- RENDER_IFRAME: Display an iframe with the provider’s interface
Payment Action HandlingThe specific implementation for handling each action type will depend on your application’s UI framework and requirements. Ensure you handle all possible action types that your configured payment providers might return.
Demo AppIn addition to the code examples provided, you can access the Demo App for a complete implementation of Yuno SDKs (clone from the repository).