bizz84 / bizz84/SwiftyStoreKit

Questions about the return value and processing order of the VerifyPurchase function

Open
#586 0 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 tried a function like this:

```
func verifyPurchase(productId:String,sharedSecret:String) ->String {
var returnValue = "none"
let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: sharedSecret)
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(productId+"_purchased")
returnValue = "purchased"

case .notPurchased:
print(productId+"_notPurchased")
returnValue = "notPurchased"
}
case .error:
print(productId+"_error")
returnValue = "error"
}
}
return returnValue
}

 print(verifyPurchase(productId:xxxxx,sharedSecret:xxxxx) )
```

However, the function always returns "none" even if the purchase is successful.
What is the order in which the VerifyPurchase function is processed?
How can this function return the correct value?

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.