Browse Source

Merge pull request #465 from zhudengdengdeng/master

Resolved repurchasing a non-consumable not calling completion, on macOS
Samuel Spencer 5 years ago
parent
commit
8559919e08
1 changed files with 15 additions and 3 deletions
  1. 15 3
      SwiftyStoreKit/PaymentsController.swift

+ 15 - 3
SwiftyStoreKit/PaymentsController.swift

@@ -103,6 +103,21 @@ class PaymentsController: TransactionController {
             payments.remove(at: paymentIndex)
             return true
         }
+
+        if transactionState == .restored {
+            print("Unexpected restored transaction for payment \(transactionProductIdentifier)")
+
+            let purchase = PurchaseDetails(productId: transactionProductIdentifier, quantity: transaction.payment.quantity, product: payment.product, transaction: transaction, originalTransaction: transaction.original, needsFinishTransaction: !payment.atomically)
+
+            payment.callback(.purchased(purchase: purchase))
+
+            if payment.atomically {
+                paymentQueue.finishTransaction(transaction)
+            }
+            payments.remove(at: paymentIndex)
+            return true
+        }
+
         if transactionState == .failed {
 
             payment.callback(.failed(error: transactionError(for: transaction.error as NSError?)))
@@ -112,9 +127,6 @@ class PaymentsController: TransactionController {
             return true
         }
 
-        if transactionState == .restored {
-            print("Unexpected restored transaction for payment \(transactionProductIdentifier)")
-        }
         return false
     }