Search in sources :

Example 1 with PurchaseUpdatesResponse

use of com.amazon.device.iap.model.PurchaseUpdatesResponse 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 2 with PurchaseUpdatesResponse

use of com.amazon.device.iap.model.PurchaseUpdatesResponse in project SeriesGuide by UweTrottmann.

the class AmazonPurchasingListener method onPurchaseUpdatesResponse.

/**
 * Callback for {@link PurchasingService#getPurchaseUpdates}.
 *
 * You will receive receipts for all possible purchase history from this callback.
 */
@Override
public void onPurchaseUpdatesResponse(final PurchaseUpdatesResponse response) {
    Timber.d("onPurchaseUpdatesResponse: requestId (%s) purchaseUpdatesResponseStatus (%s) userId (%s)", response.getRequestId(), response.getRequestStatus(), response.getUserData().getUserId());
    final PurchaseUpdatesResponse.RequestStatus status = response.getRequestStatus();
    switch(status) {
        case SUCCESSFUL:
            iapManager.setAmazonUserId(response.getUserData().getUserId(), response.getUserData().getMarketplace());
            for (final Receipt receipt : response.getReceipts()) {
                iapManager.handleReceipt(receipt, response.getUserData());
            }
            if (response.hasMore()) {
                PurchasingService.getPurchaseUpdates(false);
            }
            iapManager.reloadPurchaseStatus();
            break;
        case FAILED:
        case NOT_SUPPORTED:
            Timber.d("onProductDataResponse: failed, should retry request");
            iapManager.disableAllPurchases();
            break;
    }
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse)

Aggregations

PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)2 PurchasingListener (com.amazon.device.iap.PurchasingListener)1 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)1 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)1 Receipt (com.amazon.device.iap.model.Receipt)1 UserDataResponse (com.amazon.device.iap.model.UserDataResponse)1 Product (com.amazon.purchase.model.Product)1 Receipt (com.amazon.purchase.model.Receipt)1 Response (com.amazon.purchase.model.Response)1 UserData (com.amazon.purchase.model.UserData)1