bizz84 / bizz84/SwiftyStoreKit

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

Open
#556 4 comments 0 reactions 0 assignees View on GitHub
type: question
Dominant language
Swift
Stars
6.7k
Forks
801
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.