Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
ivrnet_payment
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad
ivrnet_payment
Commits
bd6f9d5b
Commit
bd6f9d5b
authored
Dec 01, 2023
by
Bilal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added logic to check invoice status
parent
7192500a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
8 deletions
+80
-8
src/component/PrimaryButton.jsx
src/component/PrimaryButton.jsx
+3
-3
src/component/Telepay.js
src/component/Telepay.js
+63
-5
src/server.js
src/server.js
+14
-0
No files found.
src/component/PrimaryButton.jsx
View file @
bd6f9d5b
...
@@ -2,9 +2,9 @@ import PropTypes from 'prop-types';
...
@@ -2,9 +2,9 @@ import PropTypes from 'prop-types';
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
'
./style.css
'
;
import
'
./style.css
'
;
export
const
PrimaryButton
=
({
label
=
'
Label
'
,
submitt
ed
=
false
})
=>
{
export
const
PrimaryButton
=
({
label
=
'
Label
'
,
disabl
ed
=
false
})
=>
{
return
(
return
(
<
button
disabled=
{
submitt
ed
}
className=
'primary-button'
type=
{
'
submit
'
}
>
<
button
disabled=
{
disabl
ed
}
className=
'primary-button'
type=
{
'
submit
'
}
>
<
div
>
{
label
}
</
div
>
<
div
>
{
label
}
</
div
>
</
button
>
</
button
>
);
);
...
@@ -13,5 +13,5 @@ export const PrimaryButton = ({ label = 'Label', submitted = false }) => {
...
@@ -13,5 +13,5 @@ export const PrimaryButton = ({ label = 'Label', submitted = false }) => {
PrimaryButton
.
propTypes
=
{
PrimaryButton
.
propTypes
=
{
label
:
PropTypes
.
string
,
label
:
PropTypes
.
string
,
onClick
:
PropTypes
.
func
,
onClick
:
PropTypes
.
func
,
submitt
ed
:
PropTypes
.
bool
,
disabl
ed
:
PropTypes
.
bool
,
};
};
src/component/Telepay.js
View file @
bd6f9d5b
...
@@ -10,6 +10,7 @@ import { CloseOutlined } from '@mui/icons-material';
...
@@ -10,6 +10,7 @@ import { CloseOutlined } from '@mui/icons-material';
export
const
Telepay
=
()
=>
{
export
const
Telepay
=
()
=>
{
const
[
error
,
setError
]
=
useState
(
null
);
const
[
error
,
setError
]
=
useState
(
null
);
const
[
success
,
setSuccess
]
=
useState
(
null
);
const
[
success
,
setSuccess
]
=
useState
(
null
);
const
[
invoiceStatus
,
setInvoiceStatus
]
=
useState
(
null
);
const
[
submitted
,
setSubmitted
]
=
React
.
useState
(
false
);
const
[
submitted
,
setSubmitted
]
=
React
.
useState
(
false
);
const
[
errorSnackbarOpen
,
setErrorSnackbarOpen
]
=
React
.
useState
(
false
);
const
[
errorSnackbarOpen
,
setErrorSnackbarOpen
]
=
React
.
useState
(
false
);
const
[
formData
,
setFormData
]
=
useState
({
const
[
formData
,
setFormData
]
=
useState
({
...
@@ -44,6 +45,10 @@ export const Telepay = () => {
...
@@ -44,6 +45,10 @@ export const Telepay = () => {
});
});
};
};
const
submitButtonText
=
()
=>
{
return
success
===
null
?
'
SUBMIT
'
:
'
CHECK STATUS
'
;
};
const
handleDeleteLineItem
=
(
index
)
=>
{
const
handleDeleteLineItem
=
(
index
)
=>
{
if
(
formData
.
line_items
.
length
<=
1
)
{
if
(
formData
.
line_items
.
length
<=
1
)
{
setError
(
'
1 line item is needed
'
);
setError
(
'
1 line item is needed
'
);
...
@@ -69,8 +74,37 @@ export const Telepay = () => {
...
@@ -69,8 +74,37 @@ export const Telepay = () => {
const
handleSubmit
=
async
(
e
)
=>
{
const
handleSubmit
=
async
(
e
)
=>
{
setSubmitted
(
true
);
setSubmitted
(
true
);
e
.
preventDefault
();
e
.
preventDefault
();
console
.
log
(
formData
);
if
(
success
===
null
)
{
await
submitInvoice
();
}
else
{
await
checkInvoiceStatus
();
}
};
const
checkInvoiceStatus
=
async
()
=>
{
try
{
const
response
=
await
fetch
(
`https://callback-click2pay.ivrnet.com/callback/invoices/
${
success
.
invoice_id
}
`
,
{
method
:
'
GET
'
});
if
(
response
.
ok
)
{
const
responseData
=
await
response
.
json
();
setInvoiceStatus
(
responseData
);
}
else
{
const
errorData
=
await
response
.
json
();
setError
(
errorData
.
error
||
'
An error occurred
'
);
setErrorSnackbarOpen
(
true
);
}
}
catch
(
error
)
{
setError
(
'
An error occurred while making the API request
'
);
setErrorSnackbarOpen
(
true
);
}
finally
{
setSubmitted
(
false
);
}
};
const
submitInvoice
=
async
()
=>
{
try
{
try
{
const
response
=
await
fetch
(
'
https://callback-click2pay.ivrnet.com/callback/post_data/
'
,
{
const
response
=
await
fetch
(
'
https://callback-click2pay.ivrnet.com/callback/post_data/
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
...
@@ -95,6 +129,7 @@ export const Telepay = () => {
...
@@ -95,6 +129,7 @@ export const Telepay = () => {
setSubmitted
(
false
);
setSubmitted
(
false
);
}
}
};
};
return
(
return
(
<
form
onSubmit
=
{
handleSubmit
}
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
Snackbar
<
Snackbar
...
@@ -245,12 +280,35 @@ export const Telepay = () => {
...
@@ -245,12 +280,35 @@ export const Telepay = () => {
<
/div
>
<
/div
>
<
a
className
=
'
add-product-link
'
onClick
=
{
handleAddProduct
}
>
Add
another
product
<
/a
>
<
a
className
=
'
add-product-link
'
onClick
=
{
handleAddProduct
}
>
Add
another
product
<
/a
>
<
/div
>
<
/div
>
{
success
&&
(
<
div
className
=
'
alert alert-primary w-100
'
role
=
'
alert
'
>
{(
success
||
invoiceStatus
)
&&
(
Access
Code
:
{
success
.
access_code
}
<
div
className
=
{
'
d-flex flex-column w-100 gap-3
'
}
>
{
success
&&
(
<
React
.
Fragment
>
<
div
className
=
'
alert alert-primary w-100 m-0 p-0
'
role
=
'
alert
'
>
<
div
>
Access
Code
:
{
success
.
access_code
}
<
/div
>
<
/div
>
<
div
className
=
'
alert alert-primary w-100 m-0 p-0
'
role
=
'
alert
'
>
<
div
>
Invoice
Number
:
{
success
.
invoice_id
}
<
/div
>
<
/div
>
<
/React.Fragment
>
)}
{
invoiceStatus
&&
parseFloat
(
invoiceStatus
.
total_amount
)
===
0
&&
(
<
div
className
=
'
alert alert-primary w-100 m-0 p-0
'
role
=
'
alert
'
>
<
div
>
Status
:
Fully
Paid
<
/div
>
<
/div
>
)}
{
invoiceStatus
&&
parseFloat
(
invoiceStatus
.
total_amount
)
!==
0
&&
(
<
div
className
=
'
alert alert-primary w-100 m-0 p-0
'
role
=
'
alert
'
>
<
div
>
Pending
Amount
:
{
invoiceStatus
.
total_amount
}
<
/div
>
<
/div
>
)}
<
/div
>
<
/div
>
)}
)}
<
PrimaryButton
label
=
'
SUBMIT
'
submitt
ed
=
{
submitted
}
/
>
<
PrimaryButton
label
=
{
submitButtonText
()}
disabl
ed
=
{
submitted
}
/
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
<
/form
>
<
/form
>
...
...
src/server.js
View file @
bd6f9d5b
...
@@ -25,6 +25,20 @@ app.post('/api/data', async (req, res) => {
...
@@ -25,6 +25,20 @@ app.post('/api/data', async (req, res) => {
}
}
});
});
app
.
get
(
'
/api/invoices/:id
'
,
async
(
req
,
res
)
=>
{
try
{
const
basicAuthHeader
=
'
Basic
'
+
btoa
(
'
test23:password
'
);
const
response
=
await
axios
.
get
(
`https://central-staging.ivrnet.com/api/v1/invoices/
${
req
.
params
.
id
}
`
,
{
headers
:
{
'
Authorization
'
:
basicAuthHeader
,
},
});
res
.
json
(
response
.
data
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
error
:
error
?.
response
?.
data
?.
error
||
'
Internal server error
'
});
}
});
app
.
listen
(
port
,
()
=>
{
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server is running on port
${
port
}
`
);
console
.
log
(
`Server is running on port
${
port
}
`
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment