Search in sources :

Example 6 with Receipt

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

Receipt (com.amazon.device.iap.model.Receipt)6 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)3 UserData (com.amazon.device.iap.model.UserData)2 PurchaseInfo (net.osmand.plus.inapp.InAppPurchases.PurchaseInfo)2 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)1