SwiftyStoreKit
SwiftyStoreKit copied to clipboard
How to buy a subscription again after it expires on Auto-Renewable subscription?
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?
I'm worried about the same problem. Did you solve this problem by any chance?
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.
I think this problem should also exist when Apple Review.
Same issue here. Did you fix it?