bizz84 / SwiftyStoreKit

Lightweight In App Purchases Swift framework for iOS 8.0+, tvOS 9.0+ and macOS 10.10+ ⛺
MIT License
6.53k stars 793 forks source link

verifyPurchase always returns "not Purchased" #594

Open ghost opened 3 years ago

ghost commented 3 years ago

Bug Report

I'm using code like the following in viewDidLoad at startup, but from a week or two week ago it always returns "notPurchased".

    func verifyPurchase(productId:String) {
        let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: xxxxxx)
        SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
            switch result {
            case .success(let receipt):
                let purchaseResult = SwiftyStoreKit.verifyPurchase(productId: productId, inReceipt: receipt)
                switch purchaseResult {
                case .purchased:
                    print("purchased")
                case .notPurchased:
                    print("notPurchased")
            case .error:
                print("error")
            }
        }
    }

To Reproduce Whenever I call verifyPurchase(productId: "zzzzzz") in ViewDidLoad, "not Purchased" is printed. This seems to happen for all consumable, non-consumable, auto-renewable subscription, and non-renewing subscriptions.

Expected behavior In my case, verifyPurchase with viewDidLoad always prints "notPurchased", but the purchase is successful.

When I press the buy button, it asks "You've already purchased this.Would you like to get it again for free". unnamed

Platform Information

Additional context

Even if I use the code that worked normally until a few weeks ago or the app on TestFlight as it is, verifyPurchase also fails. I suspect that this issue is caused by the influence of the iOS version and so on.

If anyone has a similar problem and finds a solution, please let me know.

louiskabo commented 3 years ago

Just to clarify, you state that this behavior happens for all types of IAP’s. Have you tested with all types of IAP’s? I would think consumables for example would not result in the “already purchased” message...

Also, from the readme, there are different ways to verify a purchase depending on if it’s a subscription vs a consumable product.

Sam-Spencer commented 3 years ago

Do you have any additional details on this?

nenhall commented 3 years ago

I also encountered the same problem, and the product type is: nonConsumable; it can be verified during normal purchase, and every time the purchase is verified through restorePurchases, it will return notPurchased; The same operation, verify that there is no problem with autoRenewable;

The following code is not a complete code, it is my approximate operation at the time

SwiftyStoreKit.restorePurchases(atomically: true, applicationUsername: "") { results in
            let successPurchases = results.restoredPurchases
            successPurchases.forEach { purchase in
                SwiftyStoreKit.verifyReceipt(using: AppleReceipt, forceRefresh: forceRefresh) { verifyReceiptResult in
                  switch verifyReceiptResult {
                case .success(let receiptInfo):
                    switch product.type {
                    case .nonConsumable:
                        let verifyPurchase = StoreKit2.verifyPurchase(productId: product.rawValue, inReceipt: receiptInfo)
                        switch verifyPurchase {
                        case .purchased(let item):
                            appendLog("验证购买✅","purchased:", product.rawValue)

                        case .notPurchased:
                            appendLog("验证购买⚠️","notPurchased:", product.rawValue)
                        }
                    }
                }
            }
       }
 }

macOS 11.2 sandbox