我想在我的Android應用程序中將應用程序結算集成。我正在使用版本3 apis。爲此,我創建了一個被管理產品。使用In app billing進行測試「付款選項」
我跟隨此tutorial。以下是我的代碼。
IabHelper mHelper;
final String BONUS_BUDGET = "bonus_budget";
Button purchaseButton;
String applePrice, skuID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fantasy_login);
purchaseButton = (Button) findViewById(R.id.login_button);
String base64EncodedPublicKey = "MY BASE64 KEY";
MyLog.e(TAG, "onCreate");
mHelper = new IabHelper(this, base64EncodedPublicKey);
final IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// handle error
return;
} else {
Log.e(TAG,
"result : " + result.getResponse()
+ result.getMessage());
}
try {
if (inventory == null) {
Toast.makeText(FC_FantasyCricketLoginActivity.this,
"Inventory is null", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(
FC_FantasyCricketLoginActivity.this,
inventory.getSkuDetails(BONUS_BUDGET)
.getPrice().toString(),
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(FC_FantasyCricketLoginActivity.this,
"inventory catch block", Toast.LENGTH_LONG).show();
}
// Toast.makeText(FC_FantasyCricketLoginActivity.this, "",
// duration)
// Log.e(TAG,
// "Inventory :" + inventory.getSkuDetails(BONUS_BUDGET).);
//
// applePrice =
// inventory.getSkuDetails(BONUS_BUDGET).getPrice();
// skuID = inventory.getSkuDetails(BONUS_BUDGET).getSku();
// update the UI
}
};
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if (result.isSuccess()) {
Log.e(TAG, "Successfully set up in app billing");
List<String> additionalSkuList = new ArrayList<String>();
additionalSkuList.add(BONUS_BUDGET);
Log.e(TAG, "Size of list"
+ additionalSkuList.get(0).toString());
mHelper.queryInventoryAsync(true, additionalSkuList,
mQueryFinishedListener);
} else {
Log.e(TAG,
"Problem in setting of in app billing "
+ result.toString());
}
}
});
final IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
} else if (purchase.getSku().equals(skuID)) {
Log.e(TAG,
"Purchase done time:"
+ String.valueOf(purchase.getPurchaseTime())
+ "SKU id : " + purchase.getSku());
}
}
};
purchaseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mHelper.launchPurchaseFlow(FC_FantasyCricketLoginActivity.this,
skuID, 10001, mPurchaseFinishedListener,
"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
}
});
}
它顯示產品並顯示它處於測試模式。但在此之後,它顯示Payment Options
。我需要添加我的實際帳戶嗎?還是有沒有一種方法可以在不添加實際帳戶的情況下進行測試?
創建一個測試帳戶,並對其進行測試。 – Max
我可以添加測試電子郵件地址,但是如何添加測試帳戶? – keen