Guest User

Untitled

a guest
Aug 6th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.49 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. hour : 17,
  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. text : 'none'
  56. };
  57.  
  58.  
  59. }
  60.  
  61. _sendMsg = (oid) => {
  62. 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' )
  63. .then(function (response) {
  64. //alert('msg send')
  65. console.log('send');
  66. })
  67. .catch(function (error) {
  68. //alert('msg not send')
  69. console.log(error);
  70. });
  71. }
  72.  
  73. _onlinePayment = (tp) => {
  74. var that = this;
  75. var options = {
  76. description: 'Liquor Order Payment',
  77. image: 'https://image.ibb.co/dRfzk8/pp_Cropped.jpg',
  78. currency: 'INR',
  79. key: 'rzp_test_W95b9b1G4Voj1E',
  80. amount: tp*100,
  81. name: 'Liquorcart',
  82. prefill: {
  83. email: '',
  84. contact: this.state.dt.mobile,
  85. name: this.state.dt.name
  86. },
  87. theme: { color: '#000' }
  88. }
  89.  
  90. RazorpayCheckout.open(options).then((data) => {
  91. // handle success
  92. payId = data.razorpay_payment_id;
  93. // console.log(move)
  94. // console.log(payId)
  95. // alert(`Success: ${data.razorpay_payment_id}`);
  96. orderKey = base.push('liquorOrders', {
  97. data: {
  98. userid: this.state.userKey,
  99. date: this.state.date,
  100. amount: tp,
  101. totalItems: this.state.totalItems,
  102. status: 'Confirmed',
  103. userCords: this.state.dt.address.userCords,
  104. deliveryPerson: 'mobileNo',
  105. item: this.state.dt.cart,
  106. address: this.state.dt.address,
  107. name: this.state.dt.name,
  108. mobile: this.state.dt.mobile,
  109. deliveryTiming: this.state.deliveryTiming,
  110. paymentMode: 'Online',
  111. razorpayId: payId
  112. },
  113. then(err) {
  114. if (!err) {
  115. base.remove('/users/' + fuckkk + '/cart');
  116. that._sendMsg(orderKey.key.substring(14, ));
  117. move.navigate('orderSuccess');
  118. }
  119. }
  120. });
  121.  
  122. }).catch((error) => {
  123. // handle failure
  124. alert(` ${error.description}`);
  125. move.navigate('orderError');
  126. });
  127. RazorpayCheckout.onExternalWalletSelection(data => {
  128. alert(`External Wallet Selected: ${data.external_wallet} `);
  129. });
  130. }
  131.  
  132. componentWillMount(){
  133.  
  134. AsyncStorage.getItem("userKey").then((value) => {
  135. fuckkk = value
  136. this.setState({ userKey: value });
  137. console.log('sdf' + this.state.userKey)
  138. console.log('ga' + fuckkk)
  139.  
  140. base.bindToState('users/' + this.state.userKey, {
  141. context: this,
  142. asArray: false,
  143. state: 'dt'
  144. })
  145.  
  146. }).done();
  147.  
  148.  
  149.  
  150.  
  151. }
  152.  
  153. componentDidMount() {
  154.  
  155.  
  156. switch (hour) {
  157. case 1:
  158. return (
  159. this.setState({
  160. ts122: 'flex',
  161. ts24: 'flex',
  162. ts46: 'flex',
  163. ts69: 'flex',
  164. nextDay: '',
  165. })
  166. );
  167. case 2:
  168. return (
  169. this.setState({
  170. ts122: 'flex',
  171. ts24: 'flex',
  172. ts46: 'flex',
  173. ts69: 'flex',
  174. nextDay: '',
  175. })
  176. );
  177. case 3:
  178. return (
  179. this.setState({
  180. ts122: 'flex',
  181. ts24: 'flex',
  182. ts46: 'flex',
  183. ts69: 'flex',
  184. nextDay: ''
  185. })
  186. );
  187. case 4:
  188. return (
  189. this.setState({
  190. ts122: 'flex',
  191. ts24: 'flex',
  192. ts46: 'flex',
  193. ts69: 'flex',
  194. nextDay: ''
  195. })
  196. );
  197. case 5:
  198. return (
  199. this.setState({
  200. ts122: 'flex',
  201. ts24: 'flex',
  202. ts46: 'flex',
  203. ts69: 'flex',
  204. nextDay: ''
  205. })
  206. );
  207. case 6:
  208. return (
  209. this.setState({
  210. ts122: 'flex',
  211. ts24: 'flex',
  212. ts46: 'flex',
  213. ts69: 'flex',
  214. nextDay: ''
  215. })
  216. );
  217. case 7:
  218. return (
  219. this.setState({
  220. ts122: 'flex',
  221. ts24: 'flex',
  222. ts46: 'flex',
  223. ts69: 'flex',
  224. nextDay: ''
  225. })
  226. );
  227. case 8:
  228. return (
  229. this.setState({
  230. ts122: 'flex',
  231. ts24: 'flex',
  232. ts46: 'flex',
  233. ts69: 'flex',
  234. nextDay: ''
  235. })
  236. );
  237. case 9:
  238. return (
  239. this.setState({
  240. ts122: 'flex',
  241. ts24: 'flex',
  242. ts46: 'flex',
  243. ts69: 'flex',
  244. nextDay: ''
  245. })
  246. );
  247. case 10:
  248. return (
  249. this.setState({
  250. ts122: 'flex',
  251. ts24: 'flex',
  252. ts46: 'flex',
  253. ts69: 'flex',
  254. nextDay: ''
  255. })
  256. );
  257. case 11:
  258. return (
  259. this.setState({
  260. ts122: 'flex',
  261. ts24: 'flex',
  262. ts46: 'flex',
  263. ts69: 'flex',
  264. nextDay: ''
  265. })
  266. );
  267. case 12:
  268. return (
  269. this.setState({
  270. ts122: 'none',
  271. ts24: 'flex',
  272. ts46: 'flex',
  273. ts69: 'flex',
  274. nextDay: '',
  275. })
  276. );
  277. case 13:
  278. return (
  279. this.setState({
  280. ts122: 'none',
  281. ts24: 'flex',
  282. ts46: 'flex',
  283. ts69: 'flex',
  284. nextDay: '',
  285. })
  286. );
  287. case 14:
  288. return (
  289. this.setState({
  290. ts122: 'none',
  291. ts24: 'none',
  292. ts46: 'flex',
  293. ts69: 'flex',
  294. nextDay: '',
  295. })
  296. );
  297. case 15:
  298. return (
  299. this.setState({
  300. ts122: 'none',
  301. ts24: 'none',
  302. ts46: 'flex',
  303. ts69: 'flex',
  304. nextDay: '',
  305. })
  306. );
  307. case 16:
  308. return (
  309. this.setState({
  310. ts122: 'none',
  311. ts24: 'none',
  312. ts46: 'none',
  313. ts69: 'flex',
  314. nextDay: '',
  315. })
  316. );
  317. case 17:
  318. return (
  319. this.setState({
  320. ts122: 'none',
  321. ts24: 'none',
  322. ts46: 'none',
  323. ts69: 'flex',
  324. nextDay: '',
  325. })
  326. );
  327. case 18:
  328. return (
  329. this.setState({
  330. nextDay: 'TOMORROW',
  331. ts122: 'flex',
  332. ts24: 'flex',
  333. ts46: 'flex',
  334. ts69: 'flex',
  335. })
  336. );
  337. case 19:
  338. return (
  339. this.setState({
  340. nextDay: 'TOMORROW',
  341. ts122: 'flex',
  342. ts24: 'flex',
  343. ts46: 'flex',
  344. ts69: 'flex',
  345. })
  346. );
  347. case 20:
  348. return (
  349. this.setState({
  350. nextDay: 'TOMORROW',
  351. ts122: 'flex',
  352. ts24: 'flex',
  353. ts46: 'flex',
  354. ts69: 'flex',
  355. })
  356. );
  357. case 21:
  358. return (
  359. this.setState({
  360. nextDay: 'TOMORROW',
  361. ts122: 'flex',
  362. ts24: 'flex',
  363. ts46: 'flex',
  364. ts69: 'flex',
  365. })
  366. );
  367. case 22:
  368. return (
  369. this.setState({
  370. nextDay: 'TOMORROW',
  371. ts122: 'flex',
  372. ts24: 'flex',
  373. ts46: 'flex',
  374. ts69: 'flex',
  375. })
  376. );
  377. case 23:
  378. return (
  379. this.setState({
  380. nextDay: 'TOMORROW',
  381. ts122: 'flex',
  382. ts24: 'flex',
  383. ts46: 'flex',
  384. ts69: 'flex',
  385. })
  386. );
  387. case 24:
  388. return (
  389. this.setState({
  390. nextDay: '',
  391. ts122: 'flex',
  392. ts24: 'flex',
  393. ts46: 'flex',
  394. ts69: 'flex',
  395. })
  396. );
  397. }
  398.  
  399.  
  400.  
  401. }
  402.  
  403.  
  404. componentDidUpdate(prevProps, prevState){
  405.  
  406. var hola = 0;
  407. var bhola = 0;
  408. if(prevState.dt.name !== this.state.dt.name){
  409. _.each(this.state.dt.cart, (val, key) => {
  410. hola = hola + (val.price * val.orderQty)
  411. bhola = bhola + parseInt(val.orderQty)
  412. })
  413.  
  414. this.setState({
  415. total: hola,
  416. totalItems: bhola,
  417. })
  418. }
  419.  
  420. if( hour != new Date().getHours()){
  421. hour = new Date().getHours();
  422. }
  423. }
  424.  
  425.  
  426. render() {
  427.  
  428. return (
  429. <SafeAreaView style={{flex:1,backgroundColor:'#000'}}>
  430. <Container style={{backgroundColor:'#fff'}}>
  431. <OfflineNotice />
  432. <StatusBar hidden={true} />
  433. <Header style={styles.header}>
  434. <Left>
  435. <Button onPress={() => this.props.navigation.goBack()} style={{backgroundColor:'transparent',marginLeft:-20}} >
  436. <Icon type='Ionicons' name='md-arrow-back' style={{color:'#fff',fontSize:32}} />
  437. </Button>
  438. </Left>
  439. <Body>
  440. </Body>
  441. <Right>
  442.  
  443. </Right>
  444. </Header>
  445. <ListItem itemDivider>
  446. <Text style={{ fontFamily: 'EncodeSansCondensed-Bold', fontSize: 15, color: '#000' }}>CHOOSE {this.state.nextDay} DELIVERY TIMING </Text>
  447. </ListItem>
  448.  
  449.  
  450. <ListItem onPress={ () => {
  451. this.setState({
  452. one : true,
  453. two : false,
  454. three : false,
  455. four : false,
  456. deliveryTiming : '12:00NOON--2:00PM',
  457. showPM : 'flex',
  458. showCardOD: 'flex',
  459. showCOD: 'flex',
  460. })
  461. }} style={{ display: this.state.ts122 }}>
  462. <Left>
  463. <Radio selected={this.state.one} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  464. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'12:00NOON to 02:00PM '}</Text>
  465. </Left>
  466. </ListItem>
  467.  
  468. <ListItem onPress={() => {
  469. this.setState({
  470. two: true,
  471. one : false,
  472. three : false,
  473. four: false,
  474. deliveryTiming: '2:00PM--4:00PM',
  475. showPM : 'flex',
  476. showCardOD: 'flex',
  477. showCOD: 'flex',
  478. })
  479. }} style={{ display: this.state.ts46 }}>
  480. <Left>
  481. <Radio selected={this.state.two} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  482. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'2:00 PM to 4:00PM '}</Text>
  483. </Left>
  484. </ListItem>
  485.  
  486. <ListItem onPress={() => {
  487. this.setState({
  488. two: false,
  489. one : false,
  490. three: true,
  491. four: false,
  492. deliveryTiming: '4:00PM--6:00PM',
  493. showPM : 'flex',
  494. showCardOD: 'flex',
  495. showCOD: 'none',
  496. })
  497. }} style={{ display: this.state.ts46 }}>
  498. <Left>
  499. <Radio selected={this.state.three} radioSelectedColor={"#5cb85c"} style={{marginTop:-3}} />
  500. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'4:00 PM to 6:00PM '}</Text>
  501. </Left>
  502. </ListItem>
  503.  
  504. <ListItem onPress={() => {
  505. this.setState({
  506. two: false,
  507. one: false,
  508. three: false,
  509. four: true,
  510. deliveryTiming: '6:00PM--9:00PM',
  511. showPM : 'flex',
  512. showCardOD: 'none',
  513. showCOD: 'none',
  514. })
  515. }} style={{ display: this.state.ts69 }}>
  516. <Left>
  517. <Radio selected={this.state.four} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  518. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> {'6:00 PM to 9:00PM'} </Text>
  519. </Left>
  520. </ListItem>
  521.  
  522.  
  523. <Content style={{display:this.state.showPM}}>
  524. <ListItem itemDivider>
  525. <Text style={{fontFamily:'EncodeSansCondensed-Bold', fontSize:15, color:'#000'}}>CHOOSE PAYMENT METHOD </Text>
  526. </ListItem>
  527.  
  528. <ListItem onPress={() => {
  529. if( this.state.deliveryTiming !== null){
  530.  
  531. base.push('/liquorOrders', {
  532. data: {
  533. userid: this.state.userKey,
  534. date: this.state.date,
  535. amount: this.state.total,
  536. totalItems: this.state.totalItems,
  537. status: 'Confirmed',
  538. userCords: this.state.dt.address.userCords,
  539. deliveryPerson: 'mobileNo',
  540. item: this.state.dt.cart,
  541. address: this.state.dt.address,
  542. name: this.state.dt.name,
  543. mobile: this.state.dt.mobile,
  544. deliveryTiming: this.state.deliveryTiming,
  545. paymentMode : 'COD'
  546. }
  547. }).then(newLocation => {
  548. base.remove('/users/' + this.state.userKey + '/cart');
  549. this._sendMsg(newLocation.key.substring(14, ))
  550. move.navigate('orderSuccess');
  551. //console.log(newLocation)
  552. }).catch(err => {
  553. console.log(err)
  554. });
  555.  
  556. this.setState({
  557. pm1 : !this.state.pm1,
  558. pm2: false,
  559. pm3 : false,
  560. })
  561. }else{
  562. Alert.alert('Select Delivery Timing...');
  563. }
  564. }} style={{ display: this.state.showCOD }}>
  565. <Left>
  566. <Radio selected={this.state.pm1} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  567. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> CASH / PAYTM ON DELIVERY </Text>
  568. </Left>
  569. <Right>
  570. <Icon style={{ fontSize: 25, color: '#000',marginRight:5 }} type="FontAwesome" name="rupee" />
  571. </Right>
  572. </ListItem>
  573.  
  574. <ListItem onPress={() => {
  575. if (this.state.deliveryTiming !== null) {
  576.  
  577. base.push('/liquorOrders', {
  578. data: {
  579. userid: this.state.userKey,
  580. date: this.state.date,
  581. amount: this.state.total,
  582. totalItems: this.state.totalItems,
  583. status: 'Confirmed',
  584. userCords: this.state.dt.address.userCords,
  585. deliveryPerson: 'mobileNo',
  586. item: this.state.dt.cart,
  587. address: this.state.dt.address,
  588. name: this.state.dt.name,
  589. mobile: this.state.dt.mobile,
  590. deliveryTiming: this.state.deliveryTiming,
  591. paymentMode : 'CardOnDelivery'
  592. }
  593. }).then(newLocation => {
  594. base.remove('/users/' + this.state.userKey + '/cart');
  595. this._sendMsg(newLocation.key.substring(14, ))
  596. move.navigate('orderSuccess');
  597. //console.log(newLocation)
  598. }).catch(err => {
  599. console.log(err)
  600. });
  601.  
  602.  
  603. this.setState({
  604. pm1: false,
  605. pm2: !this.state.pm2,
  606. pm3: false,
  607. })
  608. } else {
  609. Alert.alert('Select Delivery Timing...');
  610. }
  611. }} style={{ display: this.state.showCardOD }}>
  612. <Left>
  613. <Radio selected={this.state.pm2} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  614. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> CARD ON DELIVERY </Text>
  615. </Left>
  616. <Right>
  617. <Icon style={{ fontSize: 25, color: '#000' }} type="Ionicons" name="ios-card" />
  618. </Right>
  619. </ListItem>
  620.  
  621. <ListItem onPress={() => {
  622. if (this.state.deliveryTiming !== null) {
  623. this._onlinePayment(this.state.total);
  624. this.setState({
  625. pm1: false,
  626. pm2: false,
  627. pm3: !this.state.pm3,
  628. })
  629. } else {
  630. Alert.alert('Select Delivery Timing...');
  631. }
  632. }} >
  633. <Left>
  634. <Radio selected={this.state.pm3} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  635. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> ONLINE PAYMENT </Text>
  636. </Left>
  637. <Right>
  638. <Icon style={{ fontSize: 22, color: '#000' }} type="MaterialIcons" name="laptop" />
  639. </Right>
  640. </ListItem>
  641.  
  642. <ListItem onPress={() => {
  643. if (this.state.deliveryTiming !== null) {
  644.  
  645. this.props.navigation.navigate('PaymentsScreen',{userKey : this.state.userKey});
  646.  
  647. this.setState({
  648. pm1: false,
  649. pm2: false,
  650. pm3: false,
  651. pm4: !this.state.pm4,
  652. })
  653. console.log(this.props);
  654. } else {
  655. Alert.alert('Select Delivery Timing...');
  656. }
  657. }} >
  658. <Left>
  659. <Radio selected={this.state.pm3} selectedColor={"#5cb85c"} style={{marginTop:-3}} />
  660. <Text style={{ marginLeft: '2%', textAlign: 'left', fontSize: 12, fontFamily: 'EncodeSansCondensed-Bold', color: '#444' }}> PayTM </Text>
  661. </Left>
  662. <Right>
  663. <Icon style={{ fontSize: 22, color: '#000' }} type="Entypo" name="wallet" />
  664. </Right>
  665. </ListItem>
  666.  
  667. </Content>
  668.  
  669.  
  670. </Container>
  671. </SafeAreaView>
  672. );
  673. }
  674. }
  675.  
  676.  
  677. const styles = StyleSheet.create({
  678. header:{
  679. backgroundColor:'#000',
  680. height:65,
  681. paddingBottom:3,
  682. },
  683. mainBody:{
  684. backgroundColor:'#0c0e0f',
  685. },
  686. cardBg:{
  687. //backgroundColor:'#1e1e1e',
  688. elevation:1,
  689. margin:'1%',
  690. },
  691.  
  692. });
  693.  
  694.  
  695. export default PaymentMode;
Add Comment
Please, Sign In to add comment