|
@@ -45,12 +45,15 @@ public class SwiftyStoreKit {
|
|
private var receiptRefreshRequest: InAppReceiptRefreshRequest?
|
|
private var receiptRefreshRequest: InAppReceiptRefreshRequest?
|
|
#endif
|
|
#endif
|
|
// MARK: Enums
|
|
// MARK: Enums
|
|
- public enum PurchaseResultType {
|
|
|
|
- case Success(productId: String)
|
|
|
|
- case Error(error: ErrorType)
|
|
|
|
|
|
+ public enum PurchaseErrorType {
|
|
|
|
+ case Failed(error: ErrorType)
|
|
case NoProductIdentifier
|
|
case NoProductIdentifier
|
|
case PaymentNotAllowed
|
|
case PaymentNotAllowed
|
|
}
|
|
}
|
|
|
|
+ public enum PurchaseResultType {
|
|
|
|
+ case Success(productId: String)
|
|
|
|
+ case Error(error: PurchaseErrorType)
|
|
|
|
+ }
|
|
public enum RetrieveResultType {
|
|
public enum RetrieveResultType {
|
|
case Success(product: SKProduct)
|
|
case Success(product: SKProduct)
|
|
case Error(error: ErrorType)
|
|
case Error(error: ErrorType)
|
|
@@ -102,7 +105,7 @@ public class SwiftyStoreKit {
|
|
sharedInstance.purchase(product: product, completion: completion)
|
|
sharedInstance.purchase(product: product, completion: completion)
|
|
}
|
|
}
|
|
else if case .Error(let error) = result {
|
|
else if case .Error(let error) = result {
|
|
- completion(result: .Error(error: error))
|
|
|
|
|
|
+ completion(result: .Error(error: .Failed(error: error)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -164,11 +167,11 @@ public class SwiftyStoreKit {
|
|
// MARK: private methods
|
|
// MARK: private methods
|
|
private func purchase(product product: SKProduct, completion: (result: PurchaseResultType) -> ()) {
|
|
private func purchase(product product: SKProduct, completion: (result: PurchaseResultType) -> ()) {
|
|
guard SwiftyStoreKit.canMakePayments else {
|
|
guard SwiftyStoreKit.canMakePayments else {
|
|
- completion(result: PurchaseResultType.PaymentNotAllowed)
|
|
|
|
|
|
+ completion(result: .Error(error: .PaymentNotAllowed))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
guard let productIdentifier = product._productIdentifier else {
|
|
guard let productIdentifier = product._productIdentifier else {
|
|
- completion(result: PurchaseResultType.NoProductIdentifier)
|
|
|
|
|
|
+ completion(result: .Error(error: .NoProductIdentifier))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -188,7 +191,7 @@ public class SwiftyStoreKit {
|
|
// TODO: Need a way to match with current product?
|
|
// TODO: Need a way to match with current product?
|
|
return .Success(productId: productId)
|
|
return .Success(productId: productId)
|
|
case .Failed(let error):
|
|
case .Failed(let error):
|
|
- return .Error(error: error)
|
|
|
|
|
|
+ return .Error(error: .Failed(error: error))
|
|
case .Restored(_):
|
|
case .Restored(_):
|
|
fatalError("case Restored is not allowed for purchase flow")
|
|
fatalError("case Restored is not allowed for purchase flow")
|
|
case .NothingToRestore:
|
|
case .NothingToRestore:
|