Payment Selection (Unity SDK)

The payment selection flow includes a UI where a user selects the payment method they wish to use for the purchase. This flow does not wrap the calls made to create or pay an invoice, and instead returns the payment method ID the user selects. At this point, you will need to make calls to create and pay the invoice outside of the SDK.

Tilia Hosted Checkout

Prerequisites

  • Authorized User Password Token (A User Password Token is a string that enables Tilia Pay to verify that a request belongs to an authorized session)
note

All methods and flows in the Tilia SDK require you to have a server setup that communicates with Tilia’s APIs (your server will have a private api key which needs to remain secure and should never be exposed to client-side applications). Your client application should communicate with your own api (ensuring user authentication) to retrieve data required by the Tilia SDK.

Server-Side Code Example to Retrieve User Access Token

  • Requires your server to retrieve a client credentials access token. See more here .
  • Requires an account id for a user that has been registered with Tilia. See more here .
Copy
Copied
curl -i -X POST \
  https://auth.staging.tilia-inc.com/authorize/user \
  -H 'Authorization: Bearer <CLIENT_CREDENTIALS_ACCESS_TOKEN_HERE>' \
  -H 'Content-Type: application/json' \
  -d '{
    "account_id": "<USER_ACCOUNT_ID_HERE>",
    "return_token": true,
  }'

Example Responce Payload

Copy
Copied
{
    "status": "Success",
    "message": [],
    "codes": [],
    "payload": {
        "token": {
            "access_token": "USER_PASSWORD_TOKEN",
            "token_type": "Bearer",
            "refresh_token": "REFRESH_TOKEN",
            "expiry": "TOKEN_EXPIRATION"
        }
    }
}

Your api should return the access_token to your client application to use in the Tilia SDK. For more information on the /authorize/user endpoint go here

C# Code Example

This code snippet is an example of how to execute the Payment Selection Flow from inside your own code.

  • This example assumes that your code contains a variable called TiliaManager that is a valid reference to a TiliaUIManager class that is active in your Unity scene (part of the standard Tilia Canvas Group).
  • TiliaUIMessages.Message is a static function that assumes you have the TiliaUIMessages class active in your Unity scene (part of the standard Tilia Canvas Group).
Copy
Copied
public void DoPaymentSelectionFlow()
{
    TiliaManager.PaymentSelectionFlow(
    (result) => {
        // Completed
        // result is a TiliaEvent class
        // result.Data is a string value containing the ID of the payment method chosen by the user.
        TiliaUIMessages.Message("The user selected payment method " + result.Data + ".");
    },
    (result) => {
        // Canceled
        // result is a TiliaEvent class
        TiliaUIMessages.Message("The user canceled the payment selection flow.");
    },
    (result) => {
        // Error
		// result is a TiliaEvent class
        // result.Payload is an object of TiliaResponse type which includes API error data such as the web server response code and any API specific messages.
        TiliaUIMessages.Message("There was an error while attempting to execute payment selection flow.");
    });
}

GetPaymentMethods

In the case of a virtual purchase, the call to pay an invoice will fail if the user does not have enough funds in their spendable token balance to cover the invoice. If you would like, you can employ the GetPaymentMethods function to see if their balance will cover the invoice.

Example

Copy
Copied
TiliaReturnCode GetPaymentMethods(Action onComplete, TiliaToken authToken = null)
  • onComplete: Action callback event. Callback happens on both success and failure.
  • authToken: Optional authentication token to use. If not specified, will default to SDK global auth token.