ios – How exit inBillingRetryPeriod state in Storekit2


I’m currently testing subscriptions in sandbox. In Appstore connect, I set a grace period of 3 days.
I subscribed for a service which expired and now it’s inBillingRetryPeriod state. I thought it had to do with my payment method. After updating my payment method, it still remains in that state. Checking Status.RenewalInfo’s gracePeriodExpiration and expirationReason values produces nil. How do I exit the inBillingRetry state. I’m new to in-app purchases. Thanks. Here’s the relevant code:

    ...
    @MainActor
    func updateSubscriptionStatus() async {
        do {
            
            guard let product = storeManager.renewables.first,
                  let statuses = try await product.subscription?.status else {return}
            
            var highestProduct: Product? = nil
            var highestStatus: Product.SubscriptionInfo.Status? = nil
            
            for status in statuses {
                switch status.state {
                case .expired, .revoked:
                    continue
                default:
                    let verifiedRenewalInfo = try storeManager.checkVerified(status.renewalInfo)
                    
                    //Find the first subscription in the store that matches id on the `status.renewalInfo`
                    guard let newSubscription = storeManager.renewables.first(where: {$0.id == verifiedRenewalInfo.autoRenewPreference}) else { continue }
                    
                    guard let currentProduct = highestProduct else {
                        highestProduct = newSubscription
                        highestStatus = status
                        // next status
                        continue
                    }
                    
                    let currentProductTier = storeManager.tierDuration(for: currentProduct.id)
                    let newTier = storeManager.tierDuration(for: newSubscription.id)
                    if newTier > currentProductTier {
                        //updated product and status
                        highestProduct = newSubscription
                        highestStatus = status
                    }
                }
            }
            
             
            currentSubscription = highestProduct // currentSubscription is an @State 
            status = highestStatus // status is an @State 
            print("current status")
            print(highestStatus?.state)
            if let mySubcriptionStatus = status,
               case .verified(let renewalInfo) = highestStatus?.renewalInfo {
                print(mySubcriptionStatus.state) // StoreKit.Product.SubscriptionInfo.RenewalState(rawValue: 3) -- inBillingRetryPeriod
                print(renewalInfo.expirationReason) // nil
                print(renewalInfo.gracePeriodExpirationDate) // nil
            }
        } catch  {
            print(error)
        }
        
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img