|
|
@@ -1,28 +1,29 @@
|
|
|
import 'package:electronic_assistant/base/base_controller.dart';
|
|
|
import 'package:electronic_assistant/data/bean/payment_way.dart';
|
|
|
import 'package:electronic_assistant/data/repositories/store_repository.dart';
|
|
|
+import 'package:electronic_assistant/module/store/payment_status_manager.dart';
|
|
|
import 'package:electronic_assistant/resource/string.gen.dart';
|
|
|
import 'package:electronic_assistant/router/app_pages.dart';
|
|
|
import 'package:electronic_assistant/sdk/pay/agile_pay.dart';
|
|
|
import 'package:electronic_assistant/sdk/pay/alipay/ali_pay_info.dart';
|
|
|
import 'package:electronic_assistant/sdk/pay/applepay/apple_pay_info.dart';
|
|
|
import 'package:electronic_assistant/sdk/pay/code/agile_pay_code.dart';
|
|
|
-import 'package:electronic_assistant/utils/error_handler.dart';
|
|
|
import 'package:electronic_assistant/utils/http_handler.dart';
|
|
|
import 'package:electronic_assistant/utils/toast_util.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import '../../data/api/response/order_pay_response.dart';
|
|
|
+import '../../data/api/response/user_info_response.dart';
|
|
|
import '../../data/bean/store_item.dart';
|
|
|
import '../../data/bean/wechat_payment_sign_bean.dart';
|
|
|
import '../../data/consts/constants.dart';
|
|
|
import '../../data/consts/error_code.dart';
|
|
|
+import '../../data/repositories/account_repository.dart';
|
|
|
import '../../dialog/loading_dialog.dart';
|
|
|
import '../../sdk/pay/assist/product_type.dart';
|
|
|
-import '../../sdk/pay/listener/agile_pay_state.dart';
|
|
|
import '../../sdk/pay/wxpay/wechat_pay_info.dart';
|
|
|
|
|
|
-class StoreController extends BaseController {
|
|
|
+class StoreController extends BaseController implements PaymentStatusCallback {
|
|
|
final isExpanded = false.obs;
|
|
|
|
|
|
final RxList<StoreItem> storeItems = <StoreItem>[].obs;
|
|
|
@@ -35,6 +36,10 @@ class StoreController extends BaseController {
|
|
|
|
|
|
final RxBool isPaymentWayExpanded = false.obs;
|
|
|
|
|
|
+ final Rxn<UserInfoResponse> _userInfo = accountRepository.userInfo;
|
|
|
+
|
|
|
+ UserInfoResponse? get userInfo => _userInfo.value;
|
|
|
+
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
@@ -82,7 +87,7 @@ class StoreController extends BaseController {
|
|
|
await storeRepository.orderPay(storeItem.id, payPlatform, payMethod);
|
|
|
|
|
|
dynamic payInfo;
|
|
|
-
|
|
|
+ String outTradeNo = response.outTradeNo;
|
|
|
if (payPlatform == PayPlatform.android) {
|
|
|
if (payMethod == PayMethod.alipay) {
|
|
|
payInfo = AliPayInfo(response.alipayOrderString!);
|
|
|
@@ -107,42 +112,62 @@ class StoreController extends BaseController {
|
|
|
response.appAccountToken);
|
|
|
}
|
|
|
AgilePay.startPay(payInfo, success: (String? result) {
|
|
|
- ToastUtil.showToast('支付成功');
|
|
|
- LoadingDialog.hide();
|
|
|
+ LoadingDialog.show(StringName.storeQueryPayState.tr);
|
|
|
+ checkPaymentStatus(outTradeNo, paymentWay, storeItem);
|
|
|
+ Future.delayed(const Duration(seconds: 30), () {
|
|
|
+ LoadingDialog.hide();
|
|
|
+ });
|
|
|
}, payError: (int error, String? errorMessage) {
|
|
|
- ToastUtil.showToast(StringName.storePayError.tr);
|
|
|
+ errorPayToast(error);
|
|
|
LoadingDialog.hide();
|
|
|
}, error: (int errno, String? error) {
|
|
|
- if (errno == AgilePayCode.payCodeNotSupport) {
|
|
|
- ToastUtil.showToast(StringName.storePayNotSupport.tr);
|
|
|
- } else if (errno == AgilePayCode.payCodeCancelError) {
|
|
|
- ToastUtil.showToast(StringName.storePayUserCancel.tr);
|
|
|
- } else if (errno == AgilePayCode.payCodeWxEnvError) {
|
|
|
- ToastUtil.showToast(StringName.storePayWxEvnError.tr);
|
|
|
- } else if (errno == AgilePayCode.payCodeNotConnectStore) {
|
|
|
- ToastUtil.showToast(StringName.storePayNotConnectstore.tr);
|
|
|
- } else {
|
|
|
- ToastUtil.showToast(StringName.storePayError.tr);
|
|
|
- }
|
|
|
+ errorPayToast(errno);
|
|
|
LoadingDialog.hide();
|
|
|
});
|
|
|
} catch (error) {
|
|
|
+ LoadingDialog.hide();
|
|
|
if (error is ServerErrorException &&
|
|
|
error.code == ErrorCode.errorCodeNoLogin) {
|
|
|
ToastUtil.showToast(StringName.errorCodeNoLogin.tr);
|
|
|
Get.toNamed(RoutePath.login);
|
|
|
} else {
|
|
|
- ErrorHandler.toastError(error);
|
|
|
+ ToastUtil.showToast(StringName.storePayError.tr);
|
|
|
}
|
|
|
}
|
|
|
- // finally {
|
|
|
- // LoadingDialog.hide();
|
|
|
- // }
|
|
|
+ }
|
|
|
+
|
|
|
+ void errorPayToast(int errno) {
|
|
|
+ if (errno == AgilePayCode.payCodeNotSupport) {
|
|
|
+ ToastUtil.showToast(StringName.storePayNotSupport.tr);
|
|
|
+ } else if (errno == AgilePayCode.payCodeCancelError) {
|
|
|
+ ToastUtil.showToast(StringName.storePayUserCancel.tr);
|
|
|
+ } else if (errno == AgilePayCode.payCodeWxEnvError) {
|
|
|
+ ToastUtil.showToast(StringName.storePayWxEvnError.tr);
|
|
|
+ } else if (errno == AgilePayCode.payCodeNotConnectStore) {
|
|
|
+ ToastUtil.showToast(StringName.storePayNotConnectstore.tr);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(StringName.storePayError.tr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void checkPaymentStatus(
|
|
|
+ String orderNo, PaymentWay paymentWay, StoreItem storeItemBean) {
|
|
|
+ paymentStatusManager.registerPaymentSuccessCallback(orderNo, this);
|
|
|
+ paymentStatusManager.checkPaymentStatus(orderNo, paymentWay, storeItemBean);
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void onClose() {
|
|
|
super.onClose();
|
|
|
AgilePay.dispose();
|
|
|
+ paymentStatusManager.unregisterPaymentSuccessCallback(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onPaymentSuccess(
|
|
|
+ String orderNo, PaymentWay paymentWay, StoreItem storeItemBean) {
|
|
|
+ LoadingDialog.hide();
|
|
|
+ ToastUtil.showToast(StringName.storePaySuccess.tr);
|
|
|
+ Get.back();
|
|
|
}
|
|
|
}
|