Ver Fonte

Not callback when purchse but get restored state

bird há 6 anos atrás
pai
commit
b216b219bd
1 ficheiros alterados com 15 adições e 3 exclusões
  1. 15 3
      SwiftyStoreKit/PaymentsController.swift

+ 15 - 3
SwiftyStoreKit/PaymentsController.swift

@@ -83,6 +83,21 @@ class PaymentsController: TransactionController {
             payments.remove(at: paymentIndex)
             payments.remove(at: paymentIndex)
             return true
             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 {
         if transactionState == .failed {
 
 
             payment.callback(.failed(error: transactionError(for: transaction.error as NSError?)))
             payment.callback(.failed(error: transactionError(for: transaction.error as NSError?)))
@@ -92,9 +107,6 @@ class PaymentsController: TransactionController {
             return true
             return true
         }
         }
 
 
-        if transactionState == .restored {
-            print("Unexpected restored transaction for payment \(transactionProductIdentifier)")
-        }
         return false
         return false
     }
     }