|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import Alipay from 'expo-native-alipay';
|
|
|
import { Stack, useRouter } from 'expo-router';
|
|
import { Stack, useRouter } from 'expo-router';
|
|
|
import React, { useState } from 'react';
|
|
import React, { useState } from 'react';
|
|
|
import { ActivityIndicator, Alert, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
import { ActivityIndicator, Alert, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
@@ -31,34 +32,32 @@ export default function RechargeScreen() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ setLoading(true);
|
|
|
setLoading(true);
|
|
setLoading(true);
|
|
|
try {
|
|
try {
|
|
|
- // Uniapp logic: generatePaymentLink -> tradeNo
|
|
|
|
|
- const res = await services.wallet.generatePaymentLink(amount, 'ALIPAY_H5', 'CASH');
|
|
|
|
|
|
|
+ // Use ALIPAY_APP for native payment with correct API
|
|
|
|
|
+ const res: any = await services.wallet.rechargeSubmit(amount, 'ALIPAY_APP', 'CASH');
|
|
|
|
|
|
|
|
- if (res && res.data && res.data.tradeNo) {
|
|
|
|
|
- const tradeNo = res.data.tradeNo;
|
|
|
|
|
- Alert.alert(
|
|
|
|
|
- '提示',
|
|
|
|
|
- '已生成充值订单,请完成支付',
|
|
|
|
|
- [
|
|
|
|
|
- {
|
|
|
|
|
- text: '已支付',
|
|
|
|
|
- onPress: async () => {
|
|
|
|
|
- const checkRes = await services.wallet.checkPaymentStatus({ tradeNo: tradeNo });
|
|
|
|
|
- if (checkRes && checkRes.code === 0 && checkRes.data.paySuccess) {
|
|
|
|
|
- Alert.alert('提示', '支付成功');
|
|
|
|
|
- router.replace('/wallet/recharge_record');
|
|
|
|
|
- } else {
|
|
|
|
|
- Alert.alert('提示', checkRes.msg || '支付未完成或查询失败');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- { text: '稍后支付' }
|
|
|
|
|
- ]
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ console.log('Recharge API Res:', res);
|
|
|
|
|
+
|
|
|
|
|
+ // Handle response which might be direct string or object with payInfo
|
|
|
|
|
+ const payInfo = typeof res?.data === 'string' ? res?.data : (res?.data?.payInfo || res?.data?.orderInfo || res?.data?.tradeNo);
|
|
|
|
|
+
|
|
|
|
|
+ if (payInfo && typeof payInfo === 'string' && (payInfo.startsWith('alipay_root_cert_sn') || payInfo.includes('alipay_sdk'))) {
|
|
|
|
|
+ Alipay.setAlipayScheme('alipay2021005175632205');
|
|
|
|
|
+ const result = await Alipay.pay(payInfo);
|
|
|
|
|
+ console.log('Alipay Result:', result);
|
|
|
|
|
+
|
|
|
|
|
+ if (result?.resultStatus === '9000') {
|
|
|
|
|
+ Alert.alert('提示', '充值成功');
|
|
|
|
|
+ router.replace('/wallet/recharge_record');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Alert.alert('提示', '支付未完成');
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (res?.data?.tradeNo && !payInfo) {
|
|
|
|
|
+ Alert.alert('提示', '获取支付信息失败(仅获取到订单号)');
|
|
|
} else {
|
|
} else {
|
|
|
- Alert.alert('失败', '生成充值订单失败');
|
|
|
|
|
|
|
+ Alert.alert('失败', '生成充值订单失败 ' + (res?.msg || ''));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|