Jump to: navigation, search

Payment system API

Revision as of 14:05, 17 March 2015 by Anysdk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Configure listener

User system has callback information. Developer needs to configure a listener and override listener method.

class PluginChannel:public PayResultListener
    virtual void onPayResult(PayResultCode ret, const char* msg, TProductInfo info);
Developer needs to override onPayResult method
std::map<std::string , ProtocolIAP*>*   _pluginsIAPMap= AgentManager::getInstance()->getIAPPlugin();
std::map<std::string , ProtocolIAP*>::iterator iter;
for(iter = _pluginsIAPMap->begin(); iter != _pluginsIAPMap->end(); iter++)

Payment process




1.Game clients APP calls AnySDK Framework payment port to request order number
2.AnySDK Framework obtains order number
3.AnySDK Framework request payment from SDK server
4.After successfull payment, SDK server syncs up notification to AnySDK Framework (game client)
5.SDK server will asynchronously notify AnySDK server
6.AnySDK server responds to SDK server
7.AnySDK server will notify Game server of the payment results
8.Game server will respond to AnySDK payment notification
9.Game server verifies payment notification and releases item

Multiple payment methods

AnySDK Framework supports four payment methods: Dang Le SDK payment method, China Mobile, China Unicom and China Telecom. Develper needs to offer relevant UI for implementing multiple payment logic.

std::map<std::string , ProtocolIAP*>::iterator it = _pluginsIAPMap->begin();
     if(_pluginsIAPMap->size() == 1)/There is only one kind of payment method

      else //Multiple payment method
	   //Developer needs to design their own logic and UI for multiple payment method, example included in Sample

Related APIs


When loading plug-ins, the entire SDK is already initialized. The developer does not need to initialize separately. After user system is initialized, there will be a callback of related information, see following:

callback information code msg
Initialization successfull kPayInitSuccess simple description of null or error information
Initialization failed kPayInitFail simple description of null or error information


void payForProduct(TProductInfo info);
TProductInfo is actually a map, and tracks payment related information. Developer needs to provide below payment parameters:
Note: When calling the payment function some player information parameters need to be imported (such as character name, ID, level). This is compulsory as requested by certain channels (such as UC, Xiaomi) and will not be used in any way by AnySDK. If developers do not add this information or add fake data, it will not pass channel QA.

Parameter Need to be transmiteed Parameter description
Product_Id Y Product ID (Lenovo, Qi Xiazi, Coolpad product IDs need to be the same as the product IDs configured by the channels)
Product_Name Y Product name
Product_Price Y Product price (type, currency)
Product_Count Y Product amount (unless the game needs to support a feature where multiple items can be purchased with one click, otherwise fillling in 1 will suffice)
Role_Id Y Game character ID
Role_Name Y Game character name
Role_Grade Y Game character level
Role_Balance Y User in-game virtual currency balance, such as silver, gold coins, talismans
Server_Id Y Server ID, if there is none, fill in “1”
EXT N Expansion field

Product_Price needs to be transmitted in whole numbers since some SDK do not recognize floating points.

Callback information
Callback information code msg
Payment successfully kPaySuccess simple description of null or error information
Payment cancelled kPayCancel simple description of null or error information
Payment failed kPayFail simple description of null or error information
Payment network error kPayNetworkError simple description of null or error information
Payment information incomplete kPayProductionInforIncomplete simple description of null or error information

Take an example

void PluginChannel::pay()
    std::map<std::string , ProtocolIAP*>::iterator it = _pluginsIAPMap->begin();
        productInfo["Product_Price"] = "1";
        productInfo["Product_Id"] = "101";
        productInfo["Product_Name"] = "gold";
        productInfo["Server_Id"] = "13";
        productInfo["Product_Count"] = "1";
        productInfo["Role_Id"] = "1";
        productInfo["Role_Name"] = "1";
        if(_pluginsIAPMap->size() == 1)//只存在一种支付方式There is only one kind of payment method
        else //Multiple payment method
            //Developer needs to design their own logic and UI for multiple payment method


//payment callback
//process callback function 		
case kPaySuccess://payment successfull callback
//after succesfull payment, game processes correspondingly
case kPayNetworkError://payment network error callback
case kPayCancel:// payment failed callback
case kPayProductionInforIncomplete://payment information incomplete callback
case kPayFail://payment failed callback
//after failed payment, game processes correspondingly

Obtain order number

std::string getOrderId() User can obtain order number through this function.