Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaGer Keymanager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer Keymanager
Commits
7279fec8
Commit
7279fec8
authored
1 year ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
actually checking refund expiration
parent
caa7d8ba
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pass/app/Payment.js
+8
-0
8 additions, 0 deletions
pass/app/Payment.js
pass/app/Zammad.js
+50
-1
50 additions, 1 deletion
pass/app/Zammad.js
pass/config/default.json
+2
-1
2 additions, 1 deletion
pass/config/default.json
pass/routes/orders/refund.js
+10
-29
10 additions, 29 deletions
pass/routes/orders/refund.js
with
70 additions
and
31 deletions
pass/app/Payment.js
+
8
−
0
View file @
7279fec8
...
...
@@ -115,6 +115,14 @@ class Payment {
* @returns {boolean}
*/
isRefundAllowed
()
{
if
(
!
config
.
get
(
"
app.zammad.refund_enabled
"
))
{
return
false
;
}
// Check if Payment is older than 30 days
let
minDate
=
dayjs
().
add
(
-
30
,
"
days
"
);
if
(
this
.
created_at
.
isBefore
(
minDate
))
{
return
false
;
}
return
this
.
payment_processor
.
isRefundSupported
();
}
...
...
This diff is collapsed.
Click to expand it.
pass/app/Zammad.js
+
50
−
1
View file @
7279fec8
...
...
@@ -14,7 +14,7 @@ class Zammad {
static
async
CREATE_NOTIFICATION
(
token_amount
,
price
,
payment_method
)
{
// Check if notifications are turned on
try
{
if
(
config
.
get
(
"
app.zammad.enabled
"
))
{
if
(
config
.
get
(
"
app.zammad.
notification_
enabled
"
))
{
let
zammad_url
=
config
.
get
(
"
app.zammad.url
"
)
+
"
/api/v1/ticket_articles
"
;
let
zammad_data
=
{
...
...
@@ -48,6 +48,55 @@ class Zammad {
return
false
;
}
}
/**
* Creates a notification in the configured Zammad instance
*
* @param {string} message
*
* @returns {Promise<boolean>}
*/
static
async
CREATE_REFUND_TICKET
(
message
,
payment_reference_id
)
{
// Check if notifications are turned on
try
{
if
(
config
.
get
(
"
app.zammad.refund_enabled
"
))
{
let
zammad_url
=
config
.
get
(
"
app.zammad.url
"
)
+
"
/api/v1/tickets
"
;
let
subject
=
`Erstattung (
${
payment_reference_id
}
)`
;
let
zammad_data
=
{
"
title
"
:
subject
,
"
group
"
:
"
Tokens
"
,
"
customer_id
"
:
"
guess:noreply@metager.de
"
,
"
preferences
"
:
{
"
channel_id
"
:
3
},
"
article
"
:
{
"
type
"
:
"
note
"
,
"
sender
"
:
"
Customer
"
,
"
subject
"
:
subject
,
"
body
"
:
message
,
"
content_type
"
:
"
text/html
"
,
"
internal
"
:
false
}
}
return
fetch
(
zammad_url
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
"
Authorization
"
:
`Token
${
config
.
get
(
"
app.zammad.api_key
"
)}
`
},
body
:
JSON
.
stringify
(
zammad_data
)
}).
then
(
response
=>
{
return
true
;
}).
catch
(
e
=>
{
console
.
error
(
e
);
return
false
;
})
}
else
{
return
true
;
}
}
catch
(
e
)
{
console
.
error
(
e
);
return
false
;
}
}
}
module
.
exports
=
Zammad
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pass/config/default.json
+
2
−
1
View file @
7279fec8
...
...
@@ -23,7 +23,8 @@
"api_key"
:
"<OSTICKET_API_KEY>"
},
"zammad"
:
{
"enabled"
:
false
,
"notification_enabled"
:
false
,
"refund_enabled"
:
true
,
"url"
:
"<ZAMMAD_URL>"
,
"api_key"
:
"<ZAMMAD_API_KEY>"
,
"notification_ticket_id"
:
"0"
...
...
This diff is collapsed.
Click to expand it.
pass/routes/orders/refund.js
+
10
−
29
View file @
7279fec8
...
...
@@ -3,6 +3,7 @@ var router = express.Router({ mergeParams: true });
const
config
=
require
(
"
config
"
);
const
Key
=
require
(
"
../../app/Key
"
);
const
Zammad
=
require
(
"
../../app/Zammad
"
);
// Base URL: /key/:key/orders/:order/refund
router
.
use
(
"
/
"
,
(
req
,
res
,
next
)
=>
{
...
...
@@ -44,36 +45,16 @@ router.post("/", (req, res, next) => {
let
message
=
ejs
.
render
(
template
,
req
.
data
);
// No validation errors. Try to create a new Ticket
return
fetch
(
`
${
config
.
get
(
"
app.osticket.url
"
)}
/api/tickets.json`
,
{
method
:
"
post
"
,
headers
:
{
"
X-API-Key
"
:
config
.
get
(
"
app.osticket.api_key
"
),
"
Content-Type
"
:
"
application/json
"
,
},
body
:
JSON
.
stringify
({
alert
:
true
,
autorespond
:
false
,
source
:
"
API
"
,
name
:
"
Metzgermeister Unbekannt
"
,
email
:
"
no-reply@metager.de
"
,
subject
:
`MetaGer Schlüssel: Erstattung (
${
req
.
data
.
order
.
payment
.
public_id
}
)`
,
message
:
`data:text/html;charset=utf-8,
${
message
}
`
,
topicId
:
12
,
// ToDo change topic for english autoresponder
}),
return
Zammad
.
CREATE_REFUND_TICKET
(
message
,
req
.
data
.
order
.
payment
.
public_id
).
then
(
success
=>
{
if
(
success
)
{
return
Key
.
GET_KEY
(
req
.
data
.
key
.
key
.
get_key
(),
true
);
}
else
{
return
Promise
.
reject
(
"
Fehler beim Erstellen der Benachrichtigung,
"
);
}
}).
then
((
key
)
=>
{
key
.
discharge_key
(
req
.
data
.
order
.
refund
.
count
,
req
.
data
.
order
.
payment_reference
.
id
);
return
key
.
save
();
})
.
then
(
async
(
response
)
=>
{
if
(
response
.
status
!=
201
)
{
console
.
error
(
await
response
.
text
());
return
Promise
.
reject
(
"
Fehler beim Erstellen der Benachrichtigung,
"
);
}
else
{
return
Key
.
GET_KEY
(
req
.
data
.
key
.
key
.
get_key
(),
true
);
}
})
.
then
((
key
)
=>
{
key
.
discharge_key
(
req
.
data
.
order
.
refund
.
count
,
req
.
data
.
order
.
payment_reference
.
id
);
return
key
.
save
();
})
.
then
((
new_key
)
=>
{
req
.
data
.
key
.
key
=
new_key
;
req
.
data
.
order
.
refund
.
success
=
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment