Return success when call SwiftyStoreKit.purchaseProduct to resubscribe on a subscription they already purchased

#707 · closed · 2 comments

View on GitHub ↗

sapphirezzz

## Bug Report When call SwiftyStoreKit.purchaseProduct to resubscribe on a subscription they already purchased, it return success result. **To Reproduce** Steps to reproduce the behavior: 1. Call SwiftyStoreKit.purchaseProduct to resubscribe on a subscription they already purchased 2. It shows up a dialog "You're currently subscribed to this." with two action "Manage" and "OK" 3. If tap "Manage", it shows manage dialog and return result error paymentCancelled. if tap "OK", return success result. But the result.transaction.transactionIdentifier is not exits on verify receipt result that apple return. 4. If call SwiftyStoreKit.purchaseProduct again, it does not show the dialog again and directly return success result. But also the result.transaction.transactionIdentifier is not exits on verify receipt result that apple return. **Expected behavior** I hope it can return hasAlreadySubscribed error or something like that when tap "ok" or when call purchaseProduct again . For now, I can not tell user what happen . There are many other situations that transactionIdentifier is not exits . ## Platform Information - OS: iOS 17.4.1 - Purchase Type: auto-renewable subscription - Environment: sandbox - SwiftyStoreKit version: 0.16.1 ## Additional context Add any other context about the problem here. **Potentially Related Issues** - Issue #396 - Issue #183 - Issue #178 - Issue #40 **Screenshots** If applicable, add screenshots to help explain your problem.

Comments

sapphirezzz

I saw issue 183 mentioned: > In your case, I would propose the following: > > Only let the user purchase a subscription if has never been purchased or if it was previously expired. > You can check the status of a subscription with the [verifySubscription](https://github.com/bizz84/SwiftyStoreKit#verify-subscription) method. > > If you want to ensure this works when the user has reinstalled the app, you could refresh the receipt and call verifySubscription in application(_:didFinishLaunchingWithOptions:) (note: refreshing the receipt may prompt to sign in with Apple ID if the user is not signed in). > > The "you have already purchased ..." alert is an internal step performed by StoreKit when purchasing a product and there is no way to intercept it directly (AFAIK). Note that the user is not charged again when this alert appears. But the method "verifyReceipt" should use sharedSecret. It may be dangerous to hardcode it or get it from server.

sapphirezzz

I found it is cause by wrong test method. If I log out of AppStore, and tap purchase on app, then input apple account and password, after all, the transactionIdentifier is exists. If I log sandbox account on phone to test, the transactionIdentifier is not exists. But It seems that, we can only know this resubscribe after user pay again.