Android应用内订阅:面临测试应用内订阅的问题

时间:2018-09-08 19:07:04

标签: java android publish-subscribe subscription in-app

  1. 我已经在Android应用程序的App subscription中实现了。但是我无法在调试模式下进行测试。我们始终需要生成一个已签名的APK并检查下一个过程-有人可以建议如何处理这种情况。

  2. 在安装签名的APK之后,当我打开应用程序时,它会显示我的订阅产品并播放带有3天试用版和一个活动订阅按钮的对话框。在第二天,当我打开该应用程序时,它再次显示相同的消息,并且试用计数仍显示为3天。

  3. 当我按下订阅按钮时,它已处理为付款选项。经过充分的处理后,它从我的帐户中减少了每月的订阅费用,并显示了付款成功的方法。 -但我仍处于试用模式,那么为什么要减少费用。应该在3天后收费

任何人都可以建议...在下面找到我的代码

/*In-App BillingConfig*/
    private void initBillingConfig() {
        try {
            mBillingClient = BillingClient.newBuilder(context).setListener(new PurchasesUpdatedListener() {
                @Override
                public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
                    try {
                        if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
                            for (Purchase purchase : purchases) {
                                if (purchase.getSku().equalsIgnoreCase(MONTHLY_2USD)) {
                                    showToast("You have subscribed our product(" + MONTHLY_2USD + ") for next 1 month");
                                    appendLog("You have subscribed our product(" + MONTHLY_2USD + ") for next 1 month");
                                }
                            }
                        } else if (responseCode == BillingClient.BillingResponse.ITEM_ALREADY_OWNED) {
                            showToast("onPurchasesUpdated: Item already purchased");
                            appendLog("onPurchasesUpdated: Item already purchased");
                        } else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
                            showToast("You have canceled our subscription mode.");
                            appendLog("You have canceled our subscription mode.");
                        } else if (responseCode == BillingClient.BillingResponse.DEVELOPER_ERROR)   {
                            showToast("BillingClient.BillingResponse.DEVELOPER_ERROR");
                            appendLog("BillingClient.BillingResponse.DEVELOPER_ERROR");
                            overridePendingTransition(0,0);
                            finish();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        showToast("onPurchasesUpdated: " + e.getMessage());
                        appendLog("onPurchasesUpdated: " + e.getMessage());
                    }
                }
            }).build();
            mBillingClient.startConnection(new BillingClientStateListener() {
                @Override
                public void onBillingSetupFinished(@BillingClient.BillingResponse int billingResponseCode) {
                    try {
                        if (billingResponseCode == BillingClient.BillingResponse.OK) {
                            // The billing client is ready. You can query purchases here.
                            checkBillingSKU();
                        } else if (billingResponseCode == BillingClient.BillingResponse.ITEM_ALREADY_OWNED) {
                            appendLog("onBillingSetupFinished: Item already purchased");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        showToast("onBillingSetupFinished: " + e.getMessage());
                        appendLog("onBillingSetupFinished: " + e.getMessage());
                    }
                }

                @Override
                public void onBillingServiceDisconnected() {
                    // Try to restart the connection on the next request to
                    // Google Play by calling the startConnection() method.
                    try {
                        mBillingClient.startConnection(this);
                    } catch (Exception e) {
                        e.printStackTrace();
                        showToast("onBillingServiceDisconnected: " + e.getMessage());
                        appendLog("onBillingServiceDisconnected: " + e.getMessage());
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            showToast("initBillingConfig: " + e.getMessage());
            appendLog("initBillingConfig: " + e.getMessage());
        }
    }

    private void showToast(String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void checkBillingSKU() {
        try {
            List skuList = new ArrayList<>();
            skuList.add(MONTHLY_2USD);
            SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
            params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
            mBillingClient.querySkuDetailsAsync(params.build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            // Process the result.
                            try {
                                if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
                                    for (SkuDetails skuDetails : skuDetailsList) {
                                        String sku = skuDetails.getSku();
                                        String price = skuDetails.getPrice();
                                        showToast(skuDetails.toString());
                                        if (MONTHLY_2USD.equals(sku)) {
                                            //mPremiumUpgradePrice = price;
                                            purchaseProduct();
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                showToast("onSkuDetailsResponse: " + e.getMessage());
                                appendLog("onSkuDetailsResponse: " + e.getMessage());
                            }
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
            showToast("checkBillingSKU: " + e.getMessage());
            appendLog("checkBillingSKU: " + e.getMessage());
        }
    }

    private void purchaseProduct() {
        try {
            BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                    .setSku(MONTHLY_2USD)
                    .setType(BillingClient.SkuType.SUBS) // SkuType.SUB for subscription
                    .build();
            int responseCode = mBillingClient.launchBillingFlow(DashBoard.this, flowParams);
            showToast("BillingFlowParams: " + responseCode);
            appendLog("BillingFlowParams: " + responseCode);
        } catch (Exception e) {
            e.printStackTrace();
            showToast("purchaseProduct: " + e.getMessage());
            appendLog("purchaseProduct: " + e.getMessage());
        }
    }

0 个答案:

没有答案