|
@@ -1,11 +1,24 @@
|
|
|
-import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
|
|
|
|
|
|
+import 'dart:io';
|
|
|
|
|
+
|
|
|
|
|
+import 'package:classify_photo/classify_photo.dart';
|
|
|
|
|
+import 'package:clean/module/store/payment_status_manager.dart';
|
|
|
|
|
+import 'package:flutter/Material.dart';
|
|
|
|
|
+import 'package:get/get.dart';
|
|
|
|
|
+import 'package:in_app_purchase/in_app_purchase.dart';
|
|
|
|
|
|
|
|
import '../../base/base_controller.dart';
|
|
import '../../base/base_controller.dart';
|
|
|
|
|
+import '../../data/api/response/order_pay_response.dart';
|
|
|
import '../../data/bean/payment_way.dart';
|
|
import '../../data/bean/payment_way.dart';
|
|
|
import '../../data/bean/store_item.dart';
|
|
import '../../data/bean/store_item.dart';
|
|
|
|
|
+import '../../data/consts/constants.dart';
|
|
|
|
|
+import '../../data/repositories/store_repository.dart';
|
|
|
|
|
+import '../../dialog/loading_dialog.dart';
|
|
|
|
|
+import '../../sdk/pay/agile_pay.dart';
|
|
|
|
|
+import '../../sdk/pay/applepay/apple_pay_info.dart';
|
|
|
|
|
+import '../../sdk/pay/assist/product_type.dart';
|
|
|
import '../../utils/toast_util.dart';
|
|
import '../../utils/toast_util.dart';
|
|
|
|
|
|
|
|
-class StoreController extends BaseController {
|
|
|
|
|
|
|
+class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
|
|
|
|
|
final RxList<StoreItem> storeItems = <StoreItem>[].obs;
|
|
final RxList<StoreItem> storeItems = <StoreItem>[].obs;
|
|
|
|
|
|
|
@@ -16,17 +29,35 @@ class StoreController extends BaseController {
|
|
|
final Rxn<PaymentWay> currentSelectedPaymentWay = Rxn<PaymentWay>();
|
|
final Rxn<PaymentWay> currentSelectedPaymentWay = Rxn<PaymentWay>();
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
- void onInit() {
|
|
|
|
|
|
|
+ Future<void> onInit() async {
|
|
|
// TODO: implement onInit
|
|
// TODO: implement onInit
|
|
|
- StoreItem item1 = StoreItem(id: 1, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
- StoreItem item2 = StoreItem(id: 2, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
- StoreItem item3 = StoreItem(id: 3, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
|
|
+ // StoreItem item1 = StoreItem(id: 1, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
+ // StoreItem item2 = StoreItem(id: 2, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
+ // StoreItem item3 = StoreItem(id: 3, sort: 1, name: "11111", appleGoodsId: "1111", subscribable: 1, amount: 100, originalAmount: 100, auth: "auth", subscriptionMillis: 1, content: "content", priceDesc: "priceDesc", coefficient: 1);
|
|
|
|
|
+ //
|
|
|
|
|
+ // storeItems.add(item1);
|
|
|
|
|
+ // storeItems.add(item2);
|
|
|
|
|
+ // storeItems.add(item3);
|
|
|
|
|
+ //
|
|
|
|
|
+ // currentSelectedStoreItem.value = item1;
|
|
|
|
|
+
|
|
|
|
|
+ initStoreIndexData();
|
|
|
|
|
+
|
|
|
|
|
+ print(await ClassifyPhoto().checkTrialEligibility());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- storeItems.add(item1);
|
|
|
|
|
- storeItems.add(item2);
|
|
|
|
|
- storeItems.add(item3);
|
|
|
|
|
|
|
+ void initStoreIndexData() {
|
|
|
|
|
+ storeRepository.storeIndex().then((indexData) {
|
|
|
|
|
+ storeItems.clear();
|
|
|
|
|
+ storeItems.addAll(indexData.items);
|
|
|
|
|
+ currentSelectedStoreItem.value =
|
|
|
|
|
+ storeItems.isNotEmpty ? storeItems.first : null;
|
|
|
|
|
|
|
|
- currentSelectedStoreItem.value = item1;
|
|
|
|
|
|
|
+ paymentWays.clear();
|
|
|
|
|
+ paymentWays.addAll(indexData.paymentWays);
|
|
|
|
|
+ currentSelectedPaymentWay.value =
|
|
|
|
|
+ paymentWays.isNotEmpty ? paymentWays.first : null;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void onBuyClick() async {
|
|
void onBuyClick() async {
|
|
@@ -43,6 +74,59 @@ class StoreController extends BaseController {
|
|
|
}
|
|
}
|
|
|
int payPlatform = paymentWay.payPlatform;
|
|
int payPlatform = paymentWay.payPlatform;
|
|
|
int payMethod = paymentWay.payMethod;
|
|
int payMethod = paymentWay.payMethod;
|
|
|
- LoadingDialog.show(StringName.storePayLoading.tr);
|
|
|
|
|
|
|
+ // LoadingDialog.show(StringName.storePayLoading.tr);
|
|
|
|
|
+ try {
|
|
|
|
|
+ OrderPayResponse response =
|
|
|
|
|
+ await storeRepository.orderPay(storeItem.id, payPlatform, payMethod);
|
|
|
|
|
+
|
|
|
|
|
+ dynamic payInfo;
|
|
|
|
|
+ String outTradeNo = response.outTradeNo;
|
|
|
|
|
+ if (payPlatform == PayPlatform.apple) {
|
|
|
|
|
+ payInfo = ApplePayInfo(
|
|
|
|
|
+ storeItem.appleGoodsId,
|
|
|
|
|
+ storeItem.subscribable == 1
|
|
|
|
|
+ ? ProductType.nonConsumable
|
|
|
|
|
+ : ProductType.consumable,
|
|
|
|
|
+ response.appAccountToken);
|
|
|
|
|
+ }
|
|
|
|
|
+ Future.delayed(const Duration(seconds: 30), () {
|
|
|
|
|
+ LoadingDialog.hide();
|
|
|
|
|
+ });
|
|
|
|
|
+ AgilePay.startPay(payInfo, success: (String? result) {
|
|
|
|
|
+ LoadingDialog.show("");
|
|
|
|
|
+ checkPaymentStatus(outTradeNo, paymentWay, storeItem,
|
|
|
|
|
+ receiptData: result);
|
|
|
|
|
+ Future.delayed(const Duration(seconds: 30), () {
|
|
|
|
|
+ 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();
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ LoadingDialog.hide();
|
|
|
|
|
+ // ToastUtil.showToast(StringName.storePayError.tr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void checkPaymentStatus(
|
|
|
|
|
+ String orderNo, PaymentWay paymentWay, StoreItem storeItemBean,
|
|
|
|
|
+ {String? receiptData}) {
|
|
|
|
|
+ paymentStatusManager.registerPaymentSuccessCallback(orderNo, this);
|
|
|
|
|
+ paymentStatusManager.checkPaymentStatus(orderNo, paymentWay, storeItemBean,
|
|
|
|
|
+ receiptData: receiptData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @override
|
|
|
|
|
+ void onPaymentSuccess(String orderNo, PaymentWay paymentWay, StoreItem storeItemBean) {
|
|
|
|
|
+ // TODO: implement onPaymentSuccess
|
|
|
|
|
+ LoadingDialog.hide();
|
|
|
|
|
+ ToastUtil.show("Pay success");
|
|
|
|
|
+ Get.back();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|