本文整理汇总了Java中com.github.jberkel.pay.me.model.Purchase类的典型用法代码示例。如果您正苦于以下问题:Java Purchase类的具体用法?Java Purchase怎么用?Java Purchase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Purchase类属于com.github.jberkel.pay.me.model包,在下文中一共展示了Purchase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
@Override
protected List<IabResult> doInBackground(final Purchase... purchases) {
if (purchases == null || purchases.length == 0) throw new IllegalArgumentException("no purchases");
mPurchases = new ArrayList<Purchase>(purchases.length);
Collections.addAll(mPurchases, purchases);
final List<IabResult> results = new ArrayList<IabResult>(purchases.length);
for (Purchase purchase : purchases) {
try {
mIabHelper.consume(purchase);
results.add(new IabResult(OK, "Successful consume of sku " + purchase.getSku()));
} catch (IabException ex) {
results.add(ex.getResult());
}
}
return results;
}
示例2: doInBackground
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
@Override
protected List<IabResult> doInBackground(final Purchase... purchases) {
if (purchases == null || purchases.length == 0)
throw new IllegalArgumentException("no purchases");
mPurchases = new ArrayList<Purchase>(purchases.length);
Collections.addAll(mPurchases, purchases);
final List<IabResult> results = new ArrayList<IabResult>(purchases.length);
for (Purchase purchase : purchases) {
try {
mIabHelper.consume(purchase);
results.add(new IabResult(OK, "Successful consume of sku " + purchase.getSku()));
} catch (IabException ex) {
results.add(ex.getResult());
}
}
return results;
}
示例3: onConsumeFinished
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
// We know this is the "gas" sku because it's the only one we consume,
// so we don't check which sku was consumed. If you have more than one
// sku, you probably should check...
if (result.isSuccess()) {
// successfully consumed, so we apply the effects of the item in our
// game world's logic, which in our case means filling the gas tank a bit
Log.d(TAG, "Consumption successful. Provisioning.");
mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
saveData();
alert("You filled 1/4 tank. Your tank is now " + String.valueOf(mTank) + "/4 full!");
}
else {
complain("Error while consuming: " + result);
}
updateUi();
setWaitScreen(false);
Log.d(TAG, "End consumption flow.");
}
示例4: shouldConsumeAsyncMultiplePurchase
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
@Test public void shouldConsumeAsyncMultiplePurchase() throws Exception {
shouldStartSetup_SuccessCase();
Purchase p1 = mock(Purchase.class);
when(p1.getToken()).thenReturn("foo");
when(p1.getItemType()).thenReturn(INAPP);
Purchase p2 = mock(Purchase.class);
when(p2.getToken()).thenReturn("bar");
when(p2.getItemType()).thenReturn(INAPP);
List<Purchase> purchases = new ArrayList<Purchase>();
purchases.add(p1);
purchases.add(p2);
OnConsumeMultiFinishedListener listener = mock(OnConsumeMultiFinishedListener.class);
when(service.consumePurchase(API_VERSION, Robolectric.application.getPackageName(), "foo")).thenReturn(OK.code);
when(service.consumePurchase(API_VERSION, Robolectric.application.getPackageName(), "bar")).thenReturn(ERROR.code);
helper.consumeAsync(purchases, listener);
List<IabResult> results = new ArrayList<IabResult>();
results.add(new IabResult(OK));
results.add(new IabResult(ERROR));
verify(listener).onConsumeMultiFinished(purchases, results);
}
示例5: onIabPurchaseFinished
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Util.log("Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
alert(getString(R.string.Error__error_processing_purchase));
setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
setWaitScreen(false);
return;
}
Util.log("Purchase successful.");
if (purchase.getSku().equals(SKU_PREMIUM)) {
// bought the premium upgrade!
Util.log("Purchase is premium upgrade. Congratulating user.");
mIsPremium = true;
updateUi();
setWaitScreen(false);
}
}
示例6: onQueryInventoryFinished
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Util.log("Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
alert(getString(R.string.Error__check_play_store));
complain("Failed to query inventory: " + result);
return;
}
Util.log("Query inventory was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Util.log("User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
updateUi();
if (mIsPremium) {
Util.alert(context,
getString(R.string.Dialog__purchased),
getString(R.string.Dialog__purchase_message),
Util.emptyClickListener,
null);
}
setWaitScreen(false);
Util.log("Initial inventory query finished; enabling main UI.");
}
示例7: verifyDeveloperPayload
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/**
* Verifies the developer payload of a purchase.
*/
boolean verifyDeveloperPayload(Purchase p) {
// String payload = p.getDeveloperPayload();
/*
* TODO: verify that the developer payload of the purchase is correct. It will be
* the same one that you sent when initiating the purchase.
*
* WARNING: Locally generating a random string when starting a purchase and
* verifying it here might seem like a good approach, but this will fail in the
* case where the user purchases an item on one device and then uses your app on
* a different device, because on the other device you will not have access to the
* random string you originally generated.
*
* So a good developer payload has these characteristics:
*
* 1. If two different users purchase an item, the payload is different between them,
* so that one user's purchase can't be replayed to another user.
*
* 2. The payload must be such that you can verify it even when the app wasn't the
* one who initiated the purchase flow (so that items purchased by the user on
* one device work on other devices owned by the user).
*
* Using your own server to store and verify developer payloads across app
* installations is recommended.
*/
return true;
}
示例8: onQueryInventoryFinished
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Util.log("Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) {
mPremiumListener.notPremium();
return;
}
// Is it a failure?
if (result.isFailure()) {
mPremiumListener.notPremium();
Util.log("Failed to query inventory: " + result);
return;
}
Util.log("Query inventory was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
boolean mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Util.log("User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
if (mIsPremium)
mPremiumListener.isPremium();
else
mPremiumListener.notPremium();
destroy();
Util.log("Initial inventory query finished; enabling main UI.");
}
示例9: verifyDeveloperPayload
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/**
* Verifies the developer payload of a purchase.
*/
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
/*
* TODO: verify that the developer payload of the purchase is correct. It will be
* the same one that you sent when initiating the purchase.
*
* WARNING: Locally generating a random string when starting a purchase and
* verifying it here might seem like a good approach, but this will fail in the
* case where the user purchases an item on one device and then uses your app on
* a different device, because on the other device you will not have access to the
* random string you originally generated.
*
* So a good developer payload has these characteristics:
*
* 1. If two different users purchase an item, the payload is different between them,
* so that one user's purchase can't be replayed to another user.
*
* 2. The payload must be such that you can verify it even when the app wasn't the
* one who initiated the purchase flow (so that items purchased by the user on
* one device work on other devices owned by the user).
*
* Using your own server to store and verify developer payloads across app
* installations is recommended.
*/
return true;
}
示例10: consume
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/**
* Consumes a given in-app product. Consuming can only be done on an item
* that's owned, and as a result of consumption, the user will no longer own it.
* This method may block or take long to return. Do not call from the UI thread.
* For that, see {@link #consumeAsync}.
*
* @param purchase The PurchaseInfo that represents the item to consume.
* @throws IabException if there is a problem during consumption.
*/
public void consume(Purchase purchase) throws IabException {
checkNotDisposed();
checkSetupDone("consume");
if (purchase.getItemType() != INAPP) {
throw new IabException(IABHELPER_INVALID_CONSUMPTION,
"Items of type '" + purchase.getItemType() + "' can't be consumed.");
}
try {
String token = purchase.getToken();
String sku = purchase.getSku();
if (token == null || token.equals("")) {
logError("Can't consume " + sku + ". No token.");
throw new IabException(IABHELPER_MISSING_TOKEN, "PurchaseInfo is missing token for sku: "
+ sku + " " + purchase);
}
logDebug("Consuming sku: " + sku + ", token: " + token);
int response = mService.consumePurchase(API_VERSION, mContext.getPackageName(), token);
if (response == OK.code) {
logDebug("Successfully consumed sku: " + sku);
} else {
logDebug("Error consuming consuming sku " + sku + ". " + getDescription(response));
throw new IabException(response, "Error consuming sku " + sku);
}
} catch (RemoteException e) {
throw new IabException(IABHELPER_REMOTE_EXCEPTION, "Remote exception while consuming. PurchaseInfo: " + purchase, e);
}
}
示例11: consumeAsync
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/**
* Asynchronous wrapper to item consumption. Works like {@link #consume}, but
* performs the consumption in the background and notifies completion through
* the provided listener. This method is safe to call from a UI thread.
*
* @param purchase The purchase to be consumed.
* @param listener The listener to notify when the consumption operation finishes.
*/
public void consumeAsync(Purchase purchase, OnConsumeFinishedListener listener) {
if (isDisposed()) {
if (listener != null) listener.onConsumeFinished(null, new IabResult(IABHELPER_DISPOSED));
return;
}
checkSetupDone("consume");
consumeAsyncInternal(Arrays.asList(purchase), listener, null);
}
示例12: handlePurchaseResult
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
private void handlePurchaseResult(String purchaseData,
String dataSignature,
PurchaseFlowState purchaseState) {
if (purchaseData == null || dataSignature == null) {
logError("BUG: either purchaseData or dataSignature is null." +
" data="+purchaseData+", signature="+dataSignature);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature"), null);
return;
}
try {
Purchase purchase = new Purchase(purchaseState.itemType, purchaseData, dataSignature);
if (!mSignatureValidator.validate(purchaseData, dataSignature)) {
logError("Purchase signature verification FAILED for " + purchase);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for purchase " + purchase),
purchase);
return;
}
logDebug("Purchase signature successfully verified.");
purchaseState.onIabPurchaseFinished(new IabResult(OK), purchase);
} catch (JSONException e) {
logError("Failed to parse purchase data.", e);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data."), null);
}
}
示例13: consumeAsync
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/**
* Asynchronous wrapper to item consumption. Works like {@link #consume}, but
* performs the consumption in the background and notifies completion through
* the provided listener. This method is safe to call from a UI thread.
*
* @param purchase The purchase to be consumed.
* @param listener The listener to notify when the consumption operation finishes.
*/
public void consumeAsync(Purchase purchase, OnConsumeFinishedListener listener) {
if (isDisposed()) {
if (listener != null)
listener.onConsumeFinished(null, new IabResult(IABHELPER_DISPOSED));
return;
}
checkSetupDone("consume");
consumeAsyncInternal(Arrays.asList(purchase), listener, null);
}
示例14: handlePurchaseResult
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
private void handlePurchaseResult(String purchaseData,
String dataSignature,
PurchaseFlowState purchaseState) {
if (purchaseData == null || dataSignature == null) {
logError("BUG: either purchaseData or dataSignature is null." +
" data=" + purchaseData + ", signature=" + dataSignature);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature"), null);
return;
}
try {
Purchase purchase = new Purchase(purchaseState.itemType, purchaseData, dataSignature);
if (!mSignatureValidator.validate(purchaseData, dataSignature)) {
logError("Purchase signature verification FAILED for " + purchase);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for purchase " + purchase),
purchase);
return;
}
logDebug("Purchase signature successfully verified.");
purchaseState.onIabPurchaseFinished(new IabResult(OK), purchase);
} catch (JSONException e) {
logError("Failed to parse purchase data.", e);
purchaseState.onIabPurchaseFinished(
new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data."), null);
}
}
示例15: verifyDeveloperPayload
import com.github.jberkel.pay.me.model.Purchase; //导入依赖的package包/类
/** Verifies the developer payload of a purchase. */
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
/*
* TODO: verify that the developer payload of the purchase is correct. It will be
* the same one that you sent when initiating the purchase.
*
* WARNING: Locally generating a random string when starting a purchase and
* verifying it here might seem like a good approach, but this will fail in the
* case where the user purchases an item on one device and then uses your app on
* a different device, because on the other device you will not have access to the
* random string you originally generated.
*
* So a good developer payload has these characteristics:
*
* 1. If two different users purchase an item, the payload is different between them,
* so that one user's purchase can't be replayed to another user.
*
* 2. The payload must be such that you can verify it even when the app wasn't the
* one who initiated the purchase flow (so that items purchased by the user on
* one device work on other devices owned by the user).
*
* Using your own server to store and verify developer payloads across app
* installations is recommended.
*/
return true;
}