Sfoglia il codice sorgente

Make all new payment classes internal rather than public as they are not designed to be used outside SwiftyStoreKit

Andrea Bizzotto 8 anni fa
parent
commit
294293a2b0

+ 7 - 9
SwiftyStoreKit/CompleteTransactionsController.swift

@@ -25,11 +25,11 @@
 import Foundation
 import StoreKit
 
-public struct CompleteTransactions {
-    public let atomically: Bool
-    public let callback: ([Product]) -> ()
+struct CompleteTransactions {
+    let atomically: Bool
+    let callback: ([Product]) -> ()
     
-    public init(atomically: Bool, callback: @escaping ([Product]) -> ()) {
+    init(atomically: Bool, callback: @escaping ([Product]) -> ()) {
         self.atomically = atomically
         self.callback = callback
     }
@@ -49,13 +49,11 @@ extension SKPaymentTransactionState {
 }
 
 
-public class CompleteTransactionsController: TransactionController {
+class CompleteTransactionsController: TransactionController {
 
-    public var completeTransactions: CompleteTransactions?
+    var completeTransactions: CompleteTransactions?
     
-    public init() {}
-
-    public func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
+    func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
         
         guard let completeTransactions = completeTransactions else {
             return transactions

+ 12 - 13
SwiftyStoreKit/PaymentQueueController.swift

@@ -25,8 +25,7 @@
 import Foundation
 import StoreKit
 
-
-public protocol TransactionController {
+protocol TransactionController {
     
     /**
      * - param transactions: transactions to process
@@ -56,7 +55,7 @@ public protocol PaymentQueue: class {
 
 extension SKPaymentQueue: PaymentQueue { }
 
-public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
+class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
     
     private let paymentsController: PaymentsController
     
@@ -70,7 +69,7 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         paymentQueue.remove(self)
     }
 
-    public init(paymentQueue: PaymentQueue = SKPaymentQueue.default(),
+    init(paymentQueue: PaymentQueue = SKPaymentQueue.default(),
                 paymentsController: PaymentsController = PaymentsController(),
                 restorePurchasesController: RestorePurchasesController = RestorePurchasesController(),
                 completeTransactionsController: CompleteTransactionsController = CompleteTransactionsController()) {
@@ -83,7 +82,7 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         paymentQueue.add(self)
     }
     
-    public func startPayment(_ payment: Payment) {
+    func startPayment(_ payment: Payment) {
         
         let skPayment = SKMutablePayment(product: payment.product)
         skPayment.applicationUsername = payment.applicationUsername
@@ -92,7 +91,7 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         paymentsController.append(payment)
     }
     
-    public func restorePurchases(_ restorePurchases: RestorePurchases) {
+    func restorePurchases(_ restorePurchases: RestorePurchases) {
         
         if restorePurchasesController.restorePurchases != nil {
             // return .inProgress
@@ -104,12 +103,12 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         restorePurchasesController.restorePurchases = restorePurchases
     }
     
-    public func completeTransactions(_ completeTransactions: CompleteTransactions) {
+    func completeTransactions(_ completeTransactions: CompleteTransactions) {
         
         completeTransactionsController.completeTransactions = completeTransactions
     }
     
-    public func finishTransaction(_ transaction: PaymentTransaction) {
+    func finishTransaction(_ transaction: PaymentTransaction) {
         guard let skTransaction = transaction as? SKPaymentTransaction else {
             print("Object is not a SKPaymentTransaction: \(transaction)")
             return
@@ -119,7 +118,7 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
 
     
     // MARK: SKPaymentTransactionObserver
-    public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
+    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
         
         /*
          * Some notes about how requests are processed by SKPaymentQueue:
@@ -153,21 +152,21 @@ public class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         }
     }
     
-    public func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
+    func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
         
     }
     
-    public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
+    func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
         
         restorePurchasesController.restoreCompletedTransactionsFailed(withError: error)
     }
     
-    public func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
+    func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
 
         restorePurchasesController.restoreCompletedTransactionsFinished()
     }
     
-    public func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
+    func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
         
     }
 

+ 12 - 14
SwiftyStoreKit/PaymentsController.swift

@@ -26,26 +26,24 @@
 import Foundation
 import StoreKit
 
-public struct Payment: Hashable {
-    public let product: SKProduct
-    public let atomically: Bool
-    public let applicationUsername: String
-    public let callback: (TransactionResult) -> ()
+struct Payment: Hashable {
+    let product: SKProduct
+    let atomically: Bool
+    let applicationUsername: String
+    let callback: (TransactionResult) -> ()
     
-    public var hashValue: Int {
+    var hashValue: Int {
         return product.productIdentifier.hashValue
     }
-    public static func ==(lhs: Payment, rhs: Payment) -> Bool {
+    static func ==(lhs: Payment, rhs: Payment) -> Bool {
         return lhs.product.productIdentifier == rhs.product.productIdentifier
     }
 }
 
-public class PaymentsController: TransactionController {
+class PaymentsController: TransactionController {
     
     private var payments: [Payment] = []
     
-    public init() { }
-    
     private func findPaymentIndex(withProductIdentifier identifier: String) -> Int? {
         for payment in payments {
             if payment.product.productIdentifier == identifier {
@@ -55,15 +53,15 @@ public class PaymentsController: TransactionController {
         return nil
     }
     
-    public func hasPayment(_ payment: Payment) -> Bool {
+    func hasPayment(_ payment: Payment) -> Bool {
         return findPaymentIndex(withProductIdentifier: payment.product.productIdentifier) != nil
     }
     
-    public func append(_ payment: Payment) {
+    func append(_ payment: Payment) {
         payments.append(payment)
     }
     
-    public func processTransaction(_ transaction: SKPaymentTransaction, on paymentQueue: PaymentQueue) -> Bool {
+    func processTransaction(_ transaction: SKPaymentTransaction, on paymentQueue: PaymentQueue) -> Bool {
         
         let transactionProductIdentifier = transaction.payment.productIdentifier
         
@@ -104,7 +102,7 @@ public class PaymentsController: TransactionController {
         return false
     }
     
-    public func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
+    func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
         
         return transactions.filter { !processTransaction($0, on: paymentQueue) }
     }

+ 10 - 13
SwiftyStoreKit/RestorePurchasesController.swift

@@ -25,28 +25,25 @@
 import Foundation
 import StoreKit
 
-public struct RestorePurchases {
-    public let atomically: Bool
-    public let applicationUsername: String?
-    public let callback: ([TransactionResult]) -> ()
+struct RestorePurchases {
+    let atomically: Bool
+    let applicationUsername: String?
+    let callback: ([TransactionResult]) -> ()
     
-    public init(atomically: Bool, applicationUsername: String? = nil, callback: @escaping ([TransactionResult]) -> ()) {
+    init(atomically: Bool, applicationUsername: String? = nil, callback: @escaping ([TransactionResult]) -> ()) {
         self.atomically = atomically
         self.applicationUsername = applicationUsername
         self.callback = callback
     }
 }
 
-
-public class RestorePurchasesController: TransactionController {
+class RestorePurchasesController: TransactionController {
     
     public var restorePurchases: RestorePurchases?
     
     private var restoredProducts: [TransactionResult] = []
     
-    public init() { }
-    
-    public func processTransaction(_ transaction: SKPaymentTransaction, atomically: Bool, on paymentQueue: PaymentQueue) -> Product? {
+    func processTransaction(_ transaction: SKPaymentTransaction, atomically: Bool, on paymentQueue: PaymentQueue) -> Product? {
         
         let transactionState = transaction.transactionState
         
@@ -63,7 +60,7 @@ public class RestorePurchasesController: TransactionController {
         return nil
     }
     
-    public func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
+    func processTransactions(_ transactions: [SKPaymentTransaction], on paymentQueue: PaymentQueue) -> [SKPaymentTransaction] {
         
         guard let restorePurchases = restorePurchases else {
             return transactions
@@ -82,7 +79,7 @@ public class RestorePurchasesController: TransactionController {
         return unhandledTransactions
     }
     
-    public func restoreCompletedTransactionsFailed(withError error: Error) {
+    func restoreCompletedTransactionsFailed(withError error: Error) {
         
         guard let restorePurchases = restorePurchases else {
             return
@@ -96,7 +93,7 @@ public class RestorePurchasesController: TransactionController {
 
     }
     
-    public func restoreCompletedTransactionsFinished() {
+    func restoreCompletedTransactionsFinished() {
         
         guard let restorePurchases = restorePurchases else {
             return

+ 1 - 1
SwiftyStoreKitTests/CompleteTransactionsControllerTests.swift

@@ -23,8 +23,8 @@
 // THE SOFTWARE.
 
 import XCTest
-import SwiftyStoreKit
 import StoreKit
+@testable import SwiftyStoreKit
 
 class CompleteTransactionsControllerTests: XCTestCase {
 

+ 2 - 2
SwiftyStoreKitTests/PaymentQueueControllerTests.swift

@@ -23,11 +23,11 @@
 // THE SOFTWARE.
 
 import XCTest
-import SwiftyStoreKit
 import StoreKit
+@testable import SwiftyStoreKit
 
 extension Payment {
-    public init(product: SKProduct, atomically: Bool, applicationUsername: String, callback: @escaping (TransactionResult) -> ()) {
+    init(product: SKProduct, atomically: Bool, applicationUsername: String, callback: @escaping (TransactionResult) -> ()) {
         self.product = product
         self.atomically = atomically
         self.applicationUsername = applicationUsername

+ 1 - 1
SwiftyStoreKitTests/PaymentsControllerTests.swift

@@ -23,8 +23,8 @@
 // THE SOFTWARE.
 
 import XCTest
-import SwiftyStoreKit
 import StoreKit
+@testable import SwiftyStoreKit
 
 class PaymentsControllerTests: XCTestCase {
 

+ 1 - 1
SwiftyStoreKitTests/RestorePurchasesControllerTests.swift

@@ -24,8 +24,8 @@
 
 
 import XCTest
-import SwiftyStoreKit
 import StoreKit
+@testable import SwiftyStoreKit
 
 class RestorePurchasesControllerTests: XCTestCase {