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
06cac29e
Commit
06cac29e
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
storing order data on disk when payment is complete
parent
9b24a8bb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
build/pass/Dockerfile
+8
-0
8 additions, 0 deletions
build/pass/Dockerfile
docker-compose.yml
+4
-3
4 additions, 3 deletions
docker-compose.yml
pass/app/Order.js
+54
-14
54 additions, 14 deletions
pass/app/Order.js
with
66 additions
and
17 deletions
build/pass/Dockerfile
0 → 100644
+
8
−
0
View file @
06cac29e
FROM
node:19-bullseye
VOLUME
["/data"]
RUN
mkdir
/data
&&
chown
1000:1000 /data
USER
1000
CMD
[ "bash", "-c", "npm i && npm run dev"]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
docker-compose.yml
+
4
−
3
View file @
06cac29e
...
...
@@ -3,17 +3,18 @@ version: '3'
volumes
:
nodecache
:
{}
redisdata
:
{}
mgpassdata
:
{}
services
:
express
:
image
:
node:19-bullseye
command
:
bash -c "npm i && npm run dev"
user
:
1000:1000
build
:
context
:
./build/pass
environment
:
-
NODE_ENV=development
working_dir
:
/app
volumes
:
-
./pass:/app
-
mgpassdata:/data
ports
:
-
8080:3000
redis
:
...
...
This diff is collapsed.
Click to expand it.
pass/app/Order.js
+
54
−
14
View file @
06cac29e
const
config
=
require
(
"
config
"
);
const
Crypto
=
require
(
"
./Crypto
"
);
const
dayjs
=
require
(
"
dayjs
"
);
const
path
=
require
(
"
path
"
);
class
Order
{
static
get
STORAGE_KEY_PREFIX
()
{
...
...
@@ -44,6 +45,7 @@ class Order {
* Data populated by context
*/
#order_date
;
#order_path
;
#create_mode
;
#redis_client
;
...
...
@@ -60,6 +62,17 @@ class Order {
this
.
#expires_at
=
dayjs
(
expires_at
);
this
.
#order_date
=
dayjs
.
unix
(
this
.
#order_id
.
substr
(
0
,
10
));
this
.
#order_path
=
config
.
get
(
"
storage.data_path
"
);
if
(
process
.
env
.
NODE_ENV
===
"
development
"
)
{
this
.
#order_path
=
path
.
join
(
this
.
#order_path
,
"
development
"
);
}
this
.
#order_path
=
path
.
join
(
this
.
#order_path
,
this
.
#order_date
.
format
(
"
YYYY
"
),
this
.
#order_date
.
format
(
"
MM
"
),
"
orders
"
);
this
.
#amount
=
parseInt
(
amount
);
this
.
#unit_size
=
parseInt
(
unit_size
);
this
.
#price_per_unit
=
parseFloat
(
price_per_unit
);
...
...
@@ -130,9 +143,20 @@ class Order {
});
let
redis_key
=
Order
.
STORAGE_KEY_PREFIX
+
order_id
;
let
order_file
=
path
.
join
(
this
.
#order_path
,
this
.
#order_id
.
toString
()
+
"
.json
"
);
redis_client
.
hgetall
(
redis_key
).
then
((
order_data
)
=>
{
if
(
Object
.
keys
(
order_data
).
length
===
0
)
{
return
reject
(
"
Could not find Order in our database!
"
);
// Checking FS for order
let
fs
=
require
(
"
fs
"
);
if
(
fs
.
existsSync
(
order_file
))
{
order_data
=
JSON
.
parse
(
fs
.
readFileSync
(
order_file
));
}
else
{
return
reject
(
"
Could not find Order in our database! Checking FS
"
);
}
}
let
loaded_order
=
new
Order
(
order_data
.
order_id
,
...
...
@@ -169,21 +193,20 @@ class Order {
if
(
this
.
#create_mode
&&
key_exists
)
{
return
Promise
.
reject
(
"
Cannot create a Order that already exists!
"
);
}
let
stored_data
=
{
order_id
:
this
.
#order_id
,
expires_at
:
this
.
#expires_at
.
format
(
"
YYYY-MM-DD
"
),
amount
:
this
.
#amount
,
unit_size
:
this
.
#unit_size
,
price_per_unit
:
this
.
#price_per_unit
,
encrypted_sales_receipts
:
JSON
.
stringify
(
this
.
#encrypted_sales_receipts
),
signatures
:
JSON
.
stringify
(
this
.
#signatures
),
payment_completed
:
this
.
#payment_completed
,
payment_method_link
:
JSON
.
stringify
(
this
.
#payment_method_link
),
};
let
storage_promise
=
this
.
#redis_client
.
hmset
(
redis_key
,
{
order_id
:
this
.
#order_id
,
expires_at
:
this
.
#expires_at
.
format
(
"
YYYY-MM-DD
"
),
amount
:
this
.
#amount
,
unit_size
:
this
.
#unit_size
,
price_per_unit
:
this
.
#price_per_unit
,
encrypted_sales_receipts
:
JSON
.
stringify
(
this
.
#encrypted_sales_receipts
),
signatures
:
JSON
.
stringify
(
this
.
#signatures
),
payment_completed
:
this
.
#payment_completed
,
payment_method_link
:
JSON
.
stringify
(
this
.
#payment_method_link
),
})
.
hmset
(
redis_key
,
stored_data
)
.
then
((
result
)
=>
{
this
.
#create_mode
=
false
;
})
...
...
@@ -192,6 +215,23 @@ class Order {
});
await
storage_promise
;
// If the Order payment is completed store the order additionally directly to harddisk
let
fs
=
require
(
"
fs
"
);
let
order_file
=
path
.
join
(
this
.
#order_path
,
this
.
#order_id
.
toString
()
+
"
.json
"
);
// Create directory if it does not exist
if
(
!
fs
.
existsSync
(
path
.
dirname
(
order_file
)))
{
fs
.
mkdirSync
(
path
.
dirname
(
order_file
),
{
recursive
:
true
});
}
storage_promise
=
fs
.
writeFileSync
(
order_file
,
JSON
.
stringify
(
stored_data
,
null
,
4
)
);
await
storage_promise
;
}
async
delete
()
{
...
...
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