当前位置: 首页>编程语言>正文

【Google 支付】Response Code- FEATURE_NOT_SUPPORTED, Debug Message- Client does not support ProductDe...

背景

最近开发安卓SDK,看到一个与支付相关的上架条例


【Google 支付】Response Code- FEATURE_NOT_SUPPORTED, Debug Message- Client does not support ProductDe...,第1张
b0c0e9a81a29ad5c7b806af51782d8a5.png

Google Play结算服务

向下兼容google商店

不难发现,根据官网的操作直接使用新版本的api,在实际支付的时候,会调不起旧版本google商店的支付面板。

报错信息大致如下:

Response Code: FEATURE_NOT_SUPPORTED, Debug Message: Client does not support ProductDetails.

开发者不能去强制用户升级google商店吧,但是有不想这部分付费用户流失,只能做兼容。

解决方法

startPay

private void startPay(final String orderId, final String orderInfo) {
        List<QueryProductDetailsParams.Product> skuList = new ArrayList<>();
        QueryProductDetailsParams.Product product = QueryProductDetailsParams
                .Product.newBuilder()
                .setProductId(orderInfo)
                .setProductType(BillingClient.ProductType.INAPP)
                .build();
        //添加对应的 产品id 去查询详情
        skuList.add(product);

        QueryProductDetailsParams queryProductDetailsParams = QueryProductDetailsParams
                .newBuilder()
                .setProductList(skuList)
                .build();

        _billingClient.queryProductDetailsAsync(
                queryProductDetailsParams,
                new ProductDetailsResponseListener() {
                    public void onProductDetailsResponse(BillingResult billingResult,
                                                         final List<ProductDetails> productDetailsList) {
                        if(billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK && billingResult.getResponseCode() == BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED) {
                            doPayCompat(orderId, orderInfo);
                            return;
                        }

                        if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
                            onFailed(StateCode.PayStateCode.PAY_FAILED);
                            PayManager.getInstance().showTips(StateCode.PayStateCode.PAY_FAILED, "pay fail code:"+billingResult.getResponseCode()+ " msg:"+billingResult.getDebugMessage());
                            return;
                        }

                        if(productDetailsList.size() <=0){
                            onFailed(StateCode.PayStateCode.PAY_ERROR);
                            PayManager.getInstance().showTips(StateCode.PayStateCode.PAY_ERROR, "No goods found");
                            return;
                        }

                        SdkManager.getInstance().getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                List<BillingFlowParams.ProductDetailsParams> params = new ArrayList<>();
                                //添加购买数据
                                BillingFlowParams.ProductDetailsParams productDetailsParams = BillingFlowParams.ProductDetailsParams
                                        .newBuilder()
                                        .setProductDetails(productDetailsList.get(0)) //取第一个商品查询即可
                                        .build();
                                params.add(productDetailsParams);
                                BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                        .setProductDetailsParamsList(params)
                                        .setObfuscatedAccountId(DataManager.getInstance().getCurrLoginedUser().getId())
                                        .setObfuscatedProfileId(orderId)
                                        .build();
                                BillingResult billingResult = _billingClient.launchBillingFlow(SdkManager.getInstance().getActivity(), billingFlowParams);
                            }
                        });
                    }
                }
        );
    }

doPayCompat

private void doPayCompat(final  String orderId, final String orderInfo) {
        List<String> skuList = new ArrayList<>();
        skuList.add(orderInfo);
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
        _billingClient.querySkuDetailsAsync(params.build(),
                new SkuDetailsResponseListener() {
                    @Override
                    public void onSkuDetailsResponse(BillingResult billingResult,
                                                     final List<SkuDetails> skuDetailsList) {
                        // Process the result.
                        if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
                            onFailed(StateCode.PayStateCode.PAY_FAILED);
                            PayManager.getInstance().showTips(StateCode.PayStateCode.PAY_FAILED, "onSkuDetailsResponse fail code:"+billingResult.getResponseCode());
                            return;
                        }

                        SdkManager.getInstance().getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                // Retrieve a value for "skuDetails" by calling querySkuDetailsAsync().
                                final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                        .setSkuDetails(skuDetailsList.get(0))
                                        .setObfuscatedAccountId(DataManager.getInstance().getCurrLoginedUser().getId())
                                        .setObfuscatedProfileId(orderId)
                                        .build();
                                int responseCode = _billingClient.launchBillingFlow(SdkManager.getInstance().getActivity(), billingFlowParams).getResponseCode();
                            }
                        });
                    }
                }
        );

    }

google商店历史版本(访问不了挂下


https://www.xamrdz.com/lan/5uk2016544.html

相关文章: