import React, { Component } from "react"; import { Platform, StyleSheet, View, TouchableOpacity, Alert, SafeAreaView } from "react-native"; import { observable, action, transaction } from "mobx"; import Text from "react-native-text"; import { Button } from "react-native-elements"; import { observer, inject } from "mobx-react/native"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import Icon from "react-native-vector-icons/dist/Ionicons"; import Icon2 from "react-native-vector-icons/dist/MaterialCommunityIcons"; import Toast, { DURATION } from "react-native-easy-toast"; import Log from '../../config/log' import { CreditCardInput, LiteCreditCardInput } from "react-native-credit-card-input"; //component import DrawerNavigationHeader from "../../components/Public/drawerNavigationHeader"; // function import theme from "../../config/colors"; import { Fonts } from "../../config/fonts"; import { width, height } from "../../config/screen"; import Loader from "../../components/Public/loader"; import Size from "../../config/size"; const size = new Size(); const log = new Log() @inject(["userStore"]) @observer export default class Payment extends Component { @observable menu = false; @observable addCard = false; cardData = null; static navigationOptions = { drawerLabel: "Account" }; constructor(props) { super(props); this.store = this.props.userStore; } changeIndex(index) { this.tabMap.index = index; } addCardAction() { var BreakException = {}; if (this.cardData != null) { if (this.cardData.valid) { let data = { num: this.cardData.values.number.replace(/\s/g, ""), expiry: this.cardData.values.expiry.replace("/", ""), cvc: this.cardData.values.cvc }; console.log(this.cardData); log.firebaseLog('press_add_button_on_creditCard_progress',{}) this.store.postCreditCard(this, data); } else { try { Object.keys(this.cardData.status).forEach(e => { console.log(e + " - " + this.cardData.status[e]); if ( this.cardData.status[e] == "incomplete" || this.cardData.status[e] == "invalid" ) { this.refs.toast.show(e + " " + this.cardData.status[e]); throw BreakException; } }); } catch (e) { if (e !== BreakException) throw e; } } } else { console.log("error"); this.refs.toast.show("please insert card number"); } } testing(token, data) { Alert.alert(token, data, { text: "ok", onPress: () => console.log("ok") }); } @action removeCard() { Alert.alert("", "Are you sure? ", [ { text: "Cancel", onPress: () => console.log("Cancel") }, { text: "Sure", onPress: () => this.store.deleCreditCard(this) } ]); } updateCard() { //this.removeCard(); this.props.navigation.navigate("AddCard"); } render() { return ( {!this.store.addedCard ? ( { this.addCard = true; log.firebaseLog('press_add_creditCard_button',{}) }} > Add credit card {this.addCard ? ( (this.cardData = form)} /> { this.addCardAction(); }} > Add { this.addCard = false; this.cardData = null; log.firebaseLog('press_cancel_button_on_creditCard_progress',{}) }} > CANCEL ) : ( )} ) : ( { this.addCard = true; }} > {this.store.creditCardinfo.num} (this.menu = !this.menu)} > )} {this.menu ? ( { this.removeCard(); this.menu = !this.menu; log.firebaseLog('press_remove_card_button',{}) }} > Remove Card { this.menu = !this.menu; }} > CANCEL ) : ( )} ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: "center", backgroundColor: "white" }, welcome: { fontSize: 20, textAlign: "center", margin: 10 }, instructions: { textAlign: "center", color: "#333333", marginBottom: 5 }, buttonView: { width: "80%", height: 60, marginTop: 10, alignItems: "center", justifyContent: "center", borderColor: "black", borderWidth: 1 }, label: { color: "black", fontSize: 12 }, input: { fontSize: 16, color: "black" } });