jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
581 stars 145 forks source link

Getting Trial period of subscription on Android #558

Closed Dizmus closed 8 months ago

Dizmus commented 8 months ago

Bug Information

Version Number of Plugin: 7.0.5 Device Tested On: Google Pixel 7 Pro Simulator Tested On: Version of VS: VS for Mac Version of Xamarin: Xamarin.Android - Version: 13.2.1.2 Versions of other things you are using:

Steps to reproduce the Behavior

Install Plugin.InAppBilling to Android application (Xamarin or MAUI) Try to retrieve FreeTrialPeriod Length

Expected Behavior

InAppBillingProductAndroidExtras contains information about Trial Length

Actual Behavior

subscriptionOfferDetail.BasePlanId and PricingPhase.BillingPeriod contains about the subscription itselft

Code snippet

InAppBillingProductAndroidExtras inAppBillingProductAndroidExtras = inAppBillingProduct.AndroidExtras; var subscriptionOfferDetail = inAppBillingProductAndroidExtras.SubscriptionOfferDetails.SingleOrDefault();

        if (subscriptionOfferDetail == null)
        {
            throw new Exception($"Offer of subscription is not found");
        }

        var freeTrialPeriod = subscriptionOfferDetail.BasePlanId;

        var phase = subscriptionOfferDetail.PricingPhases.Single();

        switch (freeTrialPeriod.ToUpper())
        {
            case "P3D":
                return 3;
            case "P7D":
            case "P1W":
                return 7;
            default:
                throw new Exception($"Cannot parse length of subscription: {freeTrialPeriod}");
        }

Screenshotst

Dizmus commented 8 months ago
image

Subscription Trial Length: 3 days

Dizmus commented 8 months ago

Previously we used the following approach:

image
jamesmontemagno commented 8 months ago

Unfortunatelly Google got rid of it :( you have to parse it yourself: https://stackoverflow.com/questions/72632982/how-to-get-freetrialperiod-of-subscribtion-from-productdetails

Dizmus commented 8 months ago

The problem is that in AndroidExtras there is only one OfferDetails with one Pricing Plan, which is the length of subscription.

Do you mean I need to use native API to retrieve product details?

On Tue, Oct 3, 2023 at 9:13 PM James Montemagno @.***> wrote:

Unfortunatelly Google got rid of it :( you have to parse it yourself: https://stackoverflow.com/questions/72632982/how-to-get-freetrialperiod-of-subscribtion-from-productdetails

— Reply to this email directly, view it on GitHub https://github.com/jamesmontemagno/InAppBillingPlugin/issues/558#issuecomment-1745484192, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMAEK27MISNNXWX4ZAJVODX5RIVRAVCNFSM6AAAAAA5PWKGQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBVGQ4DIMJZGI . You are receiving this because you authored the thread.Message ID: @.***>

-- Best Regards Ilya Grishkevich

Dizmus commented 7 months ago

@jamesmontemagno , thanks, now I got it. Google doesn't send information about trial offer if user is not eligible for it. So, basically, there is no way to get trial length is user has already purchased a subscription