Search in sources :

Example 1 with PurchaseResponse

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

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

the class AmazonPurchasingListener method onPurchaseResponse.

/**
 * This is the callback for {@link PurchasingService#purchase}. For each time the application
 * sends a purchase request {@link PurchasingService#purchase}, Amazon Appstore will call this
 * callback when the purchase request is completed. If the RequestStatus is Successful or
 * AlreadyPurchased then application needs to call {@link com.battlelancer.seriesguide.billing.amazon.AmazonIapManager#handleReceipt}
 * to handle the purchase fulfillment. If the RequestStatus is INVALID_SKU, NOT_SUPPORTED, or
 * FAILED, notify corresponding method of {@link com.battlelancer.seriesguide.billing.amazon.AmazonIapManager}
 * .
 */
@Override
public void onPurchaseResponse(final PurchaseResponse response) {
    final String requestId = response.getRequestId().toString();
    final String userId = response.getUserData().getUserId();
    final PurchaseResponse.RequestStatus status = response.getRequestStatus();
    Timber.d("onPurchaseResponse: requestId (%s) userId (%s) purchaseRequestStatus (%s)", requestId, userId, status);
    switch(status) {
        case SUCCESSFUL:
            final Receipt receipt = response.getReceipt();
            Timber.d("onPurchaseResponse: receipt json: %s", receipt.toJSON());
            iapManager.handleReceipt(receipt, response.getUserData());
            iapManager.reloadPurchaseStatus();
            break;
        case ALREADY_PURCHASED:
            Timber.i("onPurchaseResponse: already purchased, verify subscription purchase again");
            iapManager.reloadPurchaseStatus();
            break;
        case INVALID_SKU:
            Timber.d("onPurchaseResponse: invalid SKU! onProductDataResponse should have disabled buy button already.");
            iapManager.purchaseFailed();
            break;
        case FAILED:
        case NOT_SUPPORTED:
            Timber.d("onPurchaseResponse: failed, remove purchase request from local storage");
            iapManager.purchaseFailed();
            break;
    }
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse)

Example 3 with PurchaseResponse

use of com.amazon.device.iap.model.PurchaseResponse in project Osmand by osmandapp.

the class IapPurchasingListener method onPurchaseResponse.

/**
 * This is the callback for {@link PurchasingService#purchase}. For each
 * time the application sends a purchase request
 * {@link PurchasingService#purchase}, Amazon Appstore will call this
 * callback when the purchase request is completed.
 */
@Override
public void onPurchaseResponse(final PurchaseResponse response) {
    final String requestId = response.getRequestId().toString();
    final String userId = response.getUserData().getUserId();
    final PurchaseResponse.RequestStatus status = response.getRequestStatus();
    Log.d(TAG, "onPurchaseResponse: requestId (" + requestId + ") userId (" + userId + ") purchaseRequestStatus (" + status + ")");
    switch(status) {
        case SUCCESSFUL:
            final Receipt receipt = response.getReceipt();
            Log.d(TAG, "onPurchaseResponse: receipt json:" + receipt.toJSON());
            PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.FULFILLED);
            notifyPurchaseResponseListeners(response);
            break;
        case ALREADY_PURCHASED:
            Log.i(TAG, "onPurchaseResponse: already purchased, you should verify the subscription " + "purchase on your side and make sure the purchase was granted to customer");
            notifyPurchaseResponseListeners(null);
            break;
        case INVALID_SKU:
            Log.d(TAG, "onPurchaseResponse: invalid SKU! onProductDataResponse should have disabled buy button already.");
            notifyPurchaseResponseListeners(null);
            break;
        case FAILED:
        case NOT_SUPPORTED:
            Log.d(TAG, "onPurchaseResponse: failed so remove purchase request from local storage");
            notifyPurchaseResponseListeners(null);
            break;
    }
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse)

Example 4 with PurchaseResponse

use of com.amazon.device.iap.model.PurchaseResponse in project OsmAnd by osmandapp.

the class IapPurchasingListener method onPurchaseResponse.

/**
 * This is the callback for {@link PurchasingService#purchase}. For each
 * time the application sends a purchase request
 * {@link PurchasingService#purchase}, Amazon Appstore will call this
 * callback when the purchase request is completed.
 */
@Override
public void onPurchaseResponse(final PurchaseResponse response) {
    final String requestId = response.getRequestId().toString();
    final String userId = response.getUserData().getUserId();
    final PurchaseResponse.RequestStatus status = response.getRequestStatus();
    Log.d(TAG, "onPurchaseResponse: requestId (" + requestId + ") userId (" + userId + ") purchaseRequestStatus (" + status + ")");
    switch(status) {
        case SUCCESSFUL:
            final Receipt receipt = response.getReceipt();
            Log.d(TAG, "onPurchaseResponse: receipt json:" + receipt.toJSON());
            PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.FULFILLED);
            notifyPurchaseResponseListeners(response);
            break;
        case ALREADY_PURCHASED:
            Log.i(TAG, "onPurchaseResponse: already purchased, you should verify the subscription " + "purchase on your side and make sure the purchase was granted to customer");
            notifyPurchaseResponseListeners(null);
            break;
        case INVALID_SKU:
            Log.d(TAG, "onPurchaseResponse: invalid SKU! onProductDataResponse should have disabled buy button already.");
            notifyPurchaseResponseListeners(null);
            break;
        case FAILED:
        case NOT_SUPPORTED:
            Log.d(TAG, "onPurchaseResponse: failed so remove purchase request from local storage");
            notifyPurchaseResponseListeners(null);
            break;
    }
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse)

Aggregations

PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)4 Receipt (com.amazon.device.iap.model.Receipt)3 PurchasingListener (com.amazon.device.iap.PurchasingListener)1 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)1 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)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