Gaurav
Gaurav

Reputation: 107

How to get expirey date of autoRenewable subscription

Can anyone tell me how to get expirey date of autorenewable subscription. Actually i have to check if subscription is still valid after subcription date. Please help me in this.

Upvotes: 1

Views: 1694

Answers (2)

chronikum
chronikum

Reputation: 736

I would recommend you this easy, lightweight framework:

https://github.com/bizz84/SwiftyStoreKit

let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "your-shared-secret")
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
    switch result {
    case .success(let receipt):
        let productId = "com.musevisions.SwiftyStoreKit.Subscription"
        // Verify the purchase of a Subscription
        let purchaseResult = SwiftyStoreKit.verifySubscription(
            ofType: .autoRenewable, // or .nonRenewing (see below)
            productId: productId,
            inReceipt: receipt)

        switch purchaseResult {
        case .purchased(let expiryDate, let items):
            print("\(productId) is valid until \(expiryDate)\n\(items)\n")
        case .expired(let expiryDate, let items):
            print("\(productId) is expired since \(expiryDate)\n\(items)\n")
        case .notPurchased:
            print("The user has never purchased \(productId)")
        }

    case .error(let error):
        print("Receipt verification failed: \(error)")
    }
}

as found in the SwiftyStoreKit-Documentation

I hope that helps you. If, it would be great if you could accept my answer :)

Upvotes: 2

Rajendra prajapati
Rajendra prajapati

Reputation: 16

Firstly you need to validate your base 64 receipt in apple server. If apple server respond with status key with value 0 then you will find latest_receipt_info key. This key consist all the information regarding auto renewal subscription. You can get expiry date information in expires_date key.

Upvotes: 0

Related Questions