Procházet zdrojové kódy

[fix]修复支付完未刷新时长的问题

Destiny před 11 měsíci
rodič
revize
0040341926

+ 5 - 20
lib/module/store/store_controller.dart

@@ -91,24 +91,6 @@ class StoreController extends BaseController implements PaymentStatusCallback {
       ToastUtil.show("Pay Error");
       print('恢复失败: ${result['error']}');
     }
-
-    // AgilePay.restore(success: (String? result) {
-    //   // LoadingDialog.hide();
-    // }, payError: (int error, String? errorMessage) {
-    //   debugPrint('zk---payError: $error, $errorMessage');
-    //   // errorPayToast(error);
-    //   LoadingDialog.hide();
-    // }, error: (int errno, String? error) {
-    //   debugPrint('zk---error: $errno, $error');
-    //   // errorPayToast(errno);
-    //   LoadingDialog.hide();
-    // }, restore: (String? result) {
-    //   LoadingDialog.show("");
-    //   checkRestoreStatus(result);
-    //   Future.delayed(const Duration(seconds: 30), () {
-    //     LoadingDialog.hide();
-    //   });
-    // });
   }
 
   void onBuyClick() async {
@@ -148,7 +130,7 @@ class StoreController extends BaseController implements PaymentStatusCallback {
           checkPaymentStatus(outTradeNo, paymentWay, storeItem, receiptData: receipt);
         } else {
           LoadingDialog.hide();
-          ToastUtil.show("Pay Error");
+          ToastUtil.show("Pay Error, Please try again");
           print('购买失败: ${result['error']}');
         }
       }).catchError((error) {
@@ -225,7 +207,10 @@ class StoreController extends BaseController implements PaymentStatusCallback {
     // TODO: implement onPaymentSuccess
     LoadingDialog.hide();
     ToastUtil.show("Pay success");
-    userRepository.getUserInfo();
+    // 300ms后关闭弹窗
+    Future.delayed(Duration(seconds: 3), () {
+      userRepository.getUserInfo();
+    });
     Get.back();
   }
 

+ 10 - 6
plugins/apple_pay/ios/Classes/ApplePayManager.swift

@@ -38,6 +38,7 @@ extension ApplePayManager {
     @available(iOS 15.0.0, *)
     func check(appleId: String) async -> Bool {
         print("检查自动续费订单及是否存在试用资格")
+        SKPaymentQueue.default().add(self)
         self.isCheck = true
 
         do {
@@ -91,7 +92,7 @@ extension ApplePayManager {
             }
         }
         
-        self.isPaying = true
+        self.isPaying = false
         self.isCheck = false
         self.isRestoring = false
         self.completion = complete
@@ -138,7 +139,7 @@ extension ApplePayManager: SKPaymentTransactionObserver {
             
         print("监听AppStore支付状态 updatedTransactions")
         
-        if !self.isPaying { return }
+//        if !self.isPaying { return }
         
         DispatchQueue.main.async {
             for tran in transactions {
@@ -147,17 +148,20 @@ extension ApplePayManager: SKPaymentTransactionObserver {
                 case .purchased:
                     print("商品已苹果支付成功")
                     
-                    if self.isCheck {
-                        SKPaymentQueue.default().finishTransaction(tran)
-                    } else {
-                        SKPaymentQueue.default().finishTransaction(tran)
+                    if self.isPaying {
                         if let receiptUrl = Bundle.main.appStoreReceiptURL {
                             let receiptData = try? Data(contentsOf: receiptUrl)
                             if let receiptString = receiptData?.base64EncodedString(options: .endLineWithLineFeed), let completion = self.completion {
                                 completion(true, receiptString)
                             }
                         }
+                    } else {
+                        if let completion = self.completion {
+                            completion(false, "")
+                        }
                     }
+                    
+                    SKPaymentQueue.default().finishTransaction(tran)
                 case .purchasing:
                     print("正在购买中,商品已添加进列表")
                 case .restored:

+ 1 - 1
pubspec.yaml

@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 # In Windows, build-name is used as the major, minor, and patch parts
 # of the product and file versions while build-number is used as the build suffix.
-version: 1.0.0+11
+version: 1.0.0+15
 
 environment:
   sdk: ^3.6.0