|
|
@@ -2,6 +2,7 @@ import 'dart:io';
|
|
|
|
|
|
import 'package:apple_pay/apple_pay.dart';
|
|
|
import 'package:classify_photo/classify_photo.dart';
|
|
|
+import 'package:clean/data/repositories/config_repository.dart';
|
|
|
import 'package:clean/data/repositories/user_repository.dart';
|
|
|
import 'package:clean/module/store/payment_status_manager.dart';
|
|
|
import 'package:clean/router/app_pages.dart';
|
|
|
@@ -25,7 +26,6 @@ import '../../sdk/pay/assist/product_type.dart';
|
|
|
import '../../utils/toast_util.dart';
|
|
|
|
|
|
class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
-
|
|
|
final RxList<StoreItem> storeItems = <StoreItem>[].obs;
|
|
|
|
|
|
final RxList<PaymentWay> paymentWays = <PaymentWay>[].obs;
|
|
|
@@ -48,31 +48,32 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
void onReady() {
|
|
|
EventHandler.report(EventId.event_02001);
|
|
|
super.onReady();
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
@override
|
|
|
void onClose() {
|
|
|
// TODO: implement onClose
|
|
|
super.onClose();
|
|
|
- if (isFirstIntoStore() && !userRepository.isVip()) {
|
|
|
+ if (isFirstIntoStore() &&
|
|
|
+ !userRepository.isVip() &&
|
|
|
+ configRepository.enable.value) {
|
|
|
Get.toNamed(RoutePath.discount);
|
|
|
setFirstIntoStore(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void initStoreIndexData() {
|
|
|
LoadingDialog.showLoading();
|
|
|
storeRepository.storeIndex().then((indexData) async {
|
|
|
storeItems.clear();
|
|
|
storeItems.addAll(indexData.items);
|
|
|
currentSelectedStoreItem.value =
|
|
|
- storeItems.isNotEmpty ? storeItems.first : null;
|
|
|
+ storeItems.isNotEmpty ? storeItems.first : null;
|
|
|
|
|
|
paymentWays.clear();
|
|
|
paymentWays.addAll(indexData.paymentWays);
|
|
|
currentSelectedPaymentWay.value =
|
|
|
- paymentWays.isNotEmpty ? paymentWays.first : null;
|
|
|
+ paymentWays.isNotEmpty ? paymentWays.first : null;
|
|
|
|
|
|
var freeAppleId = "";
|
|
|
for (var item in storeItems) {
|
|
|
@@ -117,7 +118,6 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
}
|
|
|
|
|
|
void onBuyClick() async {
|
|
|
-
|
|
|
EventHandler.report(EventId.event_02002);
|
|
|
StoreItem? storeItem = currentSelectedStoreItem.value;
|
|
|
if (storeItem == null) {
|
|
|
@@ -134,8 +134,9 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
LoadingDialog.showLoading();
|
|
|
try {
|
|
|
// OrderPayResponse response =
|
|
|
- storeRepository.orderPay(storeItem.id, payPlatform, payMethod).then((response) async {
|
|
|
-
|
|
|
+ storeRepository
|
|
|
+ .orderPay(storeItem.id, payPlatform, payMethod)
|
|
|
+ .then((response) async {
|
|
|
dynamic payInfo;
|
|
|
String outTradeNo = response.outTradeNo;
|
|
|
if (payPlatform == PayPlatform.apple) {
|
|
|
@@ -147,11 +148,14 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
response.appAccountToken);
|
|
|
}
|
|
|
|
|
|
- final result = await ApplePay().purchase(productId: storeItem.appleGoodsId, appAccountToken: response.appAccountToken);
|
|
|
+ final result = await ApplePay().purchase(
|
|
|
+ productId: storeItem.appleGoodsId,
|
|
|
+ appAccountToken: response.appAccountToken);
|
|
|
if (result["success"] == true) {
|
|
|
var receipt = result['receipt'];
|
|
|
print('购买成功: ${result['receipt']}');
|
|
|
- checkPaymentStatus(outTradeNo, paymentWay, storeItem, receiptData: receipt);
|
|
|
+ checkPaymentStatus(outTradeNo, paymentWay, storeItem,
|
|
|
+ receiptData: receipt);
|
|
|
} else {
|
|
|
LoadingDialog.hide();
|
|
|
ToastUtil.show("Pay Error, Please try again");
|
|
|
@@ -167,10 +171,11 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void closeBackClick(){
|
|
|
+ void closeBackClick() {
|
|
|
EventHandler.report(EventId.event_02003);
|
|
|
Get.back();
|
|
|
}
|
|
|
+
|
|
|
// 检查恢复订阅结果
|
|
|
Future<void> checkRestoreStatus(String? receiptData) async {
|
|
|
PaymentWay? paymentWay = currentSelectedPaymentWay.value;
|
|
|
@@ -214,7 +219,8 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
- void onPaymentSuccess(String orderNo, PaymentWay paymentWay, StoreItem storeItemBean) {
|
|
|
+ void onPaymentSuccess(
|
|
|
+ String orderNo, PaymentWay paymentWay, StoreItem storeItemBean) {
|
|
|
// TODO: implement onPaymentSuccess
|
|
|
LoadingDialog.hide();
|
|
|
ToastUtil.show("Pay success");
|
|
|
@@ -231,4 +237,4 @@ class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
LoadingDialog.hide();
|
|
|
ErrorHandler.toastError(error);
|
|
|
}
|
|
|
-}
|
|
|
+}
|