|
@@ -12,6 +12,7 @@ import 'package:location/data/bean/goods_bean.dart';
|
|
|
import 'package:location/data/bean/pay_item_bean.dart';
|
|
import 'package:location/data/bean/pay_item_bean.dart';
|
|
|
import 'package:location/data/repositories/account_repository.dart';
|
|
import 'package:location/data/repositories/account_repository.dart';
|
|
|
import 'package:location/data/repositories/member_repository.dart';
|
|
import 'package:location/data/repositories/member_repository.dart';
|
|
|
|
|
+import 'package:location/dialog/alipay_qr_code_dialog.dart';
|
|
|
import 'package:location/handler/error_handler.dart';
|
|
import 'package:location/handler/error_handler.dart';
|
|
|
import 'package:location/module/login/login_page.dart';
|
|
import 'package:location/module/login/login_page.dart';
|
|
|
import 'package:location/resource/assets.gen.dart';
|
|
import 'package:location/resource/assets.gen.dart';
|
|
@@ -239,7 +240,7 @@ class MemberController extends BaseController implements PaymentStatusCallback {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void onBuyClick() async {
|
|
|
|
|
|
|
+ void onBuyClick() {
|
|
|
if (selectedGoods == null) {
|
|
if (selectedGoods == null) {
|
|
|
ToastUtil.show(StringName.memberPleaseChoiceGoods);
|
|
ToastUtil.show(StringName.memberPleaseChoiceGoods);
|
|
|
return;
|
|
return;
|
|
@@ -254,60 +255,108 @@ class MemberController extends BaseController implements PaymentStatusCallback {
|
|
|
int goodsId = buyGoods.id;
|
|
int goodsId = buyGoods.id;
|
|
|
int payPlatform = buyPayWay.payPlatform;
|
|
int payPlatform = buyPayWay.payPlatform;
|
|
|
int payMethod = buyPayWay.payMethod;
|
|
int payMethod = buyPayWay.payMethod;
|
|
|
- LoadingDialog.show(StringName.payLoading);
|
|
|
|
|
|
|
+ int payWayType =
|
|
|
|
|
+ getPayWayType(payMethod: payMethod, payPlatform: payPlatform);
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- RequestPayResponse response = await memberRepository.submitAndRequestPay(
|
|
|
|
|
- goodsId: goodsId, payPlatform: payPlatform, payMethod: payMethod);
|
|
|
|
|
- dynamic payInfo;
|
|
|
|
|
- String outTradeNo = response.outTradeNo;
|
|
|
|
|
- if (payPlatform == PayPlatform.android) {
|
|
|
|
|
- if (payMethod == PayMethod.alipay) {
|
|
|
|
|
- payInfo = AliPayInfo(response.alipayOrderString!);
|
|
|
|
|
- } else if (payMethod == PayMethod.wechat) {
|
|
|
|
|
- WechatPaymentSignBean bean =
|
|
|
|
|
- WechatPaymentSignBean.stringToBean(response.wechatPayPrepayJson!);
|
|
|
|
|
- payInfo = WechatPayInfo(
|
|
|
|
|
- appId: bean.appId,
|
|
|
|
|
- partnerId: bean.partnerId,
|
|
|
|
|
- prepayId: bean.prepayId,
|
|
|
|
|
- package: bean.package,
|
|
|
|
|
- noncestr: bean.nonceStr,
|
|
|
|
|
- timestamp: bean.timeStamp,
|
|
|
|
|
- sign: bean.sign);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ LoadingDialog.show(StringName.payLoading);
|
|
|
|
|
+ memberRepository
|
|
|
|
|
+ .submitAndRequestPay(
|
|
|
|
|
+ goodsId: goodsId, payPlatform: payPlatform, payMethod: payMethod)
|
|
|
|
|
+ .then((response) {
|
|
|
|
|
+ if (payWayType == PayWayType.paymentWayWechat) {
|
|
|
|
|
+ _onWeChatPay(response.outTradeNo, response.wechatPayPrepayJson!,
|
|
|
|
|
+ payMethod, buyGoods, buyPayWay);
|
|
|
|
|
+ } else if (payWayType == PayWayType.paymentWayWechatScan) {
|
|
|
|
|
+ _onWechatScanPay();
|
|
|
|
|
+ } else if (payWayType == PayWayType.paymentWayAlipay) {
|
|
|
|
|
+ _onAliPay(response.outTradeNo, response.alipayOrderString!, payMethod,
|
|
|
|
|
+ buyGoods, buyPayWay);
|
|
|
|
|
+ } else if (payWayType == PayWayType.paymentWayAlipayScan) {
|
|
|
|
|
+ _onAliScanPay(response.outTradeNo, response.alipayQrcodeHtml!,
|
|
|
|
|
+ buyPayWay, buyGoods);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ToastUtil.show(StringName.payNotSupport);
|
|
|
}
|
|
}
|
|
|
- AgilePay.startPay(payInfo, success: (String? result) {
|
|
|
|
|
- LoadingDialog.show(StringName.payQuerypayState);
|
|
|
|
|
- checkPaymentStatus(outTradeNo, buyPayWay, buyGoods,
|
|
|
|
|
- receiptData: result);
|
|
|
|
|
- Future.delayed(const Duration(seconds: 30), () {
|
|
|
|
|
- LoadingDialog.hide();
|
|
|
|
|
- });
|
|
|
|
|
- }, payError: (int error, String? errorMessage) {
|
|
|
|
|
- debugPrint('zk---payError: $error, $errorMessage');
|
|
|
|
|
- errorPayToast(error);
|
|
|
|
|
- errorEventReport(payMethod);
|
|
|
|
|
- LoadingDialog.hide();
|
|
|
|
|
- }, error: (int errno, String? error) {
|
|
|
|
|
- debugPrint('zk---error: $errno, $error');
|
|
|
|
|
- errorPayToast(errno);
|
|
|
|
|
- errorEventReport(payMethod);
|
|
|
|
|
- LoadingDialog.hide();
|
|
|
|
|
- });
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- LoadingDialog.hide();
|
|
|
|
|
|
|
+ }).catchError((error) {
|
|
|
if (error is ServerErrorException) {
|
|
if (error is ServerErrorException) {
|
|
|
- if (error.code == ErrorCode.noLoginError) {
|
|
|
|
|
|
|
+ if (error.code == ErrorCode.payOrderError) {
|
|
|
|
|
+ refreshMemberData();
|
|
|
|
|
+ ToastUtil.show(error.message);
|
|
|
|
|
+ } else if (error.code == ErrorCode.noLoginError) {
|
|
|
ToastUtil.show(StringName.accountNoLogin);
|
|
ToastUtil.show(StringName.accountNoLogin);
|
|
|
LoginPage.start();
|
|
LoginPage.start();
|
|
|
} else {
|
|
} else {
|
|
|
- ErrorHandler.toastError(error);
|
|
|
|
|
|
|
+ ToastUtil.show(error.message);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- ToastUtil.show(StringName.payError);
|
|
|
|
|
|
|
+ ToastUtil.show(StringName.memberPaymentFailed);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }).whenComplete(() {
|
|
|
|
|
+ LoadingDialog.hide();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _onAliScanPay(String outTradeNo, String qrHtml, PayItemBean paymentWay,
|
|
|
|
|
+ GoodsBean goodsBean) {
|
|
|
|
|
+ AlipayQrCodeDialog.show(
|
|
|
|
|
+ qrCodeHtml: qrHtml,
|
|
|
|
|
+ orderId: outTradeNo,
|
|
|
|
|
+ loadSuccessCallback: () {
|
|
|
|
|
+ checkPaymentStatus(outTradeNo, paymentWay, goodsBean);
|
|
|
|
|
+ },
|
|
|
|
|
+ onCloseCallback: () async {
|
|
|
|
|
+ //关闭后再持续查询几秒
|
|
|
|
|
+ CustomLoadingDialog.show();
|
|
|
|
|
+ await Future.delayed(Duration(seconds: 4));
|
|
|
|
|
+ paymentStatusManager.removePollingSubscription(outTradeNo);
|
|
|
|
|
+ CustomLoadingDialog.hide();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void checkPaymentStatus(
|
|
|
|
|
+ String orderNo, PayItemBean paymentWay, GoodsBean goodsBean,
|
|
|
|
|
+ {String? receiptData}) {
|
|
|
|
|
+ paymentStatusManager.registerPaymentSuccessCallback(orderNo, this);
|
|
|
|
|
+ paymentStatusManager.checkPaymentStatus(orderNo, paymentWay, goodsBean,
|
|
|
|
|
+ receiptData: receiptData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _onWeChatPay(String outTradeNo, String payJson, int payMethod,
|
|
|
|
|
+ GoodsBean buyGoods, PayItemBean buyPayWay) {
|
|
|
|
|
+ final bean = WechatPaymentSignBean.stringToBean(payJson);
|
|
|
|
|
+ final payInfo = WechatPayInfo(
|
|
|
|
|
+ appId: bean.appId,
|
|
|
|
|
+ partnerId: bean.partnerId,
|
|
|
|
|
+ prepayId: bean.prepayId,
|
|
|
|
|
+ package: bean.package,
|
|
|
|
|
+ noncestr: bean.nonceStr,
|
|
|
|
|
+ timestamp: bean.timeStamp,
|
|
|
|
|
+ sign: bean.sign);
|
|
|
|
|
+ requestSdkPay(payInfo, outTradeNo, payMethod, buyGoods, buyPayWay);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _onAliPay(String outTradeNo, String payJson, int payMethod,
|
|
|
|
|
+ GoodsBean buyGoods, PayItemBean buyPayWay) {
|
|
|
|
|
+ final payInfo = AliPayInfo(payJson);
|
|
|
|
|
+ requestSdkPay(payInfo, outTradeNo, payMethod, buyGoods, buyPayWay);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void _onWechatScanPay() {}
|
|
|
|
|
+
|
|
|
|
|
+ void requestSdkPay(dynamic payInfo, String outTradeNo, int payMethod,
|
|
|
|
|
+ GoodsBean buyGoods, PayItemBean buyPayWay) {
|
|
|
|
|
+ AgilePay.startPay(payInfo, success: (String? result) {
|
|
|
|
|
+ LoadingDialog.show(StringName.payQuerypayState);
|
|
|
|
|
+ checkPaymentStatus(outTradeNo, buyPayWay, buyGoods, receiptData: result);
|
|
|
|
|
+ }, payError: (int error, String? errorMessage) {
|
|
|
|
|
+ debugPrint('zk---payError: $error, $errorMessage');
|
|
|
|
|
+ errorPayToast(error);
|
|
|
|
|
+ errorEventReport(payMethod);
|
|
|
|
|
+ }, error: (int errno, String? error) {
|
|
|
|
|
+ debugPrint('zk---error: $errno, $error');
|
|
|
|
|
+ errorPayToast(errno);
|
|
|
|
|
+ errorEventReport(payMethod);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void errorEventReport(int payMethod) {
|
|
void errorEventReport(int payMethod) {
|
|
@@ -334,14 +383,6 @@ class MemberController extends BaseController implements PaymentStatusCallback {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void checkPaymentStatus(
|
|
|
|
|
- String orderNo, PayItemBean paymentWay, GoodsBean goodsBean,
|
|
|
|
|
- {String? receiptData}) {
|
|
|
|
|
- paymentStatusManager.registerPaymentSuccessCallback(orderNo, this);
|
|
|
|
|
- paymentStatusManager.checkPaymentStatus(orderNo, paymentWay, goodsBean,
|
|
|
|
|
- receiptData: receiptData);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@override
|
|
@override
|
|
|
void onClose() {
|
|
void onClose() {
|
|
|
super.onClose();
|
|
super.onClose();
|