Search in sources :

Example 16 with Receipt

use of com.amazon.purchase.model.Receipt in project zype-firebuilder by zype.

the class PurchaseManagerTest method testIsPurchaseValidForNonValidPurchase.

/**
 * tests isPurchaseValid for non valid purchase
 */
@Test
public void testIsPurchaseValidForNonValidPurchase() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.SUCCESSFUL, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(false).when(mockPurchaseSystem).receiptValidResponse();
    mPurchaseManager.init(purchaseSystem, null);
    Thread.sleep(1000);
    Receipt receipt = TestUtils.createReceipt("rentSku", "rentSku", DateAndTimeHelper.addSeconds(new Date(), 25), null);
    mPurchaseManager.mReceiptMap.put("rentSku", receipt);
    mPurchaseManager.isPurchaseValid("rentSku", new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
            assertEquals(Response.Status.SUCCESSFUL, response.getStatus());
            assertFalse(validity);
            assertFalse(mPurchaseManager.mReceiptMap.containsKey("rentSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Receipt

use of com.amazon.purchase.model.Receipt in project zype-firebuilder by zype.

the class TestUtils method createReceipt.

public static Receipt createReceipt(String sku, String receiptTitle, Date purchaseDate, Date expiryDate) {
    Receipt receipt = new Receipt();
    receipt.setPurchasedDate(purchaseDate);
    receipt.setSku(sku);
    receipt.setReceiptId(receiptTitle);
    receipt.setExpiryDate(expiryDate);
    return 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