PaymentQueueSpy.swift 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // PaymentQueueSpy.swift
  3. // SwiftyStoreKit
  4. //
  5. // Created by Andrea Bizzotto on 17/01/2017.
  6. // Copyright © 2017 musevisions. All rights reserved.
  7. //
  8. import SwiftyStoreKit
  9. import StoreKit
  10. class PaymentQueueSpy: PaymentQueue {
  11. weak var observer: SKPaymentTransactionObserver?
  12. var payments: [SKPayment] = []
  13. var restoreCompletedTransactionCalledCount = 0
  14. var finishTransactionCalledCount = 0
  15. func add(_ observer: SKPaymentTransactionObserver) {
  16. self.observer = observer
  17. }
  18. func remove(_ observer: SKPaymentTransactionObserver) {
  19. if self.observer === observer {
  20. self.observer = nil
  21. }
  22. }
  23. func add(_ payment: SKPayment) {
  24. payments.append(payment)
  25. }
  26. func restoreCompletedTransactions(withApplicationUsername username: String?) {
  27. restoreCompletedTransactionCalledCount += 1
  28. }
  29. func finishTransaction(_ transaction: SKPaymentTransaction) {
  30. finishTransactionCalledCount += 1
  31. }
  32. }