-
-
Save natefanaro/ab835a5c1fc88887f82378e61f2bc66b to your computer and use it in GitHub Desktop.
Enables creation of SKProduct and SKPaymentTransaction so StoreKit work flow and model can be the same on a simulator as it is on a device.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import StoreKit | |
public extension SKProduct { | |
convenience init(d : Dictionary<String, AnyObject>) { | |
self.init() | |
self.setValue(d["uid"], forKey: "productIdentifier") | |
self.setValue(d["title"], forKey: "localizedTitle") | |
self.setValue(d["detail"], forKey: "localizedDescription") | |
self.setValue(NSDecimalNumber(string: (d["price"] as! String?)), forKey: "price") | |
self.setValue(NSLocale.currentLocale, forKey: "priceLocale") | |
} | |
public override var description: String { | |
return "productIdentifier \(productIdentifier), localizedTitle \(localizedTitle), localizedDescription \(localizedDescription), price \(price), priceLocale \(priceLocale.identifier)" | |
} | |
} | |
public extension SKPaymentTransaction { | |
convenience init(uid : String, state : Int) { | |
self.init() | |
self.setValue(uid, forKey: "transactionIdentifier") | |
self.setValue(NSNumber.init(value: Int32(state)), forKey: "transactionState") | |
self.setValue(NSDate(), forKey: "transactionDate") | |
} | |
public override var description: String { | |
return "transactionIdentifier \(String(describing: transactionIdentifier)), transactionState \(transactionState.rawValue), transactionDate \(transactionDate)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment