Payment

Prev Next

Available in Classic and VPC

Payment

You can sell in-game items using the in-app payment feature provided by the GAMEPOT SDK. Before checking out, you need to set Configuration by store to match the applicable store. Also, if the item has not been added to Dashboard > Payment > In-app, an error "ProductID not found" will occur.

Android

(AOS) Import in-app information

When checking out, you need to display payment information and local currency information on the page. You can use the functions below to get the current payment currency, name, etc. If it doesn't work, check your console settings.

Kotlin:

import com.nbase.sdk.Store

NBase.getProductItems() {products, e -> 
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        // In-app item information
        Log.e("NBase", products)
    }
}

Java:

NBase nBase = NBase.INSTANCE;

nBase.getProductItems((products, e) -> {
    if (e != null) {
        Log.e("NBase", "getProductItems fail: " + e.getMessage());
    } else {
        if (products != null) {
            Log.e("NBase", "getProductItems success: " + products.toString());
        }
    }
    return null;
});
  • Callback
Key Type Description
id String Product ID
productName String Product name
title String Product title
price Float Product price
localizedPrice Float Localized price
productId String Unique ID of the product
productType String Product type
productDescription String Product description
currency String Currency unit

(AOS) Request payment

You can request payment by productId in the imported in-app information.

Kotlin:

import com.nbase.sdk.Store

NBase.purchase(activity, Store.GOOGLE, productId, metadata, options) { purchase, e -> 
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", purchase)
    }
}

Java:

import com.nbase.sdk.Store;

NBase nBase = NBase.INSTANCE;
nBase.purchase(activity, storeId, productId, metadata, options, (purchase, e) -> {
    if (e != null) {
        Log.e("NBase", "purchase fail: " + e.getMessage());
    } else {
        if (purchase != null) {
            Log.e("NBase", "purchase success: " + purchase.toString());
        }
    }
    return null;
});
  • Parameter
Key Type Description Required
activity Activity Current activity O
storeId Store Store ID (See the following table) O
productId String Product ID (Dashboard → Payment → In-app item) O
metadata String Metadata X
options String Payment options feature X
Key Description
Store.GOOGLE Google Play Store
Store.ONE ONE Store
Store.GALAXY Galaxy Store
Store.AMAZON Amazon Store
Store.HUAWEI Huawei Store
  • Callback
Key Type Description
id String ID
orderId String Order ID
storeId String Store ID
productId String Product ID
billingKey String Payment key
signature String Signature
originalJson String Source JSON
developerPayload String Developer payload
packageName String Package name
isAcknowledged bool Confirmation status
purchaseState String Purchase status
purchaseTime String Purchase time
quantity String Quantity
recurringState String Recurring payment status
currency String Currency
country String Country
paymentId String Payment ID
price Float Pricing
iapVersion String In-app payment version
playerId String Player ID
serverId String Server ID
level Int Level
userdata String User data
metadata String Metadata
options String Options
authCode String Authentication code

iOS

(iOS) Import in-app information

When checking out, you need to display payment information and local currency information on the page. You can use the functions below to get the current payment currency, name, etc. If it doesn't work, check your console settings.

Swift:

let products = NBase.getProductItems()

Objective-C:

[NBaseBridge.shared getProductItems:^(NSString * _Nullable result) {
    NSLog(@"getProductItems result: %@", result);
}];
  • Callback
Key Type Description
id String Product ID
productId String Unique ID of the product
productName String Product name
productType String Product type
currency String Currency
price Float64 Product price
localizedPrice String Localized price
productDescription String Product description

(iOS) Request payment

You can request payment by productId in the imported in-app information.

Swift:

NBase.purchase(productId: productId, metadata: metadata, options: options) { result in
    switch result {
    case .success(let data):
        NBase.showToast(message: data?.encodeToJson() ?? "")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
}

Objective-C:

[NBaseBridge.shared purchase:productId metadata:metadata options:options :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"purchase Error: %@", error.localizedDescription);
    } else {
        NSLog(@"purchase succeeded with result: %@", result);
    }
}];
  • Parameter
Key Type Description Required
productId String Product ID (Dashboard > Payment > In-app item) O
metadata String Metadata X
options String Payment options feature X
  • Callback
Key Type Description
orderId String Order ID
receipt String Receipt
signature String Signature
productId String Product ID
storeId String Store ID
country String Country
quantity Int Quantity
paymentId String Payment ID
currency String Currency
serverId String Server ID
playerId String Player ID
userdata String User data
metadata String Metadata
options String Payment options
authCode String Authentication code
level Int Level
price Float64 Pricing

Unity

(Unity) Import in-app information

When checking out, you need to display payment information and local currency information on the page.
You can use the functions below to get the current payment currency, name, etc. If it doesn't work, check your console settings.

NBaseSDK.NBase.getProductItems(Store.google.ToString(), (products, error) => 
{
    if (products != null && products.Count > 0)
    {
        // Go through the list of products.
        foreach (var product in products)
        {
            // It shows the information of each product as a toast message.
            // In the example, product.ToString() is called,
            // but in reality, you can display the specific properties (e.g., name, price, etc.).
            NBaseSDK.NBase.showToast(product.ToString());
        }
    }
    else
    {
        // If the product list is empty, the user will be notified.
        NBaseSDK.NBase.showToast("The product list is empty.");
    }
});
  • Callback
Key Type Description
Products[].id string Product ID
Products[].title string Product title
Products[].productId string Unique ID of the product
Products[].productType string Product type
Products[].productName string Product name
Products[].productDescription string Product description
Products[].currency string Currency unit
Products[].price float Product price

(Unity) Request payment

You can request payment by productId in the imported in-app information.

NBaseSDK.NBase.purchase(Store.google.ToString(), productId, metadata, options, (purchase, error) => 
{
    if (error != null)
    {
        Debug.Log(error.Message.ToString());
        return;
    }
    // Payment succeeded.
});
  • Parameter
Key Type Description Required
storeId string Store ID (See the following table) O
productId string Product ID (Dashboard → Payment → In-app item) O
metadata string Metadata X
options string Payment options feature X
Key Description
Store.google.ToString() Google Play Store
Store.one.ToString() ONE Store
Store.galaxy.ToString() Galaxy Store
Store.amazon.ToString() Amazon Store
Store.huawei.ToString() Huawei Store
  • Callback
Key Type Description
storeId string Store's unique ID
paymentId string Payment ID
iapVersion string In-app payment version
productId string Product ID
billingKey string Billing key
signature string Signature
originalJson string Source JSON
orderId string Order ID
developerPayload string Developer payload
packageName string Package name
isAcknowledged bool Confirmation status
purchaseState int Purchase status
purchaseTime long Purchase time
price float Pricing
quantity int Quantity
currency string Currency unit

Troubleshooting

Q. A ProductID not found error occurs.
A. Check if the applicable product ID is registered in Dashboard > Payment > In-app .

Q. The payment is not going through.
A. See Configuration by store and check if the settings applicable for the store have been completed.

Q. (Android) java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/billingclient/api/BillingClient;
A. Add the following code.

<androidPackage spec="com.android.billingclient:billing:6.1.0" /> 

Q. (iOS) In-app information cannot be retrieved.
A. Make sure that the in-app product information and app environment (Production/Sandbox) are the same as those registered in Apple Connect.