Search in sources :

Example 1 with Receipt

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

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

Example 3 with Receipt

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

the class InAppPurchaseHelperImpl method onPurchaseFinished.

// Call when a purchase is finished
private void onPurchaseFinished(@NonNull String sku, @NonNull PurchaseResponse response) {
    Receipt receipt = response.getReceipt();
    logDebug("Purchase finished: " + receipt.getSku());
    PurchaseInfo info = getPurchaseInfo(sku, receipt);
    UserData userData = response.getUserData();
    if (userData != null) {
        info.setPurchaseToken(userData.getUserId());
    } else {
        info.setPurchaseToken(getUserId());
    }
    onPurchaseDone(info);
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseInfo(net.osmand.plus.inapp.InAppPurchases.PurchaseInfo) UserData(com.amazon.device.iap.model.UserData)

Example 4 with Receipt

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

the class InAppPurchaseHelperImpl method onPurchaseFinished.

// Call when a purchase is finished
private void onPurchaseFinished(@NonNull String sku, @NonNull PurchaseResponse response) {
    Receipt receipt = response.getReceipt();
    logDebug("Purchase finished: " + receipt.getSku());
    PurchaseInfo info = getPurchaseInfo(sku, receipt);
    UserData userData = response.getUserData();
    if (userData != null) {
        info.setPurchaseToken(userData.getUserId());
    } else {
        info.setPurchaseToken(getUserId());
    }
    onPurchaseDone(info);
}
Also used : Receipt(com.amazon.device.iap.model.Receipt) PurchaseInfo(net.osmand.plus.inapp.InAppPurchases.PurchaseInfo) UserData(com.amazon.device.iap.model.UserData)

Example 5 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