import * as React from 'react'; import Select from 'react-select'; import { Button } from 'reactstrap'; import { getPaymentModeByName } from '../../../helpers/common-helper'; import { MappingBeanInterface } from '../../../services/Models/sabpaisa-payment-types'; import sabpaisaService from '../../../services/sabpaisa-service' export interface Props { updateState: (arg: number) => void; paymentData: { [key: string]: any }, makeApiReqCardFeeCalculation: (arg: MappingBeanInterface) => void, updateStateWithError: (resError: any, screenId: number) => void, } export interface State { readonly isClearable: boolean; readonly isDisabled: boolean; readonly isLoading: boolean; readonly isRtl: boolean; readonly isSearchable: boolean; processing: boolean, selectedMapping: any, mappingBeans: any } export default class BHIMUpiQr extends React.Component { constructor(props: Props) { super(props); this.state = { isClearable: true, isDisabled: false, isLoading: false, isRtl: false, isSearchable: true, processing: false, selectedMapping: {}, mappingBeans: { label: '', value: {}, key: 2 } }; } makeApiReqBhimUPIPayment(paymentData: any, selectedMapData: any) { const { amountBean, clientCode, clientId, clientName, clientTxnId, payerEmail, payerMobNumber, requestAmount, spTxnId, } = paymentData; const { endpoint, paymode } = selectedMapData; this.setState({ processing: true }); const payload = { txnId: spTxnId, clientId, clientTxnId, requestAmount, mappingBean: { mappingId: selectedMapData['mappingId'], feeForward: selectedMapData['feeForward'], clientId: selectedMapData['clientId'], paymodeId: selectedMapData['paymodeId'], endpointId: selectedMapData['endpointId'], active: selectedMapData['active'], paymode, endpoint }, paidAmount: amountBean['paidAmount'], clientName, clientCode, payeeEmail: payerEmail, payeeMobile: payerMobNumber, amountType: amountBean['amountType'], udf1: "chrome", payMode: paymode, endPoint: endpoint } sabpaisaService.bhimUPIQrPayment(payload) .then(response => { this.setState({ processing: false }) if (response.data.bankUrl) { window.location.href = response.data.bankUrl; } }) .catch(err => { this.props.updateStateWithError(err, 400); this.setState({ processing: false }) }) } proceedBHIMUPIQRRequest = () => { const { paymentData } = this.props; const { selectedMapping } = this.state; let selectedMapData = selectedMapping.value this.makeApiReqBhimUPIPayment(paymentData, selectedMapData) } onChange = (e: any) => { if (!e) { this.setState({ selectedMapping: {} }) } else { const { value } = e; this.props.makeApiReqCardFeeCalculation(value); this.setState({ mappingBeans: value, selectedMapping: e }) } } // Lifecycle methods section render() { const { state, props, proceedBHIMUPIQRRequest } = this; const { isClearable, isSearchable, isDisabled, isLoading, isRtl, selectedMapping, processing } = state; const { paymentData } = props; const BHIM_UPI_QR_Details: any = (paymentData && paymentData.activeMapping.length) ? getPaymentModeByName("bhim_upi_qr", paymentData.activeMapping) : []; const isShowButton: boolean = Object.keys(selectedMapping).length ? true : false; return (

QR Code