bizz84 / bizz84/SwiftyStoreKit
purchaseProduct Fail
- Dominant language
- Swift
- Stars
- 6.7k
- Forks
- 801
- PR merge metrics
- No merged PRs in 30d
Description
### Platform
- [X] iOS
- [ ] macOS
- [ ] tvOS
### In app purchase type
- [ ] Consumable
- [ ] Non-consumable
- [X] Auto-Renewable Subscription
- [ ] Non-Renewing Subscription
### Environment
- [ ] Sandbox
- [X] Production
Not working in production but working in sandbox
When purchasing a subscription, it verifies the receipt correctly. Once it asks the user to buy the subscription I am getting a "Purchase Fail" error. Below is my code:
```
func verifySubscription(){
let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "**********")
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
switch result {
case .success(let receipt):
let purchaseResult = SwiftyStoreKit.verifySubscription(
type: .autoRenewable,
productId: "**********",
inReceipt: receipt)
switch purchaseResult {
case .purchased(let expiryDate, let receiptItems):
print("******************** Expiration Date: \(expiryDate) ********************")
print("******************** Receipt: \(receiptItems) ********************")
case .expired(let expiryDate, let receiptItems):
print("******************** Expiration Date: \(expiryDate) ********************")
print("******************** Receipt: \(receiptItems) ********************")
self.purchaseSubscription()
case .notPurchased:
print("******************** User never purchased ********************")
self.purchaseSubscription()
}
case .error(let error):
print("******************** Receipt Verification Error: \(error) ********************")
}
}
}
func purchaseSubscription(){
SwiftyStoreKit.purchaseProduct("**********", atomically: true) { result in
if case .success(let purchase) = result {
if purchase.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
} else {
**I AM GETTING THIS ERROR AND ITS NOT LETTING USER BUY SUBSCRIPTION**
print("******************** Purchase Error ********************")
let alertController = UIAlertController(title: "Error", message: "Cannot purchase content.\nPlease try again later", preferredStyle: .alert)
let yesAction = UIAlertAction(title: "Ok", style: .default) { (action) -> Void in }
alertController.addAction(yesAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.