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

Introductory Offer Support? #85

Closed
Jerland2 opened this issue May 5, 2021 · 19 comments
Closed

Introductory Offer Support? #85

Jerland2 opened this issue May 5, 2021 · 19 comments

Comments

@Jerland2
Copy link

Jerland2 commented May 5, 2021

Wondering if we can get introductory offer support by implementing the ability to check eligibility?

Each product returns whether it has an introductory offer tied to it. However in order to check eligibility we must parse the receipt. (Hence the feature request)

This would entail parsing the receipt for is_trial_period as well as is_in_intro_offer_period. If these values are equal to 1 somewhere, a user has already used free trial/introductory offer.

Helpful articles outlining this:
https://www.revenuecat.com/blog/ios-introductory-prices
https://developer.apple.com/documentation/storekit/in-app_purchase/subscriptions_and_offers/implementing_introductory_offers_in_your_app
https://blog.apphud.com/introductory-offers-in-ios/

Helpful article snippet:

"As of iOS 12.0, SKProduct now includes subscriptionGroupIdentifier property, so it's now possible to compute Introductory Pricing eligibility locally.
While this update is great, calculating intro eligibility locally still requires a lot of unnecessary dev work.
To check intro eligibility on iOS >= 12.0, you need to:

  • Refresh the receipt so you have updated information about the user's purchases
  • Parse the receipt and look for purchases made with introductory pricing
  • Transform the identifiers for purchases made with intro pricing into SKProducts
  • Transform the productIdentifiers you want to check eligibility for into SKProducts
  • Check if there's a match - if there's at least one purchase made using intro pricing for the same product identifier or the same subscription group, the user is not eligible. If none are found, they're eligible."
    https://www.revenuecat.com/blog/ios-introductory-prices
@Jerland2
Copy link
Author

Jerland2 commented May 5, 2021

Upon closer investigation into the TPA codebase a variable similar to promotionalOfferIdentifier from receipt.purchases.first except for introductory would suffice. as described in the article snippet. As if we can get an identifier tied to a product signifying if the user ever used an intro price then we can compare against list of products. If a match is found we have determined the user in ineligible.

@tikhop
Copy link
Owner

tikhop commented May 13, 2021

Hi @Jerland2, sorry for the late response, I've been off the grid for the last couple weeks and going to be online next week.

I think we can do it, but I need some time.

Thanks,
Pavel

@tikhop
Copy link
Owner

tikhop commented May 17, 2021

Hi @Jerland2, I'm back and about to start working on it. I think, I will have something to try later today.

@tikhop
Copy link
Owner

tikhop commented May 17, 2021

@Jerland2

I've pushed two new methods to check whether user is eligible for introductory offer into feature/introductory-offer-support branch.

Example:

...
let receipt = try InAppReceipt.localReceipt() 
var isEligible = receipt.isEligibleForIntroductoryOffer(for: "com.test.product.id")
// or 
isEligible = receipt.isEligibleForIntroductoryOffer(for: ["com.test.product.1", "com.test.product.2", "com.test.product.3"])
...

I think we can also check whether the user is not eligible for any products within the same subscription group. Let me know if you need it.

@ungerc
Copy link

ungerc commented May 21, 2021

brilliant idea, we need it 🥇

@tikhop
Copy link
Owner

tikhop commented May 21, 2021

We will definitely have it, just need to check whether current implementation works well and if so I will merge it to master and then, I will implement checking whether the user is eligible for any products within the same subscription group.

tikhop pushed a commit that referenced this issue May 24, 2021
@tikhop
Copy link
Owner

tikhop commented May 24, 2021

Hi @Jerland2, @ungerc

I've push code into feature/introductory-offer-support branch with support for checking whether user is eligible for any products within the same subscription group.

Basically, you can retrieve a subscription group from SKProductsResponse using an extension provided by the library and then check whether user is eligible or not:


extension SKManager: SKProductsRequestDelegate 
{
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) 
    {
        let group = response.subscriptionGroup
        // let groups = response.subscriptionGroups // Use this if you have more than one group 
      
        let r = try InAppReceipt()
	let isEligible = r.isEligibleForIntroductoryOffer(for: group)
	
	// Do your stuff
    }
}

I think, I will merge it into master tomorrow.

@ungerc
Copy link

ungerc commented May 24, 2021

cool, I have a day off today, will check tomorrow.

@ungerc
Copy link

ungerc commented May 25, 2021

Hi @tikhop,
nice - looks good

@tikhop
Copy link
Owner

tikhop commented May 25, 2021

@ungerc thanks for checking it out. I'm going to release it later today.

@tikhop
Copy link
Owner

tikhop commented May 25, 2021

Just released it.

Thanks @Jerland2 and @ungerc.

@tikhop tikhop closed this as completed May 25, 2021
@ungerc
Copy link

ungerc commented May 26, 2021

thanks @tikhop,
forgive my ignorance but is there a necessity for you to update sth in the cocoapods repo in order for the version to appear there?

@tikhop
Copy link
Owner

tikhop commented May 26, 2021

@ungerc I'm sorry — updating cocoapods right now.

@tikhop
Copy link
Owner

tikhop commented May 26, 2021

@ungerc

@ungerc
Copy link

ungerc commented May 26, 2021

me again @tikhop 👋🏽,
this function
func isEligibleForIntroductoryOffer(for group: SKSubscriptionGroup) -> Bool
seems to be duplicated? - or am I holding it wrong?
I see it's guarded by #if canImport(StoreKit) and an availability check, but I do not understand it.

@tikhop
Copy link
Owner

tikhop commented May 26, 2021

@ungerc

Well, there are two ways to check eligibility for a subscription group.

First, you need just to pass a set of product identifiers:

func isEligibleForIntroductoryOffer(for group: SubscriptionGroup) -> Bool //`SubscriptionGroup` is Set<String> 

Second, you must prepare SKSubscriptionGroup and pass it to the function.

func isEligibleForIntroductoryOffer(for group: SKSubscriptionGroup) -> Bool //`SKSubscriptionGroup ` class that contains `SKProducts`

@ungerc
Copy link

ungerc commented May 26, 2021

oh here: public typealias SubscriptionGroup = Set<String>
ok, maybe hard to grasp that the typealias has the same name as the class

@ungerc
Copy link

ungerc commented May 26, 2021

oh and it doesn't, now I get it - my head was in a very dark place

@tikhop
Copy link
Owner

tikhop commented May 26, 2021

Yeah, It may seem like overengineering, but I tried to emphasize that the set of product identifiers must belong to the same subscription group.

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

No branches or pull requests

3 participants