Compare commits

...

2 Commits

Author SHA1 Message Date
victorAnumudu 145b77dcf7 flutterwave payment integration 2023-05-03 02:40:47 +01:00
ameye fabf07f2d1 Merge branch 'authroute_bug_fix' of WrenchBoard/Users-Wrench into master 2023-05-02 11:17:15 +00:00
8 changed files with 185 additions and 16 deletions
+3 -1
View File
@@ -18,11 +18,13 @@ REACT_APP_USERS_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/svs/user"
#"https://devapi.mermsemr.com/en/desktop/api/v2/myfituser"
REACT_APP_SESSION_EXPIRE_MINUTES=300000
REACT_APP_SESSION_EXPIRE_CHECKER=300000
REACT_APP_SESSION_EXPIRE_CHECKER=60000
REACT_APP_LOGIN_ERROR_TIMEOUT=7000
REACT_APP_SIGNUP_ERROR_TIMEOUT=7000
REACT_APP_FLUTTERWAVE_APIKEY=FLWPUBK_TEST-54c90141b028789d671067bd72f781a9-X
# Had to change the error time to 3sec cause it took too long
REACT_APP_RESET_START_ERROR_TIMEOUT=3000
+3 -1
View File
@@ -18,11 +18,13 @@ REACT_APP_USERS_ENDPOINT="https://apigate.lotus.g1.wrenchboard.com/svs/user"
#"https://devapi.mermsemr.com/en/desktop/api/v2/myfituser"
REACT_APP_SESSION_EXPIRE_MINUTES=300000
REACT_APP_SESSION_EXPIRE_CHECKER=300000
REACT_APP_SESSION_EXPIRE_CHECKER=60000
REACT_APP_LOGIN_ERROR_TIMEOUT=7000
REACT_APP_SIGNUP_ERROR_TIMEOUT=7000
REACT_APP_FLUTTERWAVE_APIKEY=FLWPUBK_TEST-54c90141b028789d671067bd72f781a9-X
# Had to change the error time to 3sec cause it took too long
REACT_APP_RESET_START_ERROR_TIMEOUT=3000
+3 -1
View File
@@ -18,11 +18,13 @@ REACT_APP_USERS_ENDPOINT="https://apigate.orion.g1.wrenchboard.com/svs/user"
#"https://devapi.mermsemr.com/en/desktop/api/v2/myfituser"
REACT_APP_SESSION_EXPIRE_MINUTES=300000
REACT_APP_SESSION_EXPIRE_CHECKER=300000
REACT_APP_SESSION_EXPIRE_CHECKER=60000
REACT_APP_LOGIN_ERROR_TIMEOUT=7000
REACT_APP_SIGNUP_ERROR_TIMEOUT=7000
REACT_APP_FLUTTERWAVE_APIKEY=FLWPUBK_TEST-54c90141b028789d671067bd72f781a9-X
# Had to change the error time to 3sec cause it took too long
REACT_APP_RESET_START_ERROR_TIMEOUT=3000
+24 -8
View File
@@ -1,24 +1,39 @@
import React, {useState} from 'react'
import RecentActivityTable from './WalletComponent/RecentActivityTable'
import LoadingSpinner from '../Spinners/LoadingSpinner'
import { useNavigate } from 'react-router-dom'
function AddFund({payment}) {
//STATE FOR CONTROLLED INPUTS
let [inputs, setInputs] = useState('0')
const navigate = useNavigate()
//STATE FOR CONTROLLED INPUT
let [input, setInput] = useState('0')
let [inputError, setInputError] = useState('')
// FUNCTION TO HANDLE INPUT CHANGE
const handleChange = ({target:{name, value}}) => {
setInputs(value)
setInput(value)
}
//FUNCTION TO HANDLE SUBMIT
const handleSubmit = (e) => {
e.preventDefault();
const handleSubmit = () => {
setInputError('')
if(!input || input == '0'){
setInputError('Please Enter Amount')
return
}
//valid inputs before submitting. Just for texting remove later
if(isNaN(input)){
setInputError('Amount must be a Number')
return
}
const stateData = {amount: Number(input)}
navigate('confirm-add-fund', {state: stateData})
setInputs('')
setInput('')
}
return (
<div className="content-wrapper w-full lg:flex xl:space-x-8 lg:space-x-4 bottomMargin">
@@ -30,7 +45,7 @@ function AddFund({payment}) {
<div className='md:flex items-center'>
<label className='w-full md:w-2/4 text-slate-600 text-lg'>Amount(Naira) <span className='text-red-500'>*</span></label>
<input className='w-full md:w-2/4 p-3 text-lg text-right bg-slate-100 rounded-md outline-0 placeholder:text-slate-500 placeholder:text-lg'
value={inputs}
value={input}
name='amount'
type="text"
placeholder='Amount'
@@ -38,6 +53,7 @@ function AddFund({payment}) {
onChange={handleChange}
/>
</div>
{inputError && <p className='text-base text-red-500'>{inputError}</p>}
</form>
<hr />
<div className='md:p-8 p-4 add-fund-btn flex justify-end items-center py-4'>
+131
View File
@@ -0,0 +1,131 @@
import React, {useState, useEffect} from 'react'
import RecentActivityTable from './WalletComponent/RecentActivityTable'
import LoadingSpinner from '../Spinners/LoadingSpinner'
import InputCom from '../Helpers/Inputs/InputCom'
import {toast} from 'react-toastify'
import { useLocation, useNavigate } from 'react-router-dom'
import { useSelector } from 'react-redux'
import usersService from '../../services/UsersService'
import { FlutterWaveButton, closePaymentModal } from 'flutterwave-react-v3'
function ConfirmAddFund({payment}) {
let {userDetails} = useSelector(state => state.userDetails) // TO GET LOGGEDIN USER DETAILS
let [pageLoading, setPageLoading] = useState(true)
let [requestStatus, setRequestStatus] = useState({message: '', loading: false, status: false}) // STATE FOR API REQUEST
const apiURL = new usersService()
const navigate = useNavigate()
let {state} = useLocation()
//FUNCTION TO HANDLE SUBMIT
const onSuccessPayment = () => {
setRequestStatus({message: '', loading: true, status: false})
let reqData = {amount: state?.account, currency: 'NGN'}
apiURL.startTopUp(reqData).then((res)=>{
if(res.data.internal_return < 0){
setRequestStatus({message: 'Could not finish transaction', loading: false, status: false})
toast.success('Opps! something went wrong')
}
// do something
setRequestStatus({message: 'Topup successful', loading: false, status: true})
toast.success('Account Topup was sucessful')
setTimeout(()=>{
navigate('/my-wallet', {replace: true})
}, 1000)
}).catch(err => {
// do something
setRequestStatus({message: 'Opps! An Error Occured', loading: false, status: false})
toast.success('Opps! something went wrong')
})
}
const config = {
public_key: process.env.REACT_APP_FLUTTERWAVE_APIKEY,
tx_ref: Date.now(),
amount: state?.amount,
currency: 'NGN',
payment_options: 'card,mobilemoney,ussd',
customer: {
email: `${userDetails.email}`,
phone_number: userDetails.phone,
name: `${userDetails.lastname} ${userDetails.firstname}`
},
customizations: {
title: 'WrenchBoard',
description: 'Topup Payment',
logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
},
};
const fwConfig = {
...config,
text: 'Proceed',
callback: (response) => {
onSuccessPayment()
closePaymentModal() // this will close the modal programmatically
},
onClose: () => {},
};
useEffect(()=>{
// what happens if not state redirect user
if(!state){
navigate('../add-fund',{replace: true})
}else{
setPageLoading(false)
}
},[])
return (
<div className="content-wrapper w-full lg:flex xl:space-x-8 lg:space-x-4 bottomMargin">
{pageLoading ?
<LoadingSpinner size='8' color='sky-blue' />
:
<div className="lg:w-1/2 w-full mb-10 lg:mb-0">
<div className="add-fund w-full bg-white dark:bg-dark-white rounded-2xl shadow">
<h2 className='md:p-8 p-4 text-slate-900 dark:text-white text-xl lg:text-2xl font-medium'>Confirm Add Fund To Account</h2>
<hr />
<div className='px-4 md:px-8 py-4 add-fund-info'>
<div className="field w-full mb-3">
<InputCom
label="Amount (Naira):"
type="text"
name="amount"
value={state.amount || ''}
disable={true}
/>
</div>
</div>
<hr />
<div className='md:p-8 p-4 add-fund-btn flex justify-end items-center py-4'>
<FlutterWaveButton {...fwConfig} className='text-lg text-white bg-sky-blue px-4 py-2 hover:opacity-90 rounded-md' />
</div>
</div>
</div>
}
<div className="lg:w-1/2 w-full mb-10 lg:mb-0">
<div className="wallet w-full md:p-8 p-4 h-full max-h-[600px] bg-white dark:bg-dark-white overflow-y-auto rounded-2xl shadow">
<h2 className='text-gray-900 dark:text-white text-xl lg:text-2xl font-medium'>Recent Activity</h2>
<p className='text-base text-gray-600 dark:text-white'>Activity Report</p>
{payment.loading ?
<LoadingSpinner size='16' color='sky-blue' />
:
<RecentActivityTable payment={payment}/>
}
</div>
</div>
</div>
)
}
export default ConfirmAddFund
+7 -5
View File
@@ -13,10 +13,7 @@ function ConfirmTransfer({payment, wallet}) {
const navigate = useNavigate()
let {state} = useLocation()
// what happens if not state redirect user
if(!state){
navigate('../transfer-fund',{replace: true})
}
let [requestStatus, setRequestStatus] = useState({message: '', loading: false, status: false})
let [pageLoading, setPageLoading] = useState(true)
@@ -45,7 +42,12 @@ function ConfirmTransfer({payment, wallet}) {
}
useEffect(()=>{
setPageLoading(false)
// what happens if not state redirect user
if(!state){
navigate('../transfer-fund',{replace: true})
}else{
setPageLoading(false)
}
},[])
return (
<div className="content-wrapper w-full lg:flex xl:space-x-8 lg:space-x-4 bottomMargin">
+2
View File
@@ -9,6 +9,7 @@ import TransferFund from './TransferFund'
import AddFund from './AddFund'
import AddRecipient from './AddRecipient'
import ConfirmTransfer from './ConfirmTransfer'
import ConfirmAddFund from './ConfirmAddFund'
function Wallet() {
return (
@@ -112,6 +113,7 @@ const WalletRoutes = () => {
<Routes>
<Route element={<Wallet />}>
<Route path='add-fund' element={<AddFund payment={paymentHistory} />} />
<Route path='add-fund/confirm-add-fund' element={<ConfirmAddFund payment={paymentHistory} />} />
<Route path='transfer-fund' element={<TransferFund payment={paymentHistory} wallet={walletList} />} />
<Route index element={<Balance payment={paymentHistory} purchase={purchaseHistory} coupon={couponHistory} wallet={walletList} />} />
<Route path='transfer-fund/add-recipient' element={<AddRecipient />} />
+12
View File
@@ -279,6 +279,18 @@ class usersService {
return this.postAuxEnd("/loadprofile", postData);
}
//END POINT CALL FOR ACCOUNT TOP
startTopUp(post){
var postData = {
uid: localStorage.getItem("uid"),
member_id: localStorage.getItem("member_id"),
sessionid: localStorage.getItem("session_token"),
action: 11062,
...post
};
return this.postAuxEnd("/starttopup", postData);
}
//END POINT CALL FOR SENDING REFERRAL MESSAGE
sendReferralMsg(postData){
return this.postAuxEnd("/sendreferral", postData);