use of com.amazon.purchase.model.Receipt in project zype-firebuilder by zype.
the class AmazonInAppPurchase method createIapPurchasingListener.
/**
* Creates IAP purchase listener from PurchaseListener.
*/
/*package private*/
PurchasingListener createIapPurchasingListener(final PurchaseListener listener) {
Log.d(TAG, "PurchasingListener registered");
return new PurchasingListener() {
@Override
public void onUserDataResponse(UserDataResponse userDataResponse) {
Log.d(TAG, "UserDataResponse received " + userDataResponse.toString());
Response response = createResponse(isSuccessful(userDataResponse), userDataResponse.getRequestId().toString());
UserData userData = createUserDataFromIapUserData(userDataResponse.getUserData());
listener.onGetUserDataResponse(response, userData);
}
@Override
public void onProductDataResponse(ProductDataResponse productDataResponse) {
Log.d(TAG, "ProductDataResponse received " + productDataResponse.toString());
Response response = createResponse(isSuccessful(productDataResponse), productDataResponse.getRequestId().toString());
Map<String, Product> productMap = createProductMapFromProductDataResponse(productDataResponse.getProductData());
listener.onProductDataResponse(response, productMap, productDataResponse.getUnavailableSkus());
}
@Override
public void onPurchaseResponse(PurchaseResponse purchaseResponse) {
Log.d(TAG, "purchaseResponse received " + purchaseResponse.toString());
Response response = createResponse(isSuccessful(purchaseResponse), purchaseResponse.getRequestId().toString());
com.amazon.device.iap.model.Receipt iapReceipt = purchaseResponse.getReceipt();
String sku = null;
if (iapReceipt != null) {
sku = iapReceipt.getSku();
}
listener.onPurchaseResponse(response, sku, createReceipt(iapReceipt), createUserDataFromIapUserData(purchaseResponse.getUserData()));
}
@Override
public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse purchaseUpdatesResponse) {
Log.d(TAG, "purchaseUpdatesResponse received " + purchaseUpdatesResponse.toString());
Response response = createResponse(isSuccessful(purchaseUpdatesResponse), purchaseUpdatesResponse.getRequestId().toString());
List<Receipt> receipts = createReceiptList(purchaseUpdatesResponse.getReceipts());
UserData userData = createUserDataFromIapUserData(purchaseUpdatesResponse.getUserData());
listener.onUserDataResponse(response, receipts, userData, purchaseUpdatesResponse.hasMore());
}
};
}
use of com.amazon.purchase.model.Receipt in project zype-firebuilder by zype.
the class AmazonInAppPurchaseTest method testNotifyFulfillment.
@Test
public void testNotifyFulfillment() {
AmazonInAppPurchase purchase = new AmazonInAppPurchase();
purchase.notifyFulfillment("", new UserData("", ""), new Receipt(), Receipt.FulfillmentStatus.FULFILLED);
verifyStatic(times(1));
}
use of com.amazon.purchase.model.Receipt in project zype-firebuilder by zype.
the class AmazonInAppPurchaseTest method testisPurchaseValid.
@Test
public void testisPurchaseValid() {
AmazonInAppPurchase purchase = new AmazonInAppPurchase();
AReceiptVerifier verifier = mock(AReceiptVerifier.class);
purchase.registerReceiptVerification(verifier);
purchase.isPurchaseValid("", new UserData("", ""), new Receipt());
verify(verifier).validateReceipt(any(Context.class), any(String.class), any(String.class), any(UserData.class), any(Receipt.class), any(IPurchase.PurchaseListener.class));
}
use of com.amazon.purchase.model.Receipt 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.Receipt in project zype-firebuilder by zype.
the class PurchaseManager method registerReceiptSku.
/**
* Registers the new receipt with the purchase manager.
*
* @param receipt Receipt to be registered.
*/
private void registerReceiptSku(Receipt receipt) {
synchronized (receiptMapUpdateLock) {
if (receipt == null) {
return;
}
// We already have an existing receipt registered with this SKU.
if (mReceiptMap.containsKey(receipt.getSku())) {
Receipt existingReceipt = mReceiptMap.get(receipt.getSku());
Log.d(TAG, "existing key" + existingReceipt + " new receipt " + receipt);
// update it with new receipt
if (existingReceipt == null || existingReceipt.getPurchasedDate() == null || existingReceipt.getPurchasedDate().before(receipt.getPurchasedDate())) {
mReceiptMap.put(receipt.getSku(), receipt);
}
} else // As of now no receipt exist for this SKU
{
mReceiptMap.put(receipt.getSku(), receipt);
}
}
}
Aggregations