Skip to content

Instantly share code, notes, and snippets.

@yalab
Created March 18, 2015 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yalab/76576966c9475aa2510e to your computer and use it in GitHub Desktop.
Save yalab/76576966c9475aa2510e to your computer and use it in GitHub Desktop.
cocos2d-x でピンポイントに GooglePlay の課金を消費させる関数
private void clearPurchases() {
mHelper = new IabHelper(getContext(), "GOOGLE_TOKEN");
mHelper.enableDebugLogging(true);
Log.v(TAG, "mHelper.startSetup");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// 失敗した時の処理
}
List additionalSkuList = new ArrayList();
additionalSkuList.add("IAP_ID");
mHelper.queryInventoryAsync(true, additionalSkuList, new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
// エラー時のハンドリング
return;
}
Purchase purchase = inventory.getPurchase("IAP_ID");
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
Log.v(TAG, "consume Success" + purchase.getSku());
}
else {
Log.v(TAG, "consume failure" + purchase.getSku());
}
}
};
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment