Browse Source

[feat]会员折扣页,增加iOS内购支付插件和调用

hezihao 6 months ago
parent
commit
9ea21b9653
1 changed files with 61 additions and 1 deletions
  1. 61 1
      lib/module/store/new_discount/new_discount_controller.dart

+ 61 - 1
lib/module/store/new_discount/new_discount_controller.dart

@@ -876,10 +876,70 @@ class NewDiscountController extends BaseController
   }
 
   /// 恢复订阅
-  void clickRestore() {
+  Future<void> clickRestore() async {
+    PayWayInfo? paymentWay = _selectedPayWay.value;
+    if (paymentWay == null) {
+      return;
+    }
+    int payPlatform = paymentWay.payPlatform;
+    int payMethod = paymentWay.payMethod;
+
+    CustomLoadingDialog.show();
+
+    Future.delayed(const Duration(seconds: 20), () {
+      CustomLoadingDialog.hide();
+      ToastUtil.show("Restore record not found");
+    });
+
+    final result = await ApplePay().restore();
+    if (result["success"] == true) {
+      // CustomLoadingDialog.hide();
+      var receipt = result['receipt'];
+      print('查找恢复记录成功: ${result['receipt']}');
+      checkRestoreStatus(receipt);
+    } else {
+      CustomLoadingDialog.hide();
+      ToastUtil.show("Pay Error");
+      print('恢复失败: ${result['error']}');
+    }
+
     // 显示恢复订阅弹窗
     // RecoverSubscribeDialog.show("周会员2025年3月6日到期。", () {
     //   AtmobLog.d(tag, "恢复订阅弹窗 => 点击确认");
     // });
   }
+
+  /// 检查恢复订阅结果
+  Future<void> checkRestoreStatus(String? receiptData) async {
+    PayWayInfo? paymentWay = _selectedPayWay.value;
+    if (paymentWay == null) {
+      // ToastUtil.showToast(StringName.storeChoicePayment.tr);
+      return;
+    }
+    if (receiptData == null) {
+      return;
+    }
+    int payPlatform = paymentWay.payPlatform;
+    int payMethod = paymentWay.payMethod;
+    // var code = await storeRepository.resume(payPlatform, payMethod, receiptData);
+    storeRepository.resume(payPlatform, payMethod, receiptData).then((data) {
+      CustomLoadingDialog.hide();
+      ToastUtil.show("Restore success");
+      accountRepository.getUserInfo();
+      Get.back();
+    }).catchError((error) {
+      CustomLoadingDialog.hide();
+      ToastUtil.show("Restore fail");
+    });
+
+    // if (code == 0) {
+    //   CustomLoadingDialog.hide();
+    //   ToastUtil.show("Restore success");
+    //   userRepository.getUserInfo();
+    //   Get.back();
+    // } else {
+    //   CustomLoadingDialog.hide();
+    //   ToastUtil.show("Restore fail");
+    // }
+  }
 }