Product API Usage Examples
The following are examples of using the Product API to manage World Currency and World Products.
This example allows you to get a basic understanding of the Product API and implement sending and receiving messages between the server and the client, so that you can easily test the granting and deducting world currencies and products.
This example includes descriptions of both the World Currency and World Product client scripts, followed by the integrated server script that handles all server-side processing, and includes the following functions:
- Granting World Currency
- Deducting World Currency
- Granting World Products without Currency Deduction
- Deducting World Products

Below is the complete client code for managing world currency granting and deduction, and how to implement it.

- When a character is loaded, a Room Message is sent to the server to load the existing balance of currency. The UI is then updated based on the balance information received from the server.
- To facilitate message exchange, the CurrencyMessage interface is defined.
- When a user increases or decreases their currency, they send a request to the server as a Room Message. It includes data about which currency to increase or decrease and by how much.
- The server then processes the increase or decrease in currency and sends the final balance information to the client. The client receives this information and updates the UI.

Below is the complete client code for managing world product granting and deduction, and how to implement it.

- When a character loads, use the InventoryService from ZEPETO.Inventory to load the initial inventory of products. Then update the UI.
- To send and receive messages, define the ProductMessage interface. Define a ProductAction Enum for the example implementation.
- When you increase or decrease a product, you send that data to the server as a Room Message. It includes data about which product to increase or decrease and by how much.
- After processing the product changes, the server sends the final inventory information to the client, which updates the UI accordingly.
- Generally, world products should cost currency to purchase.
- In this case, you can easily sell them with a Product Purchase Button by referring to the guide Monetize Your World! Setting Up Products and Currencies

Below is the complete server code that manages the world currency and products, and how to implement it.

- Use currency.credit() and currency.debit() to increase or decrease the balance of the desired currency. Afterward, call currency.getBalances() to get the current balance for each currency.
- Use inventory.add() and inventory.use() to increase or decrease the balance of the desired currency.
- Handles requests from clients for increasing or decreasing currencies and products.
- Use loadBalance() to get the currency information registered in ZEPETO Studio.
- If there are multiple currencies, you can condition on a specific currency ID value to get the balance of only that currency.
- Pass the final balance value to the client as a Room Message.