Search in sources :

Example 6 with Receipt

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());
        }
    };
}
Also used : UserDataResponse(com.amazon.device.iap.model.UserDataResponse) PurchasingListener(com.amazon.device.iap.PurchasingListener) Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) Product(com.amazon.purchase.model.Product) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) Response(com.amazon.purchase.model.Response) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) UserDataResponse(com.amazon.device.iap.model.UserDataResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse)

Example 7 with Receipt

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));
}
Also used : Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Receipt

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));
}
Also used : Context(android.content.Context) Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Receipt

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);
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt)

Example 10 with Receipt

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);
        }
    }
}
Also used : Receipt(com.amazon.purchase.model.Receipt)

Aggregations

Receipt (com.amazon.purchase.model.Receipt)17 Response (com.amazon.purchase.model.Response)11 Test (org.junit.Test)8 Date (java.util.Date)7 UserData (com.amazon.purchase.model.UserData)4 ArrayList (java.util.ArrayList)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Context (android.content.Context)1 PurchasingListener (com.amazon.device.iap.PurchasingListener)1 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)1 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)1 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)1 UserDataResponse (com.amazon.device.iap.model.UserDataResponse)1 Product (com.amazon.purchase.model.Product)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1