Question

Getting the renew date and billing period from a subscription

  • 3 March 2023
  • 1 reply
  • 374 views

Badge +2

Hi!

I'm working on my app that offers a "PRO" version with a monthly subscription, but i want to be ready to offer additional plans, like an annual version for example. To load the options, my view looks like this:

And i used it like this to generate the upgrade buttons. 

Purchases.shared.getOfferings { (offerings, error) in
if let packages = offerings?.current?.availablePackages {
self.packages = packages
for package in self.packages {
let button = UIButton(type: .system)
let price = package.localizedPriceString
button.setTitle(price, for: .normal)
button.addTarget(self, action: #selector(self.ctaTapped(_:)), for: .touchUpInside)
button.tag = package.hash
self.CTAButtons.addArrangedSubview(button)
}
} else {
print("RevenueCat not working")
}
}

At the moment i only have one monthly subscription setup, but later it might have more options, like annual version. My first problem here is that how can i show the / month text on the button?(or /annual in case later i add another option). I don’t seem to find a way to get the billing cycle of the package. 

Next, once the subscription is active, i want to show this view:

The problem here is pretty much the same, i’m not sure how to get the currently active subscription’s name, price and next renewal date. I did this:

Purchases.shared.getCustomerInfo { (customerInfo, error) in
if customerInfo?.entitlements.all["pro"]?.isActive == true {
if let product_id = customerInfo?.entitlements.all["pro"]?.productIdentifier {
Purchases.shared.getProducts([product_id]) { products in
if let product = products.first {
self.subscriptionName.text = product.localizedTitle
self.subscriptionCost.text = product.localizedPriceString
if let expirationDate = customerInfo?.entitlements.all["pro"]?.expirationDate {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
self.subscriptionRenewDate.text = "Renews: " + dateFormatter.string(from: expirationDate)
} else {
self.subscriptionRenewDate.text = ""
}
}
}
}
}
}

The only date i could find that was relevant is expirationDate, but i’m not sure thats the correct value to use in this case. There is “Period Type” in the entitlement, but based on the docs it have Trial, Intro and Normal as the value, not the actual billing period. Can you please point me in the right direction with this?

Thanks!


1 reply

Userlevel 3
Badge +8

Hi Peter,

 

My first problem here is that how can i show the / month text on the button?

We recommend naming packages with an informative pattern, like:

<app>_<price>_<duration>_<intro duration><intro price>

So in your case, perhaps something like apple_199_1m. Then you could build some logic to read the duration/price from your package name.

 

The only date i could find that was relevant is expirationDate, but i’m not sure thats the correct value to use in this case

That would be the correct date to use, in this case. It’s the end of the current billing cycle when a renewal would take place.

 

Please let me know if I can answer anything else!

Reply