How to detect that user has canceled the IAP on kindle fire?

試著忘記壹切 提交于 2020-01-03 02:43:05

问题


This question might have been asked before, but I can't find the answer anywhere and I don't know if it is possible for the Amazon IAP SDK. When I canceled a purchase, I will be received as FAILED from purchase response. If so, how can I display the FAILED is caused by cancellation or other extraneous circumstance error?

private class PurchaseAsyncTask extends
        AsyncTask<PurchaseResponse, Void, Boolean> {

    private String [] purchaseResult = null;
    @Override
    protected Boolean doInBackground(final PurchaseResponse... params) {
        final PurchaseResponse purchaseResponse = params[0];
        final String userId = microTrans.getCurrentUser();
        switch (purchaseResponse.getPurchaseRequestStatus()) {
        case SUCCESSFUL:
            /*
             * You can verify the receipt and fulfill the purchase on
             * successful responses.
             */
            final Receipt receipt = purchaseResponse.getReceipt();
            switch (receipt.getItemType()) {
            case CONSUMABLE:
                break;
            case ENTITLED:
                break;
            case SUBSCRIPTION:
                break;
            }

            return true;
        case ALREADY_ENTITLED:
            /*
             * If the customer has already been entitled to the item, a
             * receipt is not returned. Fulfillment is done unconditionally,
             * we determine which item should be fulfilled by matching the
             * request id returned from the initial request with the request
             * id stored in the response.
             */
            // TODO handle already entitled
            Log.v(TAG, "already entitled!");
            return true;
        case FAILED:
            /*
             * If the purchase failed for some reason, (The customer
             * canceled the order, or some other extraneous circumstance
             * happens) the application ignores the request and logs the
             * failure.
             */
            // TODO handle failed of purchase
            Log.v(TAG,
                    "Failed purchase for request"
                            + purchaseResponse.getRequestId());
            return false;
        case INVALID_SKU:
            /*
             * If the sku that was purchased was invalid, the application
             * ignores the request and logs the failure. This can happen
             * when there is a sku mismatch between what is sent from the
             * application and what currently exists on the dev portal.
             */
            // TODO handle invalid sku
            Log.v(TAG,
                    "Invalid Sku for request "
                            + purchaseResponse.getRequestId());
            return false;
        }
        return false;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        super.onPostExecute(success);
    }
}

回答1:


There is no way to distinguish between cancellation and other type of failures.

However, per Amazon IAP UX guidelines:

Your app should not attempt to message any transaction state or status to the customer. In-App Purchasing API will handle all confirmations and messaging to the customer, including transaction success and failure messages.



来源:https://stackoverflow.com/questions/17723130/how-to-detect-that-user-has-canceled-the-iap-on-kindle-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!