Skip to content

Commit eb64033

Browse files
committed
fix: fix UPI/card payment - use relative API URL with Vercel proxy
1 parent ab5a65c commit eb64033

8 files changed

Lines changed: 45 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
runs-on: ubuntu-latest
6060
needs: backend
6161
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
62+
continue-on-error: true
63+
continue-on-error: true
6264

6365
steps:
6466
- uses: actions/checkout@v3

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Built with a modern MERN stack on the backend and React + React Native on the fr
77
## Live Demo
88

99
- **Website:** [zappify-sepia.vercel.app](https://zappify-sepia.vercel.app)
10-
- **Download APK:** [Zappify Android App](https://expo.dev/accounts/devendra.mi/projects/zappify/builds/24237286-1ff7-4219-ac7a-6c103ff28d00)
10+
- **Download APK:** [Zappify Android App](https://expo.dev/accounts/devendra.mi/projects/zappify/builds/29e30585-c692-470b-b195-fd7af1822eb2)
11+
- **Preview App:** [Preview App](https://drive.google.com/file/d/1IDo1ueM5tcDFiFk4r-4q5vFa-vUeZcyl/view)
1112

1213
---
1314

frontend/src/components/Checkout.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ const Checkout = ({ cartItems, onClose, onOrderPlaced }) => {
3636
const loaded = await loadRazorpayScript();
3737
if (!loaded) { alert('Razorpay failed to load. Check your internet.'); return; }
3838

39+
const apiBase = import.meta.env.VITE_API_URL || '';
40+
3941
try {
40-
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/payment/create-order`, {
42+
const res = await fetch(`${apiBase}/api/payment/create-order`, {
4143
method: 'POST',
4244
headers: { 'Content-Type': 'application/json' },
4345
body: JSON.stringify({ amount: totalAmount }),
4446
});
45-
const data = await res.json();
47+
48+
if (!res.ok) {
49+
const errText = await res.text();
50+
throw new Error(`Server error ${res.status}: ${errText || 'No response from server'}`);
51+
}
52+
53+
const text = await res.text();
54+
if (!text) throw new Error('Empty response from payment server. Make sure the backend is running and VITE_API_URL is set correctly.');
55+
const data = JSON.parse(text);
4656

4757
const options = {
4858
key: import.meta.env.VITE_RAZORPAY_KEY_ID,
@@ -52,12 +62,14 @@ const Checkout = ({ cartItems, onClose, onOrderPlaced }) => {
5262
description: 'Shoe Purchase',
5363
order_id: data.orderId,
5464
handler: async (response) => {
55-
const verifyRes = await fetch(`${import.meta.env.VITE_API_URL}/api/payment/verify`, {
65+
const verifyRes = await fetch(`${apiBase}/api/payment/verify`, {
5666
method: 'POST',
5767
headers: { 'Content-Type': 'application/json' },
5868
body: JSON.stringify(response),
5969
});
60-
const verifyData = await verifyRes.json();
70+
const verifyText = await verifyRes.text();
71+
if (!verifyText) { alert('Payment verification failed: empty response from server.'); return; }
72+
const verifyData = JSON.parse(verifyText);
6173
if (verifyData.success) {
6274
if (onOrderPlaced) onOrderPlaced(cartItems);
6375
setOrderPlaced(true);

frontend/vercel.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{ "source": "/preview", "destination": "/", "permanent": true }
44
],
55
"rewrites": [
6+
{ "source": "/api/:path*", "destination": "https://zappify-dz5a.vercel.app/api/:path*" },
67
{ "source": "/(.*)", "destination": "/index.html" }
78
]
89
}

mobile/App.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ export default function App() {
4848

4949
if (showSplash) {
5050
return (
51-
<View style={{ flex: 1, backgroundColor: '#FF3D00' }}>
52-
<StatusBar backgroundColor="#FF3D00" barStyle="light-content" />
51+
<View style={{ flex: 1, backgroundColor: '#000000' }}>
52+
<StatusBar backgroundColor="#000000" barStyle="light-content" />
5353
<Animated.View style={[styles.splashContainer, { opacity: fadeAnim }]}>
5454
<Animated.View style={{ transform: [{ scale: scaleAnim }], alignItems: 'center' }}>
55-
<Image source={require('./assets/logo.png')} style={styles.splashLogoImg} />
56-
<Text style={styles.splashSubtitle}>Premium Shoe Store</Text>
55+
<Image source={require('./assets/logo1.png')} style={styles.splashLogoImg} />
5756
</Animated.View>
5857
</Animated.View>
5958
</View>
@@ -82,13 +81,13 @@ export default function App() {
8281
const styles = StyleSheet.create({
8382
splashContainer: {
8483
flex: 1,
85-
backgroundColor: '#FF3D00',
84+
backgroundColor: '#000000',
8685
justifyContent: 'center',
8786
alignItems: 'center',
8887
},
8988
splashLogoImg: {
90-
width: 280,
91-
height: 280,
89+
width: 380,
90+
height: 220,
9291
resizeMode: 'contain',
9392
},
9493
splashSubtitle: {
@@ -98,7 +97,7 @@ const styles = StyleSheet.create({
9897
textTransform: 'uppercase',
9998
letterSpacing: 6,
10099
textAlign: 'center',
101-
marginTop: 8,
100+
marginTop: 16,
102101
fontWeight: '700',
103102
},
104103
});

mobile/app.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"slug": "zappify",
55
"version": "1.0.0",
66
"orientation": "portrait",
7-
"icon": "./assets/logo.png",
7+
"icon": "./assets/logo1.png",
88
"userInterfaceStyle": "light",
99
"newArchEnabled": true,
1010
"updates": {
@@ -16,9 +16,9 @@
1616
"policy": "appVersion"
1717
},
1818
"splash": {
19-
"image": "./assets/logo.png",
19+
"image": "./assets/logo1.png",
2020
"resizeMode": "contain",
21-
"backgroundColor": "#FF3D00"
21+
"backgroundColor": "#000000"
2222
},
2323
"ios": {
2424
"supportsTablet": true,
@@ -29,8 +29,8 @@
2929
},
3030
"android": {
3131
"adaptiveIcon": {
32-
"foregroundImage": "./assets/logo.png",
33-
"backgroundColor": "#FF3D00"
32+
"foregroundImage": "./assets/logo1.png",
33+
"backgroundColor": "#000000"
3434
},
3535
"package": "com.zappify.app",
3636
"edgeToEdgeEnabled": true

mobile/assets/logo1.png

35.9 KB
Loading

mobile/src/screens/CheckoutScreen.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { SafeAreaView } from 'react-native-safe-area-context';
44
import { Ionicons } from '@expo/vector-icons';
55
import { colors } from '../theme/colors';
66
import { useApp } from '../context/AppContext';
7-
import RazorpayCheckout from 'react-native-razorpay';
7+
8+
let RazorpayCheckout = null;
9+
try {
10+
RazorpayCheckout = require('react-native-razorpay').default;
11+
} catch (e) {
12+
RazorpayCheckout = null;
13+
}
814

915
const API_URL = 'https://zappify-dz5a.vercel.app';
1016
const RAZORPAY_KEY_ID = 'rzp_test_SZtLthHdKYuLeQ';
@@ -30,6 +36,11 @@ export default function CheckoutScreen({ navigation }) {
3036
setDone(true);
3137
return;
3238
}
39+
if (!RazorpayCheckout) {
40+
Alert.alert('Not Available', 'Payment via card/UPI requires the full app build. Please use Cash on Delivery.');
41+
return;
42+
}
43+
3344
try {
3445
const res = await fetch(`${API_URL}/api/payment/create-order`, {
3546
method: 'POST',

0 commit comments

Comments
 (0)