import React, { Component } from "react"; import { Modal, ModalBody } from 'reactstrap'; import "../../index.css"; import 'bootstrap/dist/css/bootstrap.min.css' import PaymentMethods from "./Sections/PaymentMethod" import PaymentLayout from "./Sections/Layouts/PaymentLayout" import PaymentMethodData, { CardFeeCalculation, MappingBeanInterface } from "../../services/Models/sabpaisa-payment-types"; import CardDetails from "./Sections/CardDetails"; import SavedCard from "./Sections/SavedCard"; import UpiMethods from "./Sections/UpiMethods"; import UpiPaymentProcessing from "./Sections/UpiPaymentProcessing"; import NetBanking from "./Sections/NetBanking"; import OtherMethods from "./Sections/OtherMethods"; import SavedCardCheckout from "./Sections/SavedCardCheckout"; import PaymentSuccess from "./Sections/PaymentSuccess"; import PaymentProcessing from "./Sections/PaymentProcessing"; import BankRedirect from "./Sections/BankRedirect"; import PaymentFailed from "./Sections/PaymentFailed"; import PaymentError from "./Sections/PaymentError"; import CancelPayment from "./Sections/CancelPayment"; import RequestTimeout from "./Sections/RequestTimeout"; import Rtgs from "./Sections/Rtgs"; import Neft from "./Sections/Neft"; import Imps from "./Sections/Imps"; import Wallet from "./Sections/Wallet"; import Emi from "./Sections/Emi"; import SelectEmi from "./Sections/SelectEmi"; import EmiCardDetails from "./Sections/EmiCardDetails"; import QrLoader from "./Sections/QrLoader"; import QrScreen from "./Sections/QrScreen"; import ClientDetails from "./Sections/ClientDetails"; import sabpaisaService from "../../services/sabpaisa-service"; import Cash from "./Sections/Cash"; import BHIMUpiQr from "./Sections/BHIMUpiQr"; import DebitCardDetails from "./Sections/DebitCardDetails"; import RupayCardDetails from "./Sections/RupayCardDetails"; import CVV from "./Sections/CVV"; export interface PgModalProps { isOpen?: boolean; clientCode: string; clientTxnId: string; onClick?: ( event: React.MouseEvent ) => void; additionalClass?: string; } type State = PaymentMethodData & { submitted: boolean, isOpen: boolean | undefined, currentState: number, errorMessage: string, paymentData: { [key: string]: any }, activeMappings: {}[], }; export default class PgModal extends Component { constructor(props: PgModalProps) { super(props); this.state = { submitted: false, isOpen: this.props.isOpen, currentState: 0, paymentData: {}, activeMappings: [], errorMessage: '' }; this.makeApiReqCardFeeCalculation = this.makeApiReqCardFeeCalculation.bind(this); } updateState = (counterNumber: number): void => { let finalData = { ...this.state.paymentData, amountBean: {} } this.setState({ paymentData: finalData }) this.setState({ currentState: counterNumber }); } getPaymentModes = () => { const { clientCode, clientTxnId } = this.props; sabpaisaService.getPaymentModes(clientCode, clientTxnId) .then((response: any) => { if (this.state.currentState == 400) { this.updateState(0); } this.setState({ paymentData: response.data, activeMappings: response.data.activeMappings }) }) .catch((e: Error) => { this.updateStateWithError(e, 400) }); }; makeApiReqCardFeeCalculation(payload: MappingBeanInterface) { const { clientId, clientTxnid, payerEmail, payerMobNumber, requestAmount, spTxnId, } = this.state.paymentData; let finalData: CardFeeCalculation = { "txnId": spTxnId, "clientId": clientId, "clientTxnId": clientTxnid, "requestAmount": requestAmount, "mappingBean": payload, "payerEmailId": payerEmail, "payerPhone": payerMobNumber } sabpaisaService.cardFeeCalculation(finalData) .then(data => { if (data.status == 200) { this.setState({ paymentData: { ...this.state.paymentData, ...data.data } }) } }) .catch(err => { }) } updateStateWithError = (resError: any, screenId: number): void => { const { paymentData } = this.state; if (resError === 'closedModel') { this.setState({ isOpen: false }); if (paymentData && paymentData.length) this.updateState(1); } else { let errorMessage = resError.response.data.errorMessage || resError.message; this.setState({ errorMessage }, () => { this.updateState(screenId); }); } } // Lifecycle methods componentDidMount() { if (this.props.isOpen) { this.getPaymentModes() } } renderComponent = () => { const { paymentData, errorMessage } = this.state; const obj: { [key: string]: any } = { 0: this.updateState(counterNumber)} />, 1: this.updateState(counterNumber)} />, 2: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 21: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 22: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 23: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 24: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 3: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 31: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 4: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 5: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 51: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 52: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 53: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 54: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 6: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 7: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 71: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 72: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 8: this.updateState(counterNumber)} />, 81: this.updateState(counterNumber)} />, 200: this.updateState(counterNumber)} />, 300: this.updateState(counterNumber)} />, 307: this.updateState(counterNumber)} />, 400: this.updateState(counterNumber)} />, 402: this.updateState(counterNumber)} />, 407: this.updateState(counterNumber)} />, 408: this.updateState(counterNumber)} />, 9: this.updateState(counterNumber)} childComp={ this.updateState(counterNumber)} />} />, 91: this.updateState(counterNumber)} />, } return (obj[this.state.currentState]); }; componentDidUpdate(prevProps: any) { if (prevProps.isOpen !== this.props.isOpen) { if (this.props.isOpen) { this.getPaymentModes() } this.setState({ isOpen: this.props.isOpen }); } if ((prevProps.clientTxnId !== this.props.clientTxnId) || (prevProps.clientCode !== this.props.clientCode)) { this.getPaymentModes(); } } render() { const { isOpen } = this.state; const { onClick, additionalClass } = this.props; return (
{/* */} {/* {title} */} {this.renderComponent()} {/* */}
); } }