|
@@ -104,7 +104,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
self.orderId = orderId
|
|
|
if SKPaymentQueue.canMakePayments() {
|
|
|
if let product = availableProducts.first(where: { $0.productIdentifier == productIdentifier }) {
|
|
|
- print("\("购买产品") + \(productIdentifier)")
|
|
|
+ KMPrint("\("购买产品") + \(productIdentifier)")
|
|
|
let payment = SKMutablePayment(product: product)
|
|
|
payment.applicationUsername = orderId
|
|
|
SKPaymentQueue.default().add(payment)
|
|
@@ -137,7 +137,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
//MARK: 购买返回类型
|
|
|
func handleAction(state: KMInAppPurchaseState) {
|
|
|
#if DEBUG
|
|
|
- print(state.rawValue)
|
|
|
+ KMPrint(state.rawValue)
|
|
|
#endif
|
|
|
DispatchQueue.main.async { [unowned self] in
|
|
|
if state == .verSuccess {
|
|
@@ -161,17 +161,17 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
extension KMInAppPurchaseManager: SKProductsRequestDelegate {
|
|
|
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
|
|
availableProducts = response.products
|
|
|
- print(availableProducts)
|
|
|
+ KMPrint(availableProducts)
|
|
|
#if DEBUG
|
|
|
- print(response.invalidProductIdentifiers)
|
|
|
- print("产品付费数量")
|
|
|
- print(response.products.count)
|
|
|
+ KMPrint(response.invalidProductIdentifiers)
|
|
|
+ KMPrint("产品付费数量")
|
|
|
+ KMPrint(response.products.count)
|
|
|
for p in response.products {
|
|
|
- print(p.description)
|
|
|
- print(p.localizedTitle)
|
|
|
- print(p.localizedDescription)
|
|
|
- print(p.price);
|
|
|
- print(p.productIdentifier)
|
|
|
+ KMPrint(p.description)
|
|
|
+ KMPrint(p.localizedTitle)
|
|
|
+ KMPrint(p.localizedDescription)
|
|
|
+ KMPrint(p.price);
|
|
|
+ KMPrint(p.productIdentifier)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -187,7 +187,7 @@ extension KMInAppPurchaseManager: SKProductsRequestDelegate {
|
|
|
|
|
|
func request(_ request: SKRequest, didFailWithError error: Error) {
|
|
|
// 处理请求错误
|
|
|
- print("\("用户无法进行内购") + \(error)")
|
|
|
+ KMPrint("\("用户无法进行内购") + \(error)")
|
|
|
self.handleAction(state: .notArrow)
|
|
|
}
|
|
|
}
|
|
@@ -200,7 +200,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
}
|
|
|
|
|
|
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
|
- print("服务器返回数据")
|
|
|
+ KMPrint("服务器返回数据")
|
|
|
let hasPurchased = false
|
|
|
let hasFailed = false
|
|
|
if transactions.count > 0 {
|
|
@@ -209,16 +209,16 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
switch transaction.transactionState {
|
|
|
case .purchased:
|
|
|
// 购买成功,进行本地二次验证
|
|
|
- print("购买成功,进行本地二次验证")
|
|
|
+ KMPrint("购买成功,进行本地二次验证")
|
|
|
// self.handleAction(state: .success)
|
|
|
validatePurchase(transaction: transaction)
|
|
|
case .failed:
|
|
|
// 购买失败,处理错误
|
|
|
- print("购买失败,处理错误")
|
|
|
+ KMPrint("购买失败,处理错误")
|
|
|
handleError(transaction: transaction)
|
|
|
case .restored:
|
|
|
// 恢复购买,进行本地二次验证
|
|
|
- print("恢复购买,进行本地二次验证")
|
|
|
+ KMPrint("恢复购买,进行本地二次验证")
|
|
|
// self.handleAction(state: .restoreSuccess)
|
|
|
validatePurchase(transaction: transaction)
|
|
|
default:
|
|
@@ -254,7 +254,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
// 构建请求
|
|
|
let receiptString = receiptData.base64EncodedString(options: [])
|
|
|
let tempOrderId = self.orderId ?? ""
|
|
|
- print(receiptString)
|
|
|
+ KMPrint(receiptString)
|
|
|
if transaction.transactionState == .restored {
|
|
|
KMRequestServerManager.manager.parseVerification(applePayProductId: PRODUCT_1, orderId: tempOrderId, receipt: receiptString, restore: 1) { [unowned self] success, result in
|
|
|
if success, let data = result?.result {
|
|
@@ -331,7 +331,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
}
|
|
|
|
|
|
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
|
|
|
- print("paymentQueueRestoreCompletedTransactionsFinished")
|
|
|
+ KMPrint("paymentQueueRestoreCompletedTransactionsFinished")
|
|
|
}
|
|
|
|
|
|
func parseVerificationResult(data: Data) -> Bool {
|
|
@@ -339,7 +339,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
// 如果验证成功返回 true,否则返回 false
|
|
|
// ...
|
|
|
let receipt: [String: Any] = self.parseReceipt(receiptData: data) ?? [:]
|
|
|
- print(receipt)
|
|
|
+ KMPrint(receipt)
|
|
|
let status: Int = receipt["status"] as! Int
|
|
|
if status == 21007 {
|
|
|
self.handleAction(state: .verFailed)
|
|
@@ -366,7 +366,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
// 如果验证成功返回 true,否则返回 false
|
|
|
// ...
|
|
|
let receipt: [String: Any] = self.parseReceipt(receiptData: data) ?? [:]
|
|
|
- print(receipt)
|
|
|
+ KMPrint(receipt)
|
|
|
let status: Int = receipt["status"] as! Int
|
|
|
if status == 21007 {
|
|
|
self.handleAction(state: .verFailed)
|