use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.
the class DefaultReceiptVerificationService method validateReceipt.
/**
* {@inheritDoc}
*/
@Override
public String validateReceipt(Context context, String requestId, String sku, UserData userData, Receipt receipt, IPurchase.PurchaseListener listener) {
Response purchaseResponse = new Response(requestId, Response.Status.SUCCESSFUL, null);
listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, true, userData);
return requestId;
}
use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.
the class PurchaseAction method purchased.
/**
* Inform the user of the request completion.
*
* @param requestId The request id of this call.
*/
private void purchased(String requestId) {
Log.d(TAG, "purchased mSku " + mSku + " with request " + requestId);
Response response = mPurchaseManager.purchaseResponseMap.get(requestId);
Receipt receipt = mPurchaseManager.purchaseReceiptMap.get(requestId);
/* Zype, Evgeny Cherkasov
* begin */
if (receipt != null) {
// Bundle receiptExtras = new Bundle();
// receiptExtras.putString("VideoId", mPurchaseManagerListener.getVideoId());
// receipt.setExtras(receiptExtras);
receipt.setExtras(mPurchaseManagerListener.getPurchaseExtras());
}
if (Response.Status.SUCCESSFUL.equals(response.getStatus())) {
if (receipt == null) {
// Hack for AmazonInAppPurchase, if the product was already purchased they do not
// return receipt, but the purchase is valid so we need to show the content. We
// also trigger an update purchases call here to fetch any latest purchases and
// update them in our system.
Log.i(TAG, "mSku already purchased, but is not stored in our system, " + "update inventory");
new UpdatePurchasesAction(mPurchaseManager, false).execute();
if (mPurchaseManagerListener != null) {
mPurchaseManagerListener.onValidPurchaseResponse(new Response(response.getRequestId(), Response.Status.SUCCESSFUL, null), true, mSku);
}
} else {
// Validate that the receipt received is not fake.
new PurchaseValidAction(mPurchaseManager, mSku, mPurchaseManagerListener, receipt).execute();
}
} else {
if (mPurchaseManagerListener != null) {
mPurchaseManagerListener.onValidPurchaseResponse(new Response(response.getRequestId(), Response.Status.FAILED, null), false, mSku);
}
}
cleanUp(requestId);
}
use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.
the class PurchaseManager method isPurchaseValid.
/**
* This tests that a purchase is still valid. Receipts can become obsolete at any point of
* time via external systems, such as cancelling a subscription. Its important to check that
* they are still valid before using them.
*
* @param sku The SKU of the receipt that needs to be validated.
* @param purchaseManagerListener The purchase manager listener.
*/
public void isPurchaseValid(String sku, PurchaseManagerListener purchaseManagerListener) {
validateSystemConfiguration();
if (addPendingAction(new PendingAction(sku, purchaseManagerListener, PendingAction.ACTION.IS_PURCHASE_VALID))) {
Log.i(TAG, "isPurchaseValid call for sku " + sku + " stored for future execution");
return;
}
if (sku == null) {
purchaseManagerListener.onValidPurchaseResponse(new Response(null, Response.Status.SUCCESSFUL, null), false, sku);
}
Receipt receipt = mReceiptMap.get(sku);
// Check if receipt stored with purchaseManager is expired.
if (!isLocalPurchaseDataValid(receipt)) {
Log.d(TAG, "local purchase not valid for " + receipt);
purchaseManagerListener.onValidPurchaseResponse(new Response(null, Response.Status.SUCCESSFUL, null), false, sku);
} else {
// Local receipt is still valid, now check the purchase system for receipt validity
Log.d(TAG, "local purchase is valid for " + receipt);
new PurchaseValidAction(this, sku, purchaseManagerListener, receipt).execute();
}
}
use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.
the class PurchaseHelper method initializePurchaseSystem.
/**
* Method to initialize purchase system
*/
private void initializePurchaseSystem() {
// The purchase system should be initialized by the module initializer, if there is no
// initializer available that means the purchase system is not needed.
IPurchase purchaseSystem = (IPurchase) ModuleManager.getInstance().getModule(IPurchase.class.getSimpleName()).getImpl(true);
if (purchaseSystem == null) {
Log.i(TAG, "Purchase system not registered.");
return;
}
try {
registerSkuForActions();
} catch (Exception e) {
Log.e(TAG, "Could not register actions!!", e);
}
// Register the purchase system received via ModuleManager and configure the purchase
// listener.
this.mPurchaseManager = PurchaseManager.getInstance(mContext.getApplicationContext());
try {
mPurchaseManager.init(purchaseSystem, new PurchaseManagerListener() {
@Override
public void onRegisterSkusResponse(Response response) {
if (response == null || !Response.Status.SUCCESSFUL.equals(response.getStatus())) {
Log.e(TAG, "Register products failed " + response);
} else {
// If there is a valid receipt available in the system, set content browser
// variable as true.
String sku = mPurchaseManager.getPurchasedSku();
if (sku == null) {
setSubscription(false, null);
} else {
setSubscription(true, sku);
}
Log.d(TAG, "Register products complete.");
}
mContentBrowser.updateContentActions();
}
@Override
public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
Log.e(TAG, "You should not hit here!!!");
}
/* Zype, Evgeny Cherkasov
* begin */
@Override
public void onProductDataResponse(Response response, Map<String, Product> products) {
Log.e(TAG, "You should not hit here!!!");
}
// @Override
// public String getVideoId() {
// Log.e(TAG, "You should not hit here!!!");
// return null;
// }
@Override
public Bundle getPurchaseExtras() {
Log.e(TAG, "You should not hit here!!!");
return null;
}
});
} catch (Exception e) {
Log.e(TAG, "Could not configure the purchase system. ", e);
}
}
use of com.amazon.purchase.model.Response in project zype-firebuilder by zype.
the class PurchaseManagerTest method testPurchaseForAlreadyPurchased.
/**
* Tests purchase for already purchased product
*/
@Test
public void testPurchaseForAlreadyPurchased() throws Exception {
Receipt receipt = TestUtils.createReceipt("subSku", "subSku", new Date(), null);
mPurchaseManager.mReceiptMap.put("subSku", receipt);
mPurchaseManager.init(purchaseSystem, null);
Thread.sleep(1000);
mPurchaseManager.purchaseSku("subSku", new PurchaseManagerListener() {
@Override
public void onRegisterSkusResponse(Response response) {
}
@Override
public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
assertEquals(Response.Status.SUCCESSFUL, response.getStatus());
assertTrue(validity);
assertTrue(mPurchaseManager.mReceiptMap.containsKey("subSku"));
verifyUtil.verified();
}
});
Thread.sleep(1000);
verify(verifyUtil).verified();
}
Aggregations