Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need example to get Subscriptions price #54

Open
kusyuk opened this issue Jun 22, 2023 · 1 comment
Open

Need example to get Subscriptions price #54

kusyuk opened this issue Jun 22, 2023 · 1 comment

Comments

@kusyuk
Copy link

kusyuk commented Jun 22, 2023

Hi, can anyone help me with how to implement the get the price for subscriptions? I tried looking into the library but there's no method to directly call the price (in respected currency) like the example

price = productInfo.getOneTimePurchaseOfferFormattedPrice();

@mertkaradeniz1
Copy link
Contributor

mertkaradeniz1 commented Jun 28, 2023

Hi, you can use this.

For Subs:

ProductInfo productInfo = purchaseInfo.getProductInfo();
Bundle getProduct = getProductDetails(productInfo);


Bundle getProductDetails(ProductInfo productInfo) {
        Bundle bundle = new Bundle();
        if (productInfo.getType().equals("subs")) {
            if (productInfo.getSubscriptionOfferDetails() != null) {
                for (SubscriptionOfferDetails offerDetails : productInfo.getSubscriptionOfferDetails()) {
                    bundle.putString("basePlanId", offerDetails.getBasePlanId());
                    bundle.putString("offerId", offerDetails.getOfferId());
                    bundle.putString("offerToken", offerDetails.getOfferToken());


                    for (SubscriptionOfferDetails.PricingPhases pricingPhases : offerDetails.getPricingPhases()) {
                        bundle.putString("formattedPrice", pricingPhases.getFormattedPrice());
                        bundle.putLong("priceAmountMicros", pricingPhases.getPriceAmountMicros());
                        bundle.putString("priceCurrencyCode", pricingPhases.getPriceCurrencyCode());
                        bundle.putString("billingPeriod", pricingPhases.getBillingPeriod());
                        bundle.putInt("recurrenceMode", pricingPhases.getRecurrenceMode());
                        bundle.putInt("billingCycleCount", pricingPhases.getBillingCycleCount());

                    }
                }
            }
        }

        return bundle;
    }

For In-App:

for (ProductInfo productInfo : productInfoList) {
            if (productInfo.getType().equals("inapp")) {
                String formattedPrice = productInfo.getOneTimePurchaseOfferFormattedPrice();
                String priceCurrencyCode = productInfo.getOneTimePurchaseOfferPriceCurrencyCode();
                long priceAmountMicros = productInfo.getOneTimePurchaseOfferPriceAmountMicros();
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants