Răsfoiți Sursa

renamed discount to paymentDiscount

Jan Remes 6 ani în urmă
părinte
comite
9ccc0a6d4c

+ 2 - 2
SwiftyStoreKit/PaymentQueueController.swift

@@ -125,11 +125,11 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         
         if #available(iOS 12.2, tvOS 12.2, *) {
             
-            if let obj = payment.discount, !(obj is SKPaymentDiscount) {
+            if let obj = payment.paymentDiscount, !(obj is SKPaymentDiscount) {
                 assert(false, "Unrecognized type provided for payment discount. Only SKPaymentDiscount is supported")
             }
             
-            if let discount = payment.discount as? SKPaymentDiscount {
+            if let discount = payment.paymentDiscount as? SKPaymentDiscount {
                 skPayment.paymentDiscount = discount
             }
         }

+ 1 - 1
SwiftyStoreKit/PaymentsController.swift

@@ -29,7 +29,7 @@ struct Payment: Hashable {
     let product: SKProduct
     
     /// SKPaymentDiscount
-    let discount: NSObject?
+    let paymentDiscount: AnyObject?
     let quantity: Int
     let atomically: Bool
     let applicationUsername: String

+ 5 - 19
SwiftyStoreKit/SwiftyStoreKit.swift

@@ -64,8 +64,8 @@ public class SwiftyStoreKit {
         }
     }
 
-    fileprivate func purchase(product: SKProduct, quantity: Int, atomically: Bool, applicationUsername: String = "", simulatesAskToBuyInSandbox: Bool = false, discount: NSObject? = nil, completion: @escaping (PurchaseResult) -> Void) {
-        paymentQueueController.startPayment(Payment(product: product, discount: discount, quantity: quantity, atomically: atomically, applicationUsername: applicationUsername, simulatesAskToBuyInSandbox: simulatesAskToBuyInSandbox) { result in
+    fileprivate func purchase(product: SKProduct, quantity: Int, atomically: Bool, applicationUsername: String = "", simulatesAskToBuyInSandbox: Bool = false, paymentDiscount: AnyObject? = nil, completion: @escaping (PurchaseResult) -> Void) {
+        paymentQueueController.startPayment(Payment(product: product, paymentDiscount: paymentDiscount, quantity: quantity, atomically: atomically, applicationUsername: applicationUsername, simulatesAskToBuyInSandbox: simulatesAskToBuyInSandbox) { result in
             
             completion(self.processPurchaseResult(result))
         })
@@ -167,26 +167,12 @@ extension SwiftyStoreKit {
      *  - Parameter quantity: quantity of the product to be purchased
      *  - Parameter atomically: whether the product is purchased atomically (e.g. finishTransaction is called immediately)
      *  - Parameter applicationUsername: an opaque identifier for the user’s account on your system
+     *  - Parameter product: optional discount to be applied. Must be SKProductPayment type
      *  - Parameter completion: handler for result
      */
-    public class func purchaseProduct(_ product: SKProduct, quantity: Int = 1, atomically: Bool = true, applicationUsername: String = "", simulatesAskToBuyInSandbox: Bool = false, completion: @escaping ( PurchaseResult) -> Void) {
+    public class func purchaseProduct(_ product: SKProduct, quantity: Int = 1, atomically: Bool = true, applicationUsername: String = "", simulatesAskToBuyInSandbox: Bool = false, paymentDiscount: AnyObject? = nil, completion: @escaping ( PurchaseResult) -> Void) {
         
-        sharedInstance.purchase(product: product, quantity: quantity, atomically: atomically, applicationUsername: applicationUsername, simulatesAskToBuyInSandbox: simulatesAskToBuyInSandbox, completion: completion)
-    }
-    
-    /**
-     *  Purchase a product with discount
-     *  - Parameter product: product to be purchased
-     *  - Parameter product: optional discount to be applied
-     *  - Parameter quantity: quantity of the product to be purchased
-     *  - Parameter atomically: whether the product is purchased atomically (e.g. finishTransaction is called immediately)
-     *  - Parameter applicationUsername: an opaque identifier for the user’s account on your system
-     *  - Parameter completion: handler for result
-     */
-    @available(iOS 12.2, tvOS 12.2, *)
-    public class func purchaseProductWithDiscount(_ product: SKProduct, discount: SKPaymentDiscount?, quantity: Int = 1, atomically: Bool = true, applicationUsername: String = "", simulatesAskToBuyInSandbox: Bool = false, completion: @escaping ( PurchaseResult) -> Void) {
-        
-        sharedInstance.purchase(product: product, quantity: quantity, atomically: atomically, applicationUsername: applicationUsername, simulatesAskToBuyInSandbox: simulatesAskToBuyInSandbox, discount: discount, completion: completion)
+        sharedInstance.purchase(product: product, quantity: quantity, atomically: atomically, applicationUsername: applicationUsername, simulatesAskToBuyInSandbox: simulatesAskToBuyInSandbox, paymentDiscount: paymentDiscount, completion: completion)
     }
 
     /**