Guest User

Untitled

a guest
Aug 3rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.82 KB | None | 0 0
  1. import React,{ Component } from 'react';
  2. import OfflineNotice from './OfflineNotice';
  3. import axios from 'axios';
  4. import { SafeAreaView, View, Text, StyleSheet, StatusBar, AsyncStorage,
  5. TouchableHighlight,
  6. NativeModules,
  7. NativeEventEmitter,
  8. Alert } from 'react-native';
  9. import base from '../firebaseConfig';
  10. import { Container, Content, Card, CardItem, Header, Item, Left, Right, Body, Button, Icon, Input, Image, List, ListItem, Footer, Tabs, Tab, TabHeading, Form, Label, Radio} from 'native-base';
  11. import RazorpayCheckout from 'react-native-razorpay';
  12. import MapView from 'react-native-maps';
  13.  
  14. var hour = new Date().getHours();
  15. //var hour = 12.46;
  16. var fuckkk = null;
  17. var payId = null;
  18. var move;
  19. var orderKey;
  20.  
  21. class PaymentMode extends Component {
  22. constructor(props) {
  23. super(props);
  24.  
  25. var date = new Date().getDate();
  26. var month = new Date().getMonth() + 1;
  27. var year = new Date().getFullYear();
  28. move = props.navigation;
  29.  
  30. this.state = {
  31. dt : {},
  32. date : date + '/' + month + '/' + year,
  33. latitude: null,
  34. longitude: null,
  35. showCOD : 'flex',
  36. showCardOD : 'flex',
  37. ts122 : 'none',
  38. ts24 : 'none',
  39. ts46 : 'none',
  40. ts69 : 'none',
  41. pm1:false,
  42. pm2:false,
  43. pm3:false,
  44. pm4:false,
  45. error:null,
  46. one : false,
  47. two : false,
  48. three : false,
  49. four : false,
  50. nextDay : '',
  51. deliveryTiming : null,
  52. total : 0,
  53. totalItems : 0,
  54. showPM : 'none'
  55. };
  56.  
  57.  
  58. }
  59.  
  60. _sendMsg = (oid) => {
  61. axios.get('http://smst.inroys.in/vendorsms/pushsms.aspx?user=liquor_cart&password=jaipur4321&msisdn=91' + this.state.dt.mobile +'&sid=LQRCRT&msg=Thankyou '+ this.state.dt.name + ', Your Order No '+oid+' has been Confirmed will be delivered shortly.'+'&fl=0&gwid=2' )
  62. .then(function (response) {
  63. //alert('msg send')
  64. console.log('send');
  65. })
  66. .catch(function (error) {
  67. //alert('msg not send')
  68. console.log(error);
  69. });
  70. }
  71.  
  72. _onlinePayment = (tp) => {
  73. var that = this;
  74. var options = {
  75. description: 'Liquor Order Payment',
  76. image: 'https://image.ibb.co/dRfzk8/pp_Cropped.jpg',
  77. currency: 'INR',
  78. key: 'rzp_test_W95b9b1G4Voj1E',
  79. amount: tp*100,
  80. name: 'Liquorcart',
  81. prefill: {
  82. email: '',
  83. contact: this.state.dt.mobile,
  84. name: this.state.dt.name
  85. },
  86. theme: { color: '#000' }
  87. }
  88.  
  89. RazorpayCheckout.open(options).then((data) => {
  90. // handle success
  91. payId = data.razorpay_payment_id;
  92. // console.log(move)
  93. // console.log(payId)
  94. // alert(`Success: ${data.razorpay_payment_id}`);
  95. orderKey = base.push('liquorOrders', {
  96. data: {
  97. userid: this.state.userKey,
  98. date: this.state.date,
  99. amount: tp,
  100. totalItems: this.state.totalItems,
  101. status: 'Confirmed',
  102. userCords: this.state.dt.address.userCords,
  103. deliveryPerson: 'mobileNo',
  104. item: this.state.dt.cart,
  105. address: this.state.dt.address,
  106. name: this.state.dt.name,
  107. mobile: this.state.dt.mobile,
  108. deliveryTiming: this.state.deliveryTiming,
  109. paymentMode: 'Online',
  110. razorpayId: payId
  111. },
  112. then(err) {
  113. if (!err) {
  114. base.remove('/users/' + fuckkk + '/cart');
  115. that._sendMsg(orderKey.key.substring(14, ));
  116. move.navigate('orderSuccess');
  117. }
  118. }
  119. });
  120.  
  121. }).catch((error) => {
  122. // handle failure
  123. alert(` ${error.description}`);
  124. move.navigate('orderError');
  125. });
  126. RazorpayCheckout.onExternalWalletSelection(data => {
  127. alert(`External Wallet Selected: ${data.external_wallet} `);
  128. });
  129. }
  130.  
  131. componentWillMount(){
  132.  
  133. AsyncStorage.getItem("userKey").then((value) => {
  134. fuckkk = value
  135. this.setState({ userKey: value });
  136. console.log('sdf' + this.state.userKey)
  137. console.log('ga' + fuckkk)
  138.  
  139. base.bindToState('users/' + this.state.userKey, {
  140. context: this,
  141. asArray: false,
  142. state: 'dt'
  143. })
  144.  
  145. }).done();
  146.  
  147.  
  148. // if (hour >= 16) {
  149. // this.setState({
  150. // showCOD: 'none',
  151. // })
  152. // }
  153.  
  154. // if (hour >= 18) {
  155. // this.setState({
  156. // showCardOD: 'none',
  157. // })
  158. // }
  159.  
  160. // if (hour >= 20) {
  161. // this.setState({
  162. // showCardOD: 'flex',
  163. // showCOD: 'flex',
  164. // })
  165. // }
  166.  
  167.  
  168. ///time slot BC
  169.  
  170.  
  171. if(hour < 12 ){
  172. console.log(hour < 12 );
  173.  
  174. this.setState({
  175. ts122: 'flex',
  176. ts24: 'flex',
  177. ts46: 'flex',
  178. ts69: 'flex',
  179. nextDay: '',
  180. })
  181.  
  182. }else if( hour > 12 && hour < 14){
  183.  
  184. console.log(hour > 12 && hour < 14);
  185. this.setState({
  186. ts122: 'none',
  187. ts24: 'flex',
  188. ts46: 'flex',
  189. ts69: 'flex',
  190. nextDay: '',
  191. })
  192.  
  193. }else if( hour >= 14 && hour < 16){
  194.  
  195. console.log(hour > 14 && hour < 16);
  196. this.setState({
  197. ts122: 'none',
  198. ts24: 'none',
  199. ts46: 'flex',
  200. ts69: 'flex',
  201. nextDay: '',
  202. })
  203.  
  204. }else if( hour >= 16 && hour < 18){
  205.  
  206. console.log(hour > 16 && hour < 18);
  207. this.setState({
  208. ts122: 'none',
  209. ts24: 'none',
  210. ts46: 'none',
  211. ts69: 'flex',
  212. nextDay: '',
  213. })
  214.  
  215. }else if( hour >= 18){
  216.  
  217. this.setState({
  218. nextDay: 'TOMORROW',
  219. ts122: 'flex',
  220. ts24: 'flex',
  221. ts46: 'flex',
  222. ts69: 'flex',
  223. })
  224.  
  225. }
  226.  
  227.  
  228. }
  229.  
  230. componentDidMount() {
  231.  
  232. // navigator.geolocation.getCurrentPosition(
  233. // (position) => {
  234. // console.log(position);
  235. // this.setState({
  236. // latitude: position.coords.latitude,
  237. // longitude: position.coords.longitude,
  238. // error: null,
  239. // });
  240. // },
  241. // (error) => this.setState({ error: error.message }),
  242. // { enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
  243. // );
  244.  
  245.  
  246. }
  247.  
  248.  
  249. componentDidUpdate(prevProps, prevState){
  250. var hola = 0;
  251. var bhola = 0;
  252. if(prevState.dt.name !== this.state.dt.name){
  253. _.each(this.state.dt.cart, (val, key) => {
  254. hola = hola + (val.price * val.orderQty)
  255. bhola = bhola + parseInt(val.orderQty)
  256. })
  257.  
  258. this.setState({
  259. total: hola,
  260. totalItems: bhola,
  261. })
  262. }
  263.  
  264. if( hour != new Date().getHours()){
  265. hour = new Date().getHours();
  266. }
  267. }
  268.  
  269.  
  270. render() {
  271.  
  272. return (
  273. <SafeAreaView style={{flex:1,backgroundColor:'#000'}}>
  274. <Container style={{backgroundColor:'#fff'}}>
  275. <OfflineNotice />
  276. <StatusBar hidden={true} />
  277. <Header style={styles.header}>
  278. <Left>
  279. <Button onPress={() => this.props.navigation.goBack()} style={{backgroundColor:'transparent',marginLeft:-20}} >
  280. <Icon type='Ionicons' name='md-arrow-back' style={{color:'#fff',fontSize:32}} />
  281. </Button>
  282. </Left>
  283. <Body>
  284. </Body>
  285. <Right>
  286.  
  287. </Right>
  288. </Header>
  289. <ListItem itemDivider>
  290. <Text style={{ fontFamily: 'EncodeSansCondensed-Bold', fontSize: 15, color: '#000' }}>CHOOSE {this.state.nextDay} DELIVERY TIMING </Text>
  291. </ListItem>
  292.  
  293.  
  294. <ListItem onPress={ () => {
  295. this.setState({
  296. one : true,
  297. two : false,
  298. three : false,
  299. four : false,
  300. deliveryTiming : '12:00NOON--2:00PM',
  301. showPM : 'flex',
  302. showCardOD: 'flex',
  303. showCOD: 'flex',
  304. })
  305. }} style={{ display: this.state.ts122 }}>
  306. <Left>
  307. <Radio selected={this.state.one} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  308. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'12:00NOON to 02:00PM '}</Text>
  309. </Left>
  310. </ListItem>
  311.  
  312. <ListItem onPress={() => {
  313. this.setState({
  314. two: true,
  315. one : false,
  316. three : false,
  317. four: false,
  318. deliveryTiming: '2:00PM--4:00PM',
  319. showPM : 'flex',
  320. showCardOD: 'flex',
  321. showCOD: 'flex',
  322. })
  323. }} style={{ display: this.state.ts46 }}>
  324. <Left>
  325. <Radio selected={this.state.two} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  326. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'2:00 PM to 4:00PM '}</Text>
  327. </Left>
  328. </ListItem>
  329.  
  330. <ListItem onPress={() => {
  331. this.setState({
  332. two: false,
  333. one : false,
  334. three: true,
  335. four: false,
  336. deliveryTiming: '4:00PM--6:00PM',
  337. showPM : 'flex',
  338. showCardOD: 'flex',
  339. showCOD: 'none',
  340. })
  341. }} style={{ display: this.state.ts46 }}>
  342. <Left>
  343. <Radio selected={this.state.three} radioSelectedColor={"#5cb85c"} style={{marginTop:-3}} />
  344. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'4:00 PM to 6:00PM '}</Text>
  345. </Left>
  346. </ListItem>
  347.  
  348. <ListItem onPress={() => {
  349. this.setState({
  350. two: false,
  351. one: false,
  352. three: false,
  353. four: true,
  354. deliveryTiming: '6:00PM--9:00PM',
  355. showPM : 'flex',
  356. showCardOD: 'none',
  357. showCOD: 'none',
  358. })
  359. }} style={{ display: this.state.ts69 }}>
  360. <Left>
  361. <Radio selected={this.state.four} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  362. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'6:00 PM to 9:00PM'} </Text>
  363. </Left>
  364. </ListItem>
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. <Content style={{display:this.state.showPM}}>
  372. <ListItem itemDivider>
  373. <Text style={{fontFamily:'EncodeSansCondensed-Bold', fontSize:15, color:'#000'}}>CHOOSE PAYMENT METHOD </Text>
  374. </ListItem>
  375.  
  376. <ListItem onPress={() => {
  377. if( this.state.deliveryTiming !== null){
  378.  
  379. base.push('/liquorOrders', {
  380. data: {
  381. userid: this.state.userKey,
  382. date: this.state.date,
  383. amount: this.state.total,
  384. totalItems: this.state.totalItems,
  385. status: 'Confirmed',
  386. userCords: this.state.dt.address.userCords,
  387. deliveryPerson: 'mobileNo',
  388. item: this.state.dt.cart,
  389. address: this.state.dt.address,
  390. name: this.state.dt.name,
  391. mobile: this.state.dt.mobile,
  392. deliveryTiming: this.state.deliveryTiming,
  393. paymentMode : 'COD'
  394. }
  395. }).then(newLocation => {
  396. base.remove('/users/' + this.state.userKey + '/cart');
  397. this._sendMsg(newLocation.key.substring(14, ))
  398. move.navigate('orderSuccess');
  399. //console.log(newLocation)
  400. }).catch(err => {
  401. console.log(err)
  402. });
  403.  
  404. this.setState({
  405. pm1 : !this.state.pm1,
  406. pm2: false,
  407. pm3 : false,
  408. })
  409. }else{
  410. Alert.alert('Select Delivery Timing...');
  411. }
  412. }} style={{ display: this.state.showCOD }}>
  413. <Left>
  414. <Radio selected={this.state.pm1} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  415. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> CASH / PAYTM ON DELIVERY </Text>
  416. </Left>
  417. <Right>
  418. <Icon style={{ fontSize: 25, color: '#000',marginRight:5 }} type="FontAwesome" name="rupee" />
  419. </Right>
  420. </ListItem>
  421.  
  422. <ListItem onPress={() => {
  423. if (this.state.deliveryTiming !== null) {
  424.  
  425. base.push('/liquorOrders', {
  426. data: {
  427. userid: this.state.userKey,
  428. date: this.state.date,
  429. amount: this.state.total,
  430. totalItems: this.state.totalItems,
  431. status: 'Confirmed',
  432. userCords: this.state.dt.address.userCords,
  433. deliveryPerson: 'mobileNo',
  434. item: this.state.dt.cart,
  435. address: this.state.dt.address,
  436. name: this.state.dt.name,
  437. mobile: this.state.dt.mobile,
  438. deliveryTiming: this.state.deliveryTiming,
  439. paymentMode : 'CardOnDelivery'
  440. }
  441. }).then(newLocation => {
  442. base.remove('/users/' + this.state.userKey + '/cart');
  443. this._sendMsg(newLocation.key.substring(14, ))
  444. move.navigate('orderSuccess');
  445. //console.log(newLocation)
  446. }).catch(err => {
  447. console.log(err)
  448. });
  449.  
  450.  
  451. this.setState({
  452. pm1: false,
  453. pm2: !this.state.pm2,
  454. pm3: false,
  455. })
  456. } else {
  457. Alert.alert('Select Delivery Timing...');
  458. }
  459. }} style={{ display: this.state.showCardOD }}>
  460. <Left>
  461. <Radio selected={this.state.pm2} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  462. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> CARD ON DELIVERY </Text>
  463. </Left>
  464. <Right>
  465. <Icon style={{ fontSize: 25, color: '#000' }} type="Ionicons" name="ios-card" />
  466. </Right>
  467. </ListItem>
  468.  
  469. <ListItem onPress={() => {
  470. if (this.state.deliveryTiming !== null) {
  471. this._onlinePayment(this.state.total);
  472. this.setState({
  473. pm1: false,
  474. pm2: false,
  475. pm3: !this.state.pm3,
  476. })
  477. } else {
  478. Alert.alert('Select Delivery Timing...');
  479. }
  480. }} >
  481. <Left>
  482. <Radio selected={this.state.pm3} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  483. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> ONLINE PAYMENT </Text>
  484. </Left>
  485. <Right>
  486. <Icon style={{ fontSize: 22, color: '#000' }} type="MaterialIcons" name="laptop" />
  487. </Right>
  488. </ListItem>
  489.  
  490. <ListItem onPress={() => {
  491. if (this.state.deliveryTiming !== null) {
  492.  
  493. this.props.navigation.navigate('PaymentsScreen',{userKey : this.state.userKey});
  494.  
  495. this.setState({
  496. pm1: false,
  497. pm2: false,
  498. pm3: false,
  499. pm4: !this.state.pm4,
  500. })
  501. console.log(this.props);
  502. } else {
  503. Alert.alert('Select Delivery Timing...');
  504. }
  505. }} >
  506. <Left>
  507. <Radio selected={this.state.pm3} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  508. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> PayTM </Text>
  509. </Left>
  510. <Right>
  511. <Icon style={{ fontSize: 22, color: '#000' }} type="Entypo" name="wallet" />
  512. </Right>
  513. </ListItem>
  514.  
  515. </Content>
  516.  
  517.  
  518. </Container>
  519. </SafeAreaView>
  520. );
  521. }
  522. }
  523.  
  524.  
  525. const styles = StyleSheet.create({
  526. header:{
  527. backgroundColor:'#000',
  528. height:65,
  529. paddingBottom:3,
  530. },
  531. mainBody:{
  532. backgroundColor:'#0c0e0f',
  533. },
  534. cardBg:{
  535. //backgroundColor:'#1e1e1e',
  536. elevation:1,
  537. margin:'1%',
  538. },
  539.  
  540. });
  541.  
  542.  
  543. export default PaymentMode;
Add Comment
Please, Sign In to add comment