zbb 3 mesiacov pred
rodič
commit
1680ad8524

+ 2 - 1
app.json

@@ -38,7 +38,8 @@
             "backgroundColor": "#000000"
           }
         }
-      ]
+      ],
+      "expo-native-alipay"
     ],
     "experiments": {
       "typedRoutes": true,

+ 39 - 3
app/award-detail/components/CheckoutModal.tsx

@@ -154,10 +154,45 @@ export const CheckoutModal = forwardRef<CheckoutModalRef, CheckoutModalProps>(
 
       setLoading(true);
       try {
-        const paymentType = 'WALLET';
+        let paymentType = '';
+        
+        // Prioritize Wallet if checked
+        if (cashChecked) {
+            paymentType = 'WALLET';
+        } else {
+             // Default to Alipay for now as per branch logic
+             paymentType = 'ALIPAY_APP';
+        }
+        
+        // If wallet is insufficient and logic requires mixed payment, it might be more complex
+        // strictly following branch logic: if cashChecked use Wallet, else Alipay
+
         const payNum = packFlag ? 1 : num;
 
         const res = await applyOrder(poolId, payNum, paymentType, boxNum, seatNumbers, packFlag);
+        
+        // Handle Alipay Response
+        if (res?.payInfo) {
+             const result = await Alipay.pay(res.payInfo);
+             console.log('Alipay Result:', result);
+             const resultStatus = result?.resultStatus;
+             
+             if (resultStatus === '9000') {
+                 // Payment Success
+                 // Maybe verify payment here if needed, or just assume success
+                 const tradeNo = res.bizTradeNo || res.tradeNo; // Assuming tradeNo is in applyOrder response
+                 
+                 setVisible(false);
+                 router.push({
+                    pathname: '/lottery' as any,
+                    params: { tradeNo, num, poolId }
+                 });
+                 onSuccess({ tradeNo, num });
+             } else {
+                 Alert.alert('提示', '支付未完成');
+             }
+             return;
+        }
 
         if (res?.paySuccess || res?.bizTradeNo || res?.tradeNo) {
           const tradeNo = res.bizTradeNo || res.tradeNo;
@@ -175,6 +210,7 @@ export const CheckoutModal = forwardRef<CheckoutModalRef, CheckoutModalProps>(
           Alert.alert('提示', res?.message || '支付失败,请重试');
         }
       } catch (error: any) {
+        console.error('Pay error:', error);
         Alert.alert('支付失败', error?.message || '请稍后重试');
       } finally {
         setLoading(false);
@@ -203,7 +239,7 @@ export const CheckoutModal = forwardRef<CheckoutModalRef, CheckoutModalProps>(
           } else {
             setResultLoading(false);
             if (typeof window !== 'undefined') {
-              window.alert('获取结果超时,请在仓库中查看');
+              Alert.alert('提示', '获取结果超时,请在仓库中查看');
             }
           }
         } catch {
@@ -213,7 +249,7 @@ export const CheckoutModal = forwardRef<CheckoutModalRef, CheckoutModalProps>(
           } else {
             setResultLoading(false);
             if (typeof window !== 'undefined') {
-              window.alert('获取结果失败,请在仓库中查看');
+              Alert.alert('提示', '获取结果失败,请在仓库中查看');
             }
           }
         }

+ 1 - 0
package.json

@@ -25,6 +25,7 @@
     "expo-image": "~3.0.11",
     "expo-image-picker": "~17.0.10",
     "expo-linking": "~8.0.11",
+    "expo-native-alipay": "^0.1.1",
     "expo-router": "~6.0.21",
     "expo-splash-screen": "~31.0.13",
     "expo-status-bar": "~3.0.9",

+ 67 - 0
plugins/withAlipay.js

@@ -0,0 +1,67 @@
+const { withInfoPlist, withAndroidManifest } = require('expo/config-plugins');
+
+/**
+ * Local Expo Config Plugin for @uiw/react-native-alipay
+ * Configures iOS URL Schemes and Android queries for Alipay SDK
+ */
+const withAlipay = (config, { alipayScheme = 'alipay' } = {}) => {
+  // iOS: Add URL Scheme for Alipay callback
+  config = withInfoPlist(config, (config) => {
+    if (!config.modResults.CFBundleURLTypes) {
+      config.modResults.CFBundleURLTypes = [];
+    }
+
+    // Check if alipay scheme already exists
+    const existingScheme = config.modResults.CFBundleURLTypes.find(
+      (urlType) => urlType.CFBundleURLSchemes && urlType.CFBundleURLSchemes.includes(alipayScheme)
+    );
+
+    if (!existingScheme) {
+      config.modResults.CFBundleURLTypes.push({
+        CFBundleURLName: 'alipay',
+        CFBundleURLSchemes: [alipayScheme],
+      });
+    }
+
+    // Add LSApplicationQueriesSchemes for Alipay
+    if (!config.modResults.LSApplicationQueriesSchemes) {
+      config.modResults.LSApplicationQueriesSchemes = [];
+    }
+
+    const alipaySchemes = ['alipay', 'alipays', 'alipayshare'];
+    alipaySchemes.forEach((scheme) => {
+      if (!config.modResults.LSApplicationQueriesSchemes.includes(scheme)) {
+        config.modResults.LSApplicationQueriesSchemes.push(scheme);
+      }
+    });
+
+    return config;
+  });
+
+  // Android: Add queries for Alipay package
+  config = withAndroidManifest(config, (config) => {
+    const manifest = config.modResults.manifest;
+
+    if (!manifest.queries) {
+      manifest.queries = [];
+    }
+
+    // Add package query for Alipay
+    const alipayPackage = { package: [{ $: { 'android:name': 'com.eg.android.AlipayGphone' } }] };
+    
+    // Check if already exists
+    const hasAlipayQuery = manifest.queries.some(
+      (q) => q.package && q.package.some((p) => p.$ && p.$['android:name'] === 'com.eg.android.AlipayGphone')
+    );
+
+    if (!hasAlipayQuery) {
+      manifest.queries.push(alipayPackage);
+    }
+
+    return config;
+  });
+
+  return config;
+};
+
+module.exports = withAlipay;