Google Play帐单V5-获取产品的价格

发布于 2025-02-08 22:13:23 字数 89 浏览 4 评论 0原文

在V4中,我曾经有Skudetailss.price来获取产品的价格,但现在在V5的新产品Details中不再可用。

如何在此新版本中获得产品的价格?

In v4, I used to have SkuDetails.price to get the price of the product but now it's not available anymore in the new ProductDetails in v5.

How can I get the price of a product in this new version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仲春光 2025-02-15 22:13:23

当您调用getsubscriptionofferdetails时,它将返回可为订阅产品购买的优惠。然后,您可以调用getPricingphases()获取定价阶段的列表。每个定价阶段对象都有一个getformattedPrice()调用以获取要约价格的价格( https://developer.android.com/reference/com/android/android/billingclient/api/productdetails.pricingphases.pricingphases.pricingphase

When you call getSubscriptionOfferDetails, it returns the offers available to buy for the subscription product. Then you can call getPricingPhases() to get the list of the pricing phases. Each pricing phase object has a getFormattedPrice() call to get the price of an offer's pricing phrase (https://developer.android.com/reference/com/android/billingclient/api/ProductDetails.PricingPhase)

青萝楚歌 2025-02-15 22:13:23

您必须检查可用产品

fun getAvailableProducts() {
    Timber.d("!!! Getting available products to buy ...")

    val queryProductDetailsParams =
        QueryProductDetailsParams.newBuilder()
            .setProductList(
                listOf(
                    QueryProductDetailsParams.Product.newBuilder()
                        .setProductId(SKU_SUBSCRIBE_MONTHLY)
                        .setProductType(BillingClient.ProductType.SUBS)
                        .build(),
                    QueryProductDetailsParams.Product.newBuilder()
                        .setProductId(SKU_SUBSCRIBE_YEARLY)
                        .setProductType(BillingClient.ProductType.SUBS)
                        .build()
                ))
            .build()

    billingClient.queryProductDetailsAsync(queryProductDetailsParams) {
            billingResult,
            productDetailsList ->
        if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
            availableProducts.tryEmit(productDetailsList)
            getPrices(productDetailsList)
        } else {
            Timber.d("!!!Error getting available Products to buy: ${billingResult.responseCode} ${billingResult.debugMessage}")
        }
    }
}

,然后

    private fun getPrices(productDetailsList: MutableList<ProductDetails>) {
        productDetailsList.forEach{
            when (it.productId) {
                SKU_SUBSCRIBE_MONTHLY -> {
                    currency.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.priceCurrencyCode.toString())
                    monthlyPrice.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.formattedPrice.toString())
                    Timber.d("!!!! $it.")
                }
                SKU_SUBSCRIBE_YEARLY -> {
//                    currency.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.priceCurrencyCode.toString())
                    yearlyPrice.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.formattedPrice.toString())
                    Timber.d("!!!! $it.")
                }
            }
        }
    }

You have to check for Available Products

fun getAvailableProducts() {
    Timber.d("!!! Getting available products to buy ...")

    val queryProductDetailsParams =
        QueryProductDetailsParams.newBuilder()
            .setProductList(
                listOf(
                    QueryProductDetailsParams.Product.newBuilder()
                        .setProductId(SKU_SUBSCRIBE_MONTHLY)
                        .setProductType(BillingClient.ProductType.SUBS)
                        .build(),
                    QueryProductDetailsParams.Product.newBuilder()
                        .setProductId(SKU_SUBSCRIBE_YEARLY)
                        .setProductType(BillingClient.ProductType.SUBS)
                        .build()
                ))
            .build()

    billingClient.queryProductDetailsAsync(queryProductDetailsParams) {
            billingResult,
            productDetailsList ->
        if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
            availableProducts.tryEmit(productDetailsList)
            getPrices(productDetailsList)
        } else {
            Timber.d("!!!Error getting available Products to buy: ${billingResult.responseCode} ${billingResult.debugMessage}")
        }
    }
}

And then

    private fun getPrices(productDetailsList: MutableList<ProductDetails>) {
        productDetailsList.forEach{
            when (it.productId) {
                SKU_SUBSCRIBE_MONTHLY -> {
                    currency.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.priceCurrencyCode.toString())
                    monthlyPrice.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.formattedPrice.toString())
                    Timber.d("!!!! $it.")
                }
                SKU_SUBSCRIBE_YEARLY -> {
//                    currency.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.priceCurrencyCode.toString())
                    yearlyPrice.tryEmit(it.subscriptionOfferDetails?.get(0)?.pricingPhases!!.pricingPhaseList[0]?.formattedPrice.toString())
                    Timber.d("!!!! $it.")
                }
            }
        }
    }
淡笑忘祈一世凡恋 2025-02-15 22:13:23

我使用以下代码获取价格详细信息。

私有void queryproduct(){

    QueryProductDetailsParams queryProductDetailsParams
            = QueryProductDetailsParams.newBuilder().setProductList(
                    ImmutableList.of(QueryProductDetailsParams.Product.newBuilder()
                            .setProductId("your_product_id")
                            .setProductType(BillingClient.ProductType.INAPP).build()))
            .build();

    billingClient.queryProductDetailsAsync(
            queryProductDetailsParams,

            new ProductDetailsResponseListener() {
                @Override
                public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List<ProductDetails> list) {
                    if(!list.isEmpty()){

                        productDetails = list.get(0);
                        itemdesc.setText(productDetails.getName());
                        itemprice.setText(productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());

                        itemprice.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                makePurchase();
                            }
                        });

                    }else {

                        Log.i("playsresponse", "no response from google play");
                    }
                }
            }
    );

i use the following code to get price details.

private void queryProduct() {

    QueryProductDetailsParams queryProductDetailsParams
            = QueryProductDetailsParams.newBuilder().setProductList(
                    ImmutableList.of(QueryProductDetailsParams.Product.newBuilder()
                            .setProductId("your_product_id")
                            .setProductType(BillingClient.ProductType.INAPP).build()))
            .build();

    billingClient.queryProductDetailsAsync(
            queryProductDetailsParams,

            new ProductDetailsResponseListener() {
                @Override
                public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List<ProductDetails> list) {
                    if(!list.isEmpty()){

                        productDetails = list.get(0);
                        itemdesc.setText(productDetails.getName());
                        itemprice.setText(productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());

                        itemprice.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                makePurchase();
                            }
                        });

                    }else {

                        Log.i("playsresponse", "no response from google play");
                    }
                }
            }
    );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文