|
|
|
import 'package:doublefeel_flutter/app/utils/platform_compact.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/network/api/pay_api.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/network/api/vip_api.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/result/app_result.dart';
|
|
...
|
...
|
@@ -22,41 +23,84 @@ class MembershipOfferController extends GetxController { |
|
|
|
final UserPreferencesStorage _userPreferences =
|
|
|
|
Get.find<UserPreferencesStorage>();
|
|
|
|
final AppPlatformHostApi _platformHostApi = AppPlatformHostApi();
|
|
|
|
final AlipayHostApi _alipayHostApi = AlipayHostApi();
|
|
|
|
|
|
|
|
final isUnlocking = false.obs;
|
|
|
|
Future<void> unlock() async {
|
|
|
|
if (isUnlocking.value) return;
|
|
|
|
|
|
|
|
final productId = yearlyProduct.value?.id;
|
|
|
|
final appleProductId = yearlyProduct.value?.appleId;
|
|
|
|
if (productId == null || appleProductId == null || appleProductId.isEmpty) {
|
|
|
|
AppToast.show(l10n.purchaseProductInfoUnavailable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isUnlocking.value = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final orderResult = await _payApi.createOrderByApple(productId);
|
|
|
|
if (orderResult is! AppSuccess<ApplePayOrderResponse>) {
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
if (isOhos()) {
|
|
|
|
if (productId == null) {
|
|
|
|
AppToast.show(l10n.purchaseProductInfoUnavailable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isUnlocking.value = true;
|
|
|
|
final orderResult = await _payApi.createCustomOrder(
|
|
|
|
productId: productId,
|
|
|
|
paymentChannel: PaymentChannel.alipay.value,
|
|
|
|
productChannel: ProductChannel.huawei.value,
|
|
|
|
);
|
|
|
|
if (orderResult is! AppSuccess<ApplePayOrderResponse>) {
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final orderUuid = orderResult.data.orderInfo?.orderUuid?.trim();
|
|
|
|
if (orderUuid == null || orderUuid.isEmpty) {
|
|
|
|
AppToast.show(l10n.purchaseOrderInfoUnavailable);
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
final prepayData = orderResult.data.prepayData?.trim();
|
|
|
|
if (prepayData == null || prepayData.isEmpty) {
|
|
|
|
AppToast.show(l10n.purchaseOrderInfoUnavailable);
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final paymentResult = await _performApplePayment(
|
|
|
|
productId: appleProductId,
|
|
|
|
orderUuid: orderUuid,
|
|
|
|
);
|
|
|
|
await _handleApplePaymentResult(paymentResult);
|
|
|
|
//todo 鸿蒙Alipay prepayData
|
|
|
|
final result = await _alipayHostApi.launchAliPay(prepayData);
|
|
|
|
if (result == AliPayResultCode.success) {
|
|
|
|
_trackSuccessPayOrder();
|
|
|
|
await _completeSuccessfulPurchase();
|
|
|
|
} else if (result == AliPayResultCode.error) {
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (isIOS()) {
|
|
|
|
final appleProductId = yearlyProduct.value?.appleId;
|
|
|
|
if (productId == null ||
|
|
|
|
appleProductId == null ||
|
|
|
|
appleProductId.isEmpty) {
|
|
|
|
AppToast.show(l10n.purchaseProductInfoUnavailable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isUnlocking.value = true;
|
|
|
|
final orderResult = await _payApi.createOrderByApple(productId);
|
|
|
|
if (orderResult is! AppSuccess<ApplePayOrderResponse>) {
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final orderUuid = orderResult.data.orderInfo?.orderUuid?.trim();
|
|
|
|
if (orderUuid == null || orderUuid.isEmpty) {
|
|
|
|
AppToast.show(l10n.purchaseOrderInfoUnavailable);
|
|
|
|
if (isFromOnboard) {
|
|
|
|
Get.offAllNamed(AppRoutes.home, arguments: {'isFromOnboard': true});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final paymentResult = await _performApplePayment(
|
|
|
|
productId: appleProductId,
|
|
|
|
orderUuid: orderUuid,
|
|
|
|
);
|
|
|
|
await _handleApplePaymentResult(paymentResult);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
isUnlocking.value = false;
|
|
|
|
}
|
|
...
|
...
|
@@ -87,13 +131,16 @@ class MembershipOfferController extends GetxController { |
|
|
|
}
|
|
|
|
trackMap['product_type'] = yearlyProduct.value?.appleId;
|
|
|
|
trackMap['price'] = yearlyProduct.value?.price;
|
|
|
|
|
|
|
|
final appleInfo = yearlyProductAppleInfo.value;
|
|
|
|
trackMap['currency_code'] = appleInfo?.currencyCode ?? '';
|
|
|
|
|
|
|
|
var actualPrice = appleInfo?.price ?? 0;
|
|
|
|
trackMap['actual_price'] =
|
|
|
|
actualPrice > 0 ? actualPrice : (appleInfo?.originPrice ?? 0);
|
|
|
|
if (isOhos()) {
|
|
|
|
trackMap['currency_code'] = 'CN';
|
|
|
|
trackMap['actual_price'] = yearlyProduct.value?.price;
|
|
|
|
} else if (isIOS()) {
|
|
|
|
final appleInfo = yearlyProductAppleInfo.value;
|
|
|
|
trackMap['currency_code'] = appleInfo?.currencyCode ?? '';
|
|
|
|
var actualPrice = appleInfo?.price ?? 0;
|
|
|
|
trackMap['actual_price'] =
|
|
|
|
actualPrice > 0 ? actualPrice : (appleInfo?.originPrice ?? 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ta.track(
|
|
|
|
'success_doublefeel_pay_order',
|
|
...
|
...
|
@@ -192,19 +239,24 @@ class MembershipOfferController extends GetxController { |
|
|
|
final result = await _payApi.getProductList();
|
|
|
|
if (result is! AppSuccess<PayProductListResponse>) return;
|
|
|
|
|
|
|
|
final products = (result.data.productList ?? const <PayProduct>[])
|
|
|
|
.where((product) => _nonEmpty(product.appleId) != null)
|
|
|
|
.toList();
|
|
|
|
yearlyProduct.value =
|
|
|
|
products.firstWhereOrNull((p) => p.content?.isDiscountOffer == 1);
|
|
|
|
|
|
|
|
if (yearlyProduct.value != null) {
|
|
|
|
final appleProductId = _nonEmpty(yearlyProduct.value!.appleId);
|
|
|
|
if (appleProductId == null) return;
|
|
|
|
|
|
|
|
yearlyProductAppleInfo.value = await _requestAppleProductInfo(
|
|
|
|
productId: appleProductId,
|
|
|
|
baseUnit: yearlyProduct.value!.content?.baseUnit() ?? 1);
|
|
|
|
if (isIOS()) {
|
|
|
|
final products = (result.data.productList ?? const <PayProduct>[])
|
|
|
|
.where((product) => _nonEmpty(product.appleId) != null)
|
|
|
|
.toList();
|
|
|
|
yearlyProduct.value =
|
|
|
|
products.firstWhereOrNull((p) => p.content?.isDiscountOffer == 1);
|
|
|
|
if (yearlyProduct.value != null) {
|
|
|
|
final appleProductId = _nonEmpty(yearlyProduct.value!.appleId);
|
|
|
|
if (appleProductId == null) return;
|
|
|
|
|
|
|
|
yearlyProductAppleInfo.value = await _requestAppleProductInfo(
|
|
|
|
productId: appleProductId,
|
|
|
|
baseUnit: yearlyProduct.value!.content?.baseUnit() ?? 1);
|
|
|
|
}
|
|
|
|
} else if (isOhos()) {
|
|
|
|
final products = (result.data.productList ?? const <PayProduct>[]);
|
|
|
|
yearlyProduct.value =
|
|
|
|
products.firstWhereOrNull((p) => p.content?.isDiscountOffer == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|