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

How to suscribe to a product->offer->Phase ? #64

Open
Mckill3r opened this issue Nov 10, 2023 · 2 comments
Open

How to suscribe to a product->offer->Phase ? #64

Mckill3r opened this issue Nov 10, 2023 · 2 comments

Comments

@Mckill3r
Copy link

Hi,
i'm looking to make a purchase for a subscription using the function :

billingConnector.subscribe(this, "APP_PRODUCT", 0);

I have a product named "APP_PRODUCT"
and in it i have 3 plans (weekly,montly,yearly)
and in the weekly i have a phase that let the user get a free trial of 1week.

Now using the code above i can make the user suscribe to the APP_PRODUCT -> weekly.

But how about to use the phase with a free trial ?

Regards

@akardas16
Copy link

if trial is available user will subscribe to trial otherwise user will be subscribe normal package

if ((productInfo.subscriptionOfferDetails?.size ?: 0) == 1){
    price = productInfo.getSubscriptionOfferPrice(0,0)
    "$price / Monthly".also { binding.price2.text = it }
    p2 = productInfo.subsJustPrice(0,0) / 4
}else if ((productInfo.subscriptionOfferDetails?.size ?: 0) == 2){
    price = productInfo.getSubscriptionOfferPrice(1,0)
    val s = productInfo.subscriptionOfferDetails?.get(0)?.pricingPhases?.pricingPhaseList?.get(0)?.billingPeriod?.filter { it.isDigit() }
    "$s days free, then $price / Monthly".also { binding.price2.text = it }
    p2 = productInfo.subsJustPrice(1,0) / 4
}

@Mckill3r
Copy link
Author

Mckill3r commented Nov 12, 2023

I'm using a webview for my app so i don't know the information about the ID of the offer.

I have manage to do what i need to check if user is granted FreeTrial or not by saving IDs of the offer on a Map with the name of the offer :

Map<String, Integer> offreMapping = new HashMap<>();

for (ProductInfo productInfo : productDetails) {
                    product = productInfo.getProduct();
                    int num_offers = productInfo.getSubscriptionOfferDetails().size();

                    for (int i = 0; i < num_offers; i++) {
                        String plan_id = productInfo.getSubscriptionOfferDetails().get(i).getBasePlanId();

                        if (!offreMapping.containsKey(plan_id)) {
                            offreMapping.put(plan_id, i);
                        }
                    }

I should make a verification on the OfferPrice but since i only use FreeTrial in my case i dont need to.

This way i can call a javascript function with the offer name that will convert it with the correct ID.

public void make_payment(String offer_name){
        String Offer = mContext.getString(R.string.inapp_offer);
        Integer id = offreMapping.get(offer_name);
        if(id != null) {
            billingConnector.subscribe(this, Offer, id);
        }
    }

Not perfect but working fine if other need it :)

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