C. Point Management

Points can be managed by Tnk Server or by your server depending on the 'Point management' setting. When you selected 'Managed by Tnk', all points are managed by Tnk server and you can inquiry and withdraw points of users using APIs described in this chapter. If you selected 'Callback URL', all the point reward events are sent to your server through the callback URL you entered. For callback URL, see 1.6 Callback URL.

1) Inquiry Points

Inquiry amount of points of a user from Tnk server. Because this method is invoked in async way, you have to define TnkAdEventHandler and assign it to TnkAdPlugin before invocation.

Method 
  - void TnkAdPlugin::queryPoint(int handlerId)

Description
   This method returns amount of points of a user managed by Tnk server. This method works asynchronously and delivers return values by invoking onReturnQueryPoint() method in the EventHandler.

Parameters
 Name Description
 handleId When a return values is arrived, it is delivered to onReturnQueryPoint(int handleId, int point) method of TnkAdEventHandler with this values in the first parameter. Amount of points are returned as second parameter.

2) Purchase Items

Use this method to decrease user points managed by Tnk server. Because this method is invoked in async way, you have to define TnkAdEventHandler and assign it to TnkAdPlugin before invocation.

Method 
  - void TnkAdPlugin::purchaseItem(int itemCost, const char* itemName, int handleId)

Description
   Decrease user points in Tnk server. This method works asynchronously and delivers return values by invoking onReturnPurchaseItem() method in the EventHandler.

Parameters
 Name Description
 itemCostamount of points to decrease.
 itemNameItem name or Id to purchase. 
This value is used only for logging purpose.
 handleId When a return values is arrived, it is delivered to onReturnPurchaseItem(int handleId, long curPoint, long seqId) method of TnkAdEventHandler with this values in the first parameter.
The second parameter in the callback contains amount of points left in Tnk server, and the third parameter, seqId, contains an unique  transaction Id. 
 If the amount of points of a user is less than itemCost value, points will not be decreased and seqId of negative value is returned. 

Sample Code

// HelloWorldScene.h


void HelloWorld::itemPurchased() {


TnkAdPlugin::purchaseItem(100, "item_08", 8);

}


// HelloWorldScene.cpp


void HelloWorld::onReturnPurchaseItem(int handlerId, long curPoint, long seqId) {

    if (seqId < 0) {

        CCMessageBox("Not enough coin!", "Error");

    }

    else {

        char buf[100];

        sprintf(buf, "Item purchase OK : curPoint = %ld, seqId = %ld", curPoint, seqId);

        CCMessageBox(buf, "Alert");

    }

}


Comments