Guest User

Untitled

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