Skip to content

In-app Purchase

Before you begin

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 pay

 private void onPayment(){
        SohaSDK.getInstance().pay(this, new PaymentCallback() {
            @Override
            public void onSuccess(SohaPaymentResult sohaPaymentResult) {
                Log.d("mytag", "Payment sucess : order id = "+sohaPaymentResult.getOrderId());
                //write code here
            }

            @Override
            public void onError() {

            }

            @Override
            public void onCancel() {

            }
        });
    }

After a successful payment will call the function onSuccess

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

private void getListProduct() {
        SohaSDK.getInstance().getListProduct(new PaymentNewCallBack() {
            @Override
            public void onSuccess(ListIap listIap) {
                paymentAdapter.setData(listIap.getData());
                List<IapItem> list = listIap.getData();
            }

            @Override
            public void onFailure() {

            }
        });
    }

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:

// add params: custom ext
    private void pay(String orderInfo, String ext) {
        SohaSDK.getInstance().payProduct(getActivity(), orderInfo, new OnPayListener() {
            @Override
            public void onSuccessPaymentCoin(String transID,String message)  {

            }

            @Override
            public void onMaintenancePayment() {

            }

            @Override
            public void onFail() {

            }
        }, ext);
    }
- The orderInfo parameter: order_info( com.game.appdemo.tuixu1,..) provided by SohaGame.
- The ext parameter (optional): 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. )

After integrating the APIs, immediate payment testing is not possible. we need the first build to push for Internal Testing

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

iap diagram

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 - callback 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 performed implicitly by the SDK and on the server side. The game client only needs to focus on steps 1, 4, and 5 (as marked above). In reality, step 5 is also not necessary.