Step 2. Get the product list
Retrieve the PG product information registered in the Hive Console, such as product names, prices, and discount information. Use it to display to users the list of products they can currently choose and their exact prices.
Get PG product information
Retrieve the details of the PG products registered in the Hive Console. Display the retrieved product information to users.
FetchPgProductsAsync
To implement getting the PG product list, call FetchPgProductsAsync() provided by the Hive Axyl SDK. It returns the list of products sold through PG payments in the service standard format (Single Standard).
Call parameters
| Field name | Type | Required | Description |
|---|---|---|---|
| request | ProductPg | Required | The request data that contains the query conditions (such as the product type and market). |
| context | ApiCallContext | Optional | Per-call settings object that specifies the idempotency key, cancellation token, and request policy. If omitted, the default values are used. |
ProductPg
| Field name | Type | Required | Description |
|---|---|---|---|
AppVersion | string | Optional | The app version. Example: 1.0.0 |
Country | string | Required | The country information. Example: KR |
Currency | string | Required | The currency. Example: KRW |
Language | string | Required | The language. Example: ko |
ProductType | string | Optional | The product type. Example: consumable |
ProviderId | ProductPgProviderId (enum) | Required | The market identifier. Because this request is for PG product retrieval only, specify only Pg. |
ServerId | string | Optional | The server ID you check on the App Server tab after you register the app server in App Info > App Server by following Hive Console App Server. Example: server01 |
Call example
Check the success result of PaymentsFetchPgProductsResult and the domain-specific results (Outcome) defined by this method in the example below and in the response status. For the result model and handling principles of common failures (Failure) that prevent the request from being performed, see Common error handling.
using Hive.Axyl.Payments;
using Hive.Axyl.Core;
// payments: IPaymentsService registered during initialization (for how to retrieve it, see [Install and initialize the module](../init.md))
IPaymentsService payments = HiveCore.Resolve<IPaymentsService>();
// Create the request object that contains the query conditions.
var request = new ProductPg
{
ProductType = "consumable",
ProviderId = ProductPgProviderId.Pg,
Country = "KR",
Currency = "KRW",
Language = "ko"
};
PaymentsFetchPgProductsResult result = await payments.FetchPgProductsAsync(request);
switch (result)
{
case PaymentsFetchPgProductsResult.Success success:
// Build the in-app store screen with the product list refined into the standard format.
foreach (var product in success.Data.Products)
{
Debug.Log($"{product.ProductId}: {product.Title} ({product.DisplayPrice})");
}
break;
// Handle request validation failure results (Outcome)
case PaymentsFetchPgProductsResult.PaymentBadRequest:
case PaymentsFetchPgProductsResult.PaymentInvalidParameter:
// Check the request fields and required values.
break;
// Handle common Failure
case PaymentsFetchPgProductsResult.Failure failure:
HiveError err = failure.Problem;
Debug.LogError($"[{err.Code}] {err.Message} (trace: {err.TraceId})");
break;
// Safety net: unhandled results and unknown new results (UnknownOutcome)
default:
Debug.LogWarning($"Unhandled result: {result.GetType().Name}");
break;
}
Response data
On success, the result is contained in Data (ProductResponseData) of PaymentsFetchPgProductsResult.Success.
| Field name | Type | Required | Description |
|---|---|---|---|
Data.AppVersion | string | Optional | The app version. |
Data.Country | string | Optional | The country information. |
Data.Currency | string | Optional | The currency. |
Data.Language | string | Required | The language. |
Data.Products | IReadOnlyList<ProductProducts> | Optional | The list of product information refined into the standard format. |
Data.ProviderId | ProductProviderId (enum) | Required | The market identifier. This response returns Pg. |
Data.Meta | string | Optional | Response meta information. null if there is none. |
ProductProducts
| Field name | Type | Required | Description |
|---|---|---|---|
Currency | string | Optional | The currency. Example: KRW |
Description | string | Optional | The product description. |
DisplayOriginalPrice | string | Optional | The pre-discount price for display. Example: ₩1,100 |
DisplayPrice | string | Optional | The price for display. Example: 1,200 KRW |
OriginalPrice | decimal | Optional | The pre-discount price. It may include decimals depending on the currency. Example: 1100 or 11.00 |
Price | decimal | Optional | The price. It may include decimals depending on the currency. Example: 1200 or 9.99 |
ProductId | string | Optional | The unique identifier (PID) of the product. |
ProductType | string | Optional | The product type. subscription (subscription product), consumable (consumable product) |
Title | string | Optional | The product title. Example: 1000 Gold |
Response example
// Example of success.Data in the Success branch
// success.Data.ProviderId = ProductProviderId.Pg
// success.Data.Currency = "KRW"
// success.Data.Products[0].ProductId = "com.game.product1"
// success.Data.Products[0].Title = "1000 Gold"
// success.Data.Products[0].Price = 1200.0
// success.Data.Products[0].DisplayPrice = "1,200 KRW"
// success.Data.Products[0].ProductType = "consumable"
Response status
The following table summarizes the success result of PaymentsFetchPgProductsResult and the domain-specific results (Outcome) defined by this method. For the result model and handling principles of common failures (Failure) that prevent the request from being performed, see Common error handling.
| Response case | Description | App client handling |
|---|---|---|
Success | The product list was retrieved successfully. Data contains the product list in the standard format. | Build the in-app store screen with the product list |
PaymentBadRequest | The request cannot be processed. | Check the request values and call conditions |
PaymentInvalidParameter | Invalid parameter. | Check the request field values and send the request again |
UnknownOutcome | A domain-specific result that the SDK does not recognize. | Treat it as a failure and log the result code |
Failure | Common Failure. See Common error handling. | Handle it according to the common error handling guidelines |