Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix related to add credit #67

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/routes/addPinRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ const addPinController=async(req,res)=>{
}
}
const pinVerify=async(req,res)=>{
const {pin}=req.body
const {pin,email}=req.body
try {
const user=await User.findOne({pin:pin})
if(!user) res.status(404).send({success:false,message:'invalid'})
if(user){

if(user.email ===email){
res.status(200).send({success:true,message:'pin verified successfully',email:user.email,id:user._id})
}else{
res.status(404).send({success:false,message:'pin is invalid',})
}
} catch (error) {
console.log(error)
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/loginRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const loginController = async (req, res) => {
if(validUser && validPassword){
const token = jwt.sign({ userId: validUser._id}, process.env.SECRETKEY);

return res.cookie('access_token',token,{httpOnly:true}).status(200).send({token,success:true,message:"signup successfull."})
return res.cookie('access_token',token,{httpOnly:true}).status(200).send({token,id:validUser._id,email:validUser.email,success:true,message:"signup successfull."})
}

} catch (error) {
Expand Down
16 changes: 15 additions & 1 deletion backend/routes/paymentRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const createUser=async(req,res)=>{
res.status(200).send({success:true,message:'create user successfully'})
}
}else{
console.log('created already')

res.send({success:true,message:'already created.'})
}

Expand Down Expand Up @@ -166,7 +168,7 @@ const nexPayment=async(req,res)=>{
payment_method:dataMethod.paymentMethodId,
customer:dataWallet.customerId,
amount:total,
currency:'lkr',
currency:'usd',
confirm:true,
payment_method_types:["card"],

Expand Down Expand Up @@ -212,6 +214,17 @@ const showBalance=async (req,res)=>{
console.log(error)
}
}
const paymentHistory=async(req,res)=>{
const {id}=req.body
try {
const response=await Pay.findOne({userId:id})
if(response){
res.send(response)
}
} catch (error) {
console.log(error)
}
}


router.post('/createuser',createUser)
Expand All @@ -220,4 +233,5 @@ router.post('/carddetails',carddetails)
router.post('/addcredit',addCredit)
router.post('/nexpayment',nexPayment)
router.post('/balance',showBalance)
router.post('/paymenthistory',paymentHistory)
export default router
2 changes: 1 addition & 1 deletion backend/routes/resetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const reset=async(req,res)=>{
}else{
const hashedPassword=bcrypt.hashSync(password,10)
const user=await User.findOneAndUpdate({email},{password:hashedPassword})
return res.status(200).json({success:true,message:"password reset successfully."})
return res.status(200).json({success:true,message:"password reset successfully.",id:user._id})

}
} catch (error) {
Expand Down
Binary file added frontend/src/Assets/topup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions frontend/src/navigation/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ import PinScreen from '../screens/PinScreen';
import AddCredit from '../screens/AddCredit';
import PinVerify from '../screens/PinVerify';
import Created from '../screens/Created';
import MobileTopUp from '../screens/MobileTopUp';
import TopUp from '../screens/TopUp';
import Success from '../screens/Success';
import Verify from '../screens/Verify';
import Rewards from '../screens/Rewards';
import Notification from '../screens/Notification';
import Help from '../screens/Help';
import History from '../screens/History';



Expand Down Expand Up @@ -154,6 +162,14 @@ export default function Navigation() {
<Stack.Screen name="Created" component={Created} />

<Stack.Screen name="AddCredit" component={AddCredit} />
<Stack.Screen name="MobileTopUp" component={MobileTopUp} />
<Stack.Screen name="TopUp" component={TopUp} />
<Stack.Screen name="Success" component={Success} />
<Stack.Screen name="Verify" component={Verify} />
<Stack.Screen name="Rewards" component={Rewards} />
<Stack.Screen name="Notification" component={Notification} />
<Stack.Screen name="Help" component={Help} />
<Stack.Screen name="History" component={History} />

</Stack.Navigator>

Expand Down
10 changes: 6 additions & 4 deletions frontend/src/screens/ForgetPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
View,
TextInput,
} from 'react-native';
import React from 'react';
import React, { useState } from 'react';
import {SafeAreaView} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/FontAwesome';
import COLORS from '../constants/colors';
Expand All @@ -14,8 +14,7 @@ import {useNavigation, useRoute} from '@react-navigation/native';

export default function ForgetPassword() {
const navigation = useNavigation();
const route = useRoute();
const {email} = route.params;
const [email,setEmail]=useState()
return (
<SafeAreaView style={styles.container}>
<View style={styles.header}>
Expand All @@ -32,7 +31,10 @@ export default function ForgetPassword() {
</View>
<View style={styles.inputContainer}>
<Text style={styles.label}>Email</Text>
<TextInput style={styles.input} />
<TextInput style={styles.input}
onChangeText={text => {
setEmail(text);
}} />
</View>
<View style={styles.btnContainer}>
<Button
Expand Down
65 changes: 65 additions & 0 deletions frontend/src/screens/Help.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { SafeAreaView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import React, { useState } from 'react'
import COLORS from '../constants/colors'
import Icon from 'react-native-vector-icons/FontAwesome';
import Img from '../Assets/topup.png';
import { Image } from 'react-native';
import { TextInput } from 'react-native';
import Button from '../components/Button';
import { useNavigation, useRoute } from '@react-navigation/native';
const Help = () => {
const navigation=useNavigation()



return (
<SafeAreaView style={styles.container}>
<View style={styles.header}>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Icon name="chevron-left" size={24} color={COLORS.black} />
</TouchableOpacity>
<Text style={styles.headertitle}>Help</Text>
</View>


<View style={styles.content}>
<Text style={styles.contentText}>Still developing with contact details and FAQs</Text>
</View>

</SafeAreaView>
)
}

export default Help

const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal: 28,
},
header: {
flexDirection: 'row',
margin:25,
alignItems: 'flex-end',
justifyContent: 'center',
},
headertitle: {
color: COLORS.black,

width:150,
fontSize: 18,
fontWeight: '600',
marginHorizontal: '35%',
},

content:{
marginTop:250,
},
contentText:{
color:COLORS.low_grey,
fontWeight:'600',
textAlign:'center',
fontSize:20
},

})
119 changes: 119 additions & 0 deletions frontend/src/screens/History.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { SafeAreaView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import React, { useEffect, useState } from 'react'
import COLORS from '../constants/colors'
import Icon from 'react-native-vector-icons/FontAwesome';
import Img from '../Assets/topup.png';
import { Image } from 'react-native';
import { TextInput } from 'react-native';
import Button from '../components/Button';
import { useNavigation, useRoute } from '@react-navigation/native';
import { FlatList } from 'react-native';
import { URL } from '../constants/URL';
import axios from 'axios';
const History = () => {
const navigation=useNavigation()
const route=useRoute()
const {id}=route.params
const [history, setHistory] = useState(null);
useEffect(()=>{
const fetchHistory=async ()=>{
try {
const response = await axios.post(`${URL}/api/paymenthistory`, {
id: id,
});
if (response) {
setHistory(response.data.payments)

}
} catch (error) {
console.log(error);

}
}
fetchHistory()

},[])

const renderItem = ({ item }) => {
const date = new Date(item.created * 1000);

// Format the date and time
const formattedDateTime = date.toLocaleString();
return(<View>
<View style={styles.tile}>
<Text style={styles.renderText}>{item.type}</Text>
<Text style={styles.renderText}>{`Rs.${item.amount}.00`}</Text>
<Text style={styles.renderText}>{formattedDateTime}</Text>
</View>

</View>)
};


return (
<SafeAreaView style={styles.container}>
<View style={styles.header}>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Icon name="chevron-left" size={24} color={COLORS.black} />
</TouchableOpacity>
<Text style={styles.headertitle}>History</Text>
</View>


<View style={styles.content}>

<FlatList
data={history}
renderItem={renderItem}
keyExtractor={item => item.paymentIntentId}
/>

</View>

</SafeAreaView>
)
}

export default History

const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal: 28,
},
header: {
flexDirection: 'row',
margin:25,
alignItems: 'flex-end',
justifyContent: 'center',
},
headertitle: {
color: COLORS.black,

width:150,
fontSize: 18,
fontWeight: '600',
marginHorizontal: '35%',
},
content:{

alignItems:'center',
justifyContent:'center'
},
contentText:{
color:COLORS.low_grey,
fontWeight:'600',
textAlign:'center',
fontSize:20
},
tile:{
flexDirection:'row',
padding:10,
justifyContent: 'space-between',

},
renderText:{
fontWeight:'600'
}

})
Loading