SwiftyStoreKit icon indicating copy to clipboard operation
SwiftyStoreKit copied to clipboard

How to buy a subscription again after it expires on Auto-Renewable subscription?

Open pekochun opened this issue 4 years ago • 4 comments

I used the following code to call it from the purchase button of the auto-renewal subscription. I am offering a 3-day free trial period.

    @IBAction func purchaceButtonTap(_ sender: Any) {
        self.purchase(PRODUCT_ID:"xxxx")
    }

    func purchase(PRODUCT_ID:String)
    {
       SwiftyStoreKit.purchaseProduct(PRODUCT_ID, quantity: 1, atomically: true){ result in
           switch result {
           case .success(_):
               self.verifyPurchase(PRODUCT_ID: PRODUCT_ID)
           case .error(_):
                print("error")
           }
        }
    }

    func verifyPurchase(PRODUCT_ID:String){
        let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "xxxx")
        SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
            switch result {
            case .success(let receipt):
                let purchaseResult = SwiftyStoreKit.verifySubscription(ofType: .autoRenewable, productId: PRODUCT_ID, inReceipt: receipt)
                switch purchaseResult {
                case .purchased:
                    print("Purchased")

                case .notPurchased:
                    print("notPurchased")

                case .expired( _, _):
                    print("expired")
                }
            case .error:
                print("Error")
            }
        }
    }

I was able to purchase the first time using the above code, but after the purchase expired, I had to do it again. When I press the Buy Subscription button, the message "expired" appears and I cannot purchase.

What's wrong with my code? How do I re-purchase an expired subscription?

pekochun avatar Jul 04 '20 20:07 pekochun

I'm worried about the same problem. Did you solve this problem by any chance?

jasudev avatar Oct 28 '20 06:10 jasudev

I've been plagued by this problem for a long time, and I've tried many ways to solve it,but it doesn't work.

XHL-Mao avatar Nov 06 '20 16:11 XHL-Mao

I think this problem should also exist when Apple Review.

XHL-Mao avatar Nov 06 '20 16:11 XHL-Mao

Same issue here. Did you fix it?

tulssinep avatar Mar 06 '21 07:03 tulssinep