Search in sources :

Example 6 with Response

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

the class PurchaseManagerTest method testPurchaseHappyPath.

/**
 * Test purchase happy path
 */
@Test
public void testPurchaseHappyPath() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.SUCCESSFUL, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(true).when(mockPurchaseSystem).receiptValidResponse();
    Response purchaseResponse = new Response("purchaseRequest", Response.Status.SUCCESSFUL, null);
    doReturn(purchaseResponse).when(mockPurchaseSystem).purchaseListenerResponse();
    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();
}
Also used : Response(com.amazon.purchase.model.Response) Test(org.junit.Test)

Example 7 with Response

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

the class PurchaseManagerTest method testUpdatePurchaseFailure.

/**
 * Tests for update purchase failure, asserting that the purchase update status is correctly
 * set
 */
@Test
public void testUpdatePurchaseFailure() throws Exception {
    Response response = new Response("getUserPurchaseDataSuccess", Response.Status.FAILED, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    mPurchaseManager.init(purchaseSystem, new PurchaseManagerListener() {

        @Override
        public void onRegisterSkusResponse(Response response) {
            assertEquals(Response.Status.FAILED, response.getStatus());
            verifyUtil.verified();
        }

        @Override
        public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
        }
    });
    Thread.sleep(1000);
    assertEquals(mPurchaseManager.mPurchaseSystem, purchaseSystem);
    assertEquals(PurchaseUtils.PurchaseUpdateStatus.FAILED, mPurchaseManager.PURCHASE_UPDATE_STATUS);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Test(org.junit.Test)

Example 8 with Response

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

the class PurchaseManagerTest method testPurchaseWithNonValidReceipt.

/**
 * Tests purchase with non valid receipt
 */
@Test
public void testPurchaseWithNonValidReceipt() throws Exception {
    Response response = new Response("isPurchaseValidRequest", Response.Status.FAILED, null);
    doReturn(response).when(mockPurchaseSystem).listenerResponse();
    doReturn(false).when(mockPurchaseSystem).receiptValidResponse();
    Response purchaseResponse = new Response("purchaseRequest", Response.Status.SUCCESSFUL, null);
    doReturn(purchaseResponse).when(mockPurchaseSystem).purchaseListenerResponse();
    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.FAILED, response.getStatus());
            assertFalse(validity);
            assertFalse(mPurchaseManager.mReceiptMap.containsKey("subSku"));
            verifyUtil.verified();
        }
    });
    Thread.sleep(1000);
    verify(verifyUtil).verified();
}
Also used : Response(com.amazon.purchase.model.Response) Test(org.junit.Test)

Example 9 with Response

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

the class MockIPurchaseImpl method getUserPurchaseData.

@Override
public String getUserPurchaseData(boolean reset) {
    List<Receipt> list = new ArrayList<>();
    list.addAll(TestUtils.receiptMap.values());
    Response response = listenerResponse();
    listener.onUserDataResponse(response, list, TestUtils.userData, false);
    return "getUserPurchaseDataSuccess";
}
Also used : Response(com.amazon.purchase.model.Response) Receipt(com.amazon.purchase.model.Receipt) ArrayList(java.util.ArrayList)

Example 10 with Response

use of com.amazon.purchase.model.Response 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)

Aggregations

Response (com.amazon.purchase.model.Response)21 Receipt (com.amazon.purchase.model.Receipt)11 Test (org.junit.Test)10 Date (java.util.Date)6 Product (com.amazon.purchase.model.Product)3 UserData (com.amazon.purchase.model.UserData)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Bundle (android.os.Bundle)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 IPurchase (com.amazon.purchase.IPurchase)1 PurchaseManagerListener (com.amazon.purchase.PurchaseManagerListener)1 Gson (com.google.gson.Gson)1 MarketplaceConnectBody (com.zype.fire.api.Model.MarketplaceConnectBody)1 MarketplaceConnectBodyData (com.zype.fire.api.Model.MarketplaceConnectBodyData)1 HashMap (java.util.HashMap)1