|
| 1 | +--- |
| 2 | +layout: manual |
| 3 | +language: en |
| 4 | +github: https://github.com/defold/extension-xsolla |
| 5 | +title: Xsolla documentation |
| 6 | +brief: This manual covers how to integrate and use Xsolla services in Defold. |
| 7 | +--- |
| 8 | + |
| 9 | +# Xsolla documentation |
| 10 | + |
| 11 | +This extension provides an integration with the Xsolla services for Defold. [Xsolla](https://xsolla.com) is an American financial technology company that makes payment software for video games. Xsolla solutions work in 200+ geographies, with 1,000+ payment methods, and with 130+ currencies in 20+ languauges. The integration currently supports the following Xsolla services: |
| 12 | + |
| 13 | +* [Shop Builder API](https://developers.xsolla.com/api/shop-builder/overview/) |
| 14 | + |
| 15 | + |
| 16 | +# Installation |
| 17 | +To use Xsolla services in your Defold project, add a version of the Xsolla integration to your `game.project` dependencies from the list of available [Releases](https://github.com/defold/extension-xsolla/releases). Find the version you want, copy the URL to ZIP archive of the release and add it to the project dependencies. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +Select `Project->Fetch Libraries` once you have added the version to `game.project` to download the version and make it available in your project. |
| 22 | + |
| 23 | + |
| 24 | +# Usage |
| 25 | + |
| 26 | +## Shop Builder API |
| 27 | + |
| 28 | +### Authentication |
| 29 | + |
| 30 | +Most of the Shop Builder API functions require authentication and a valid user token before use. Xsolla provides [many options for user authentication](https://developers.xsolla.com/api/login/overview/#section/Authentication/Getting-a-user-token), ranging from basic username and password authentication to authentication via a social network or publishing platform such as Steam. Developers releasing games via Crazy Games can generate an Xsolla token using the [`crazygames.get_xsolla_user_token()` API function of the Crazy Games for Defold SDK](https://defold.com/extension-crazygames/crazygames_api/#crazygames.get_xsolla_user_token:callback). |
| 31 | + |
| 32 | +Once you have an Xsolla user token you can pass it to the Shop Builder API: |
| 33 | + |
| 34 | +```lua |
| 35 | +local shop = require("xsolla.shop") |
| 36 | + |
| 37 | +shop.set_bearer_token(token) |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | +### Requests |
| 42 | + |
| 43 | +The Shop Builder API uses a REST API where each endpoint is represented by a Lua function. Each function takes a number of arguments and optional callback function, retry policy and cancellation token. Example: |
| 44 | + |
| 45 | +```lua |
| 46 | +local shop = require("xsolla.shop") |
| 47 | + |
| 48 | +local function on_sellable_items(items, err) |
| 49 | + -- do something with the sellable items |
| 50 | + pprint(items) |
| 51 | +end |
| 52 | + |
| 53 | +local function get_sellable_items() |
| 54 | + local project_id = "123456" |
| 55 | + local limit = 5 |
| 56 | + local offset = 0 |
| 57 | + local locale = "en" |
| 58 | + local additional_fields = nil |
| 59 | + local country = "US" |
| 60 | + local promo_code = "WINTER2021" |
| 61 | + local show_inactive_time_limited_items = 1 |
| 62 | + shop.get_sellable_items(project_id, limit, offset, locale, additional_fields, country, promo_code, show_inactive_time_limited_items, on_sellable_items) |
| 63 | +end |
| 64 | +``` |
| 65 | + |
| 66 | +It is also possible to use synchronous requests (using Lua coroutines). Example: |
| 67 | + |
| 68 | +```lua |
| 69 | +local function get_sellable_items() |
| 70 | + -- run the request within a coroutine |
| 71 | + shop.sync(function() |
| 72 | + local project_id = "123456" |
| 73 | + local limit = 5 |
| 74 | + local offset = 0 |
| 75 | + local locale = "en" |
| 76 | + local additional_fields = nil |
| 77 | + local country = "US" |
| 78 | + local promo_code = "WINTER2021" |
| 79 | + local show_inactive_time_limited_items = 1 |
| 80 | + local items, err = shop.get_sellable_items(project_id, limit, offset, locale, additional_fields, country, promo_code, show_inactive_time_limited_items) |
| 81 | + |
| 82 | + -- do something with the sellable items |
| 83 | + pprint(items) |
| 84 | + end) |
| 85 | +``` |
| 86 | + |
| 87 | +## Example |
| 88 | + |
| 89 | +[Refer to the example project](https://github.com/defold/extension-xsolla/tree/master/example) to see a complete example of how the intergation works. |
| 90 | + |
| 91 | + |
| 92 | +## Source code |
| 93 | + |
| 94 | +The source code is available on [GitHub](https://github.com/defold/extension-xsolla) |
| 95 | + |
| 96 | + |
| 97 | +## API reference |
0 commit comments