In-app Purchase¶
Before you begin¶
- You will need to Integrate the SohaGame SDK for iOS into your game.
- You will need to Integrate events for iOS into your game.
Overview¶
This guide explains how to integrate in-app purchases using the available APIs of the SohaGame SDK.
There are two ways to make in-app purchases:
1. Use the SDK's payment center interface¶
The SDK provides a payment center interface that displays a list of in-app purchase packages, you just need to open the payment center of the SDK for users to make purchases.
Call method openSDKPurchase
2. Use your interface¶
If you don't want to use the built-in interface of the SDK. For example: you want users to make a purchase when they click on an item pack in your game.
In this case, you need to follow these steps:
Step 1: Fetch list in-app purchase product¶
Call method getListProduct
to fetch list in-app purchase product
The following example demonstrates getListProduct
[SohaSDK getListProduct:^(NSArray *products, NSString *error) {
self.paylist = [NSArray new];
self.paylist = products;
}];
getListProduct
method returns the products
array, storing elements of type SohaIAPProduct
. You can use SohaIAPProduct
to display information about in-app purchases product.
Tip
Call getListProduct
method after user have selected character and save this data.
Step 2: Make in-app purchases¶
To make an in-app purchase, call the following method:
[SohaSDK payProductWithID:productID ext:ext];
//or
[SohaSDK payProductShowLoadingWithID:productID ext:ext];
- The ext parameter: is type string. You can pass json parameters like: payment Identifier, package name by Server Game. After successful payment, server SohaGame will return ext to the callback link for server Game (Game server callback link document here. )
The following example demonstrates payProductWithID
:
SohaIAPProduct *iap = (SohaIAPProduct *)self.paylist[1];
[SohaSDK payProductShowLoadingWithID:iap.order_info ext:""];
Step 3: In-app purchase events handling (optional)¶
When the in-app purchase is finished, the SDK will call back the success or failure events in the following delegates
- (void)sohaDidPurchaseSuccess:(SohaTransaction *)transaction{
};
- (void)sohaDidPurchaseFailed:(SohaTransaction *)transaction purchaseError:(NSString *)error{
}
Payment Callback¶
After the user successfully makes an in-app purchase, SohaGame's server will provide the transaction information to the game's server via paymetn callback. Based on this information, the game performs the addition of money or items to the user.
The API documentation for this section can be found here
See the diagram below to better understand the flow of in-app purchases
1: ClientGame calls the API in section 12 of the documentation to request transaction processing.
2-3: The SDK sends a request to the Server Platform SHG to process the transaction and make the payment with the Store.
4: The Server Platform SHG connects to the game server via a payment callback link for the game server to process the transaction and credit the money or in-game items, then display the result to the player. At the same time, the SHG server platform also receives information and sends it to the SDK. If the clientGame calls the API with the 'ext' parameter in step (1), the server platform will return the transaction information and 'ext' in the callback link. Refer to the documentation here
5: The SDK receives and processes the result:
-
Payment failure: The SDK will handle it automatically and notify the user in the game.
-
Payment success: The SDK will return the orderID to the clientGame through the delegate in the above documentation. If the clientGame has already received the result from the game server (the most accurate result), then there is no need to use the information returned from this SDK. It is used in case of necessity.
In essence, most of the steps in the transaction process are
Instructions for testing payment¶
Step 1: Check your AppleID account and log out of Media & Purchases section¶
Go to Settings -> Apple ID (log in with real account) -> Media & Purchases -> log out of the account.
Step 2: Log in to your SohaGameID test account¶
Open the application -> at the login screen -> log in with the Soha test account (mandatory as provided by SohaGame).
- SohaGameID Account: Provided by SohaGame
Step 3: Payment transactions with Sandbox account¶
When clicking on the recharge package -> a popup appears to enter the account -> log in with the sandbox account (provided by SohaGame according to the country) -> after logging in, proceed to complete the recharge.
- Sandbox Account: Provided by SohaGame in excel info file