import * as React from 'react';
import { connect } from "react-redux";
import {
TouchableOpacity,
View,
Text,
Keyboard,
BackHandler,
Image
} from 'react-native';
import { returnIcon } from '../../utils/card.js';
import Assets from '../../components/assets.manager.js';
import Lottie from 'lottie-react-native';
import moment from 'moment';
import Theme from '../../components/theme.style.js';
import CustomSafeArea from '../../components/safeArea.component.js';
import DB from '../../components/storage/';
class PayatpumpPaymentSuccess extends React.Component {
constructor(props) {
super(props)
}
state = {
email: null,
keyboardHeight: 0,
data: this.props.route?.params?.transactionData,
transactionDetails: this.props.route?.params?.transactionDetails,
newDetails: this.props.route?.params?.newDetails?.response,
loading: true,
selectedCard: null
}
componentDidMount() {
this.getCard();
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
BackHandler.addEventListener("hardwareBackPress", this.onPressBack);
}
componentWillUnmount() {
this.keyboardDidShowListener.remove()
this.keyboardDidHideListener.remove()
BackHandler.removeEventListener("hardwareBackPress", this.onPressBack);
}
getCard = async () => {
const item = await DB.get("pumpPaymentCards");
this.setState({ selectedCard: JSON.parse(item) });
}
onPressBack = () => {
this.onNavigateMain();
return true;
}
onNavigateMain = () => {
this.props.navigation.reset({
index: 0,
routes: [{name: 'Main'}]
})
}
_keyboardDidShow = (value) => {
this.setState({ keyboardHeight: value.endCoordinates.height - 120 })
}
_keyboardDidHide = () => {
this.setState({ keyboardHeight: 0 })
}
getPoints = () => {
let points = this.state.newDetails?.loyaltyPointsMessages[0]?.earnedRewardSummary || this.state.newDetails?.loyaltyPointsMessages[1]?.earnedRewardSummary || 0;
if(points === 0) {
return null;
}
return (
Earned Points
{Theme.formatter.CRNCY(points)}
)
}
render() {
return(
Success!
Transaction Date
{new moment(this.state.newDetails?.posDatetimeUtc).format("DD MMM YYYY, hh:mm A")}
Transaction ID
{this.state.newDetails?.posTransactionId}
{this.state.newDetails?.totalDiscount !== 0 &&
Subtotal
{this.state.newDetails?.formattedSubtotal}
}
{this.state.newDetails?.totalDiscount !== 0 &&
Discount
- {this.state.newDetails?.formattedTotalDiscounts}
}
Total
{this.state.newDetails?.formattedTotal}
{this.state.selectedCard &&
Payment Method
{this.state.selectedCard?.lastFour}
}
{this.getPoints()}
Thank you for your payment!
Back To Home
)
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(PayatpumpPaymentSuccess)