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();
}
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();
}
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();
}
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";
}
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());
}
};
}
Aggregations