Skip to content
Snippets Groups Projects
Commit d29cdaa7 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed PayPal payments

parent fc458c5c
No related branches found
No related tags found
No related merge requests found
...@@ -20,13 +20,20 @@ class Crypto { ...@@ -20,13 +20,20 @@ class Crypto {
} }
async private_key_get(seed_date, expiration_date) { async private_key_get(seed_date, expiration_date) {
let cache_key = "private_key_" + seed_date.format(this.#dayjs_format) + "_" + expiration_date.format(this.#dayjs_format); let cache_key =
console.log(cache_key); "private_key_" +
seed_date.format(this.#dayjs_format) +
"_" +
expiration_date.format(this.#dayjs_format);
// Check if the private key already exists in cache // Check if the private key already exists in cache
let cached_key = await this.#redis.get(cache_key); let cached_key = await this.#redis.get(cache_key);
let private_key = new NodeRSA(); let private_key = new NodeRSA();
if (cached_key === null) { if (cached_key === null) {
let seed = config.get("crypto.private_key.seed") + seed_date.format(this.#dayjs_format) + "_" + expiration_date.format(this.#dayjs_format); let seed =
config.get("crypto.private_key.seed") +
seed_date.format(this.#dayjs_format) +
"_" +
expiration_date.format(this.#dayjs_format);
let sha512 = md.sha512.create(); let sha512 = md.sha512.create();
sha512.update(seed); sha512.update(seed);
seed = sha512.digest().toHex(); seed = sha512.digest().toHex();
...@@ -58,13 +65,20 @@ class Crypto { ...@@ -58,13 +65,20 @@ class Crypto {
return private_key; return private_key;
} }
async validateMetaGerPassCode(generation_month, expiration_month, metager_pass_codes) { async validateMetaGerPassCode(
generation_month,
expiration_month,
metager_pass_codes
) {
// Check if codes are expired // Check if codes are expired
if (!this.#dayjs().isBefore(expiration_month, "month")) { if (!this.#dayjs().isBefore(expiration_month, "month")) {
return Promise.reject("Redeem Codes are expired."); return Promise.reject("Redeem Codes are expired.");
} }
let private_key = await this.private_key_get(generation_month, expiration_month); let private_key = await this.private_key_get(
generation_month,
expiration_month
);
let uuid_regexExp = let uuid_regexExp =
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi; /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
......
...@@ -33,6 +33,19 @@ class Order { ...@@ -33,6 +33,19 @@ class Order {
return 50; return 50;
} }
static GET_ORDER_FILE_BASE_PATH(order_date) {
let order_path = config.get("storage.data_path");
if (process.env.NODE_ENV === "development") {
order_path = path.join(order_path, "development");
}
order_path = path.join(
order_path,
order_date.format("YYYY"),
order_date.format("MM")
);
return order_path;
}
/** /**
* Data stored in Redis Database * Data stored in Redis Database
*/ */
...@@ -67,15 +80,7 @@ class Order { ...@@ -67,15 +80,7 @@ class Order {
this.#expires_at = dayjs(expires_at); this.#expires_at = dayjs(expires_at);
this.#order_date = dayjs.unix(this.#order_id.substr(0, 10)); this.#order_date = dayjs.unix(this.#order_id.substr(0, 10));
this.#order_path = config.get("storage.data_path"); this.#order_path = Order.GET_ORDER_FILE_BASE_PATH(this.#order_date);
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")
);
this.#amount = parseInt(amount); this.#amount = parseInt(amount);
this.#unit_size = parseInt(unit_size); this.#unit_size = parseInt(unit_size);
...@@ -167,13 +172,14 @@ class Order { ...@@ -167,13 +172,14 @@ class Order {
let redis_key = Order.STORAGE_KEY_PREFIX + order_id; 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) => { redis_client.hgetall(redis_key).then((order_data) => {
if (Object.keys(order_data).length === 0) { if (Object.keys(order_data).length === 0) {
// Checking FS for order // Checking FS for order
let order_date = dayjs.unix(order_id.substr(0, 10));
let order_file = path.join(
Order.GET_ORDER_FILE_BASE_PATH(order_date),
this.#order_id.toString() + ".json"
);
let fs = require("fs"); let fs = require("fs");
if (fs.existsSync(order_file)) { if (fs.existsSync(order_file)) {
order_data = JSON.parse(fs.readFileSync(order_file)); order_data = JSON.parse(fs.readFileSync(order_file));
...@@ -196,7 +202,6 @@ class Order { ...@@ -196,7 +202,6 @@ class Order {
); );
} }
loaded_order.set_create_mode(false); loaded_order.set_create_mode(false);
console.log(loaded_order.getEncryptedSalesReceipts());
resolve(loaded_order); resolve(loaded_order);
}); });
}); });
......
...@@ -6,45 +6,8 @@ ...@@ -6,45 +6,8 @@
"data_path": "/data" "data_path": "/data"
}, },
"keys": { "keys": {
"charset": [ "length": 8,
"a", "charset": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"length": 8
}, },
"crypto": { "crypto": {
"hmac_integrity_seed": "<insert_secret_for_hmac_seed>", "hmac_integrity_seed": "<insert_secret_for_hmac_seed>",
......
...@@ -63,6 +63,8 @@ function execute_payment_paypal(encrypted_sales_receipts) { ...@@ -63,6 +63,8 @@ function execute_payment_paypal(encrypted_sales_receipts) {
}, },
body: JSON.stringify({ body: JSON.stringify({
order_id: document.querySelector("input[name=order_id]").value, order_id: document.querySelector("input[name=order_id]").value,
expires_at: document.querySelector("input[name=expires_at]")
.value,
amount: document.querySelector("input[name=amount]").value, amount: document.querySelector("input[name=amount]").value,
unit_size: document.querySelector("input[name=unit_size]") unit_size: document.querySelector("input[name=unit_size]")
.value, .value,
...@@ -110,6 +112,7 @@ function cancelPayment(encrypted_sales_receipts) { ...@@ -110,6 +112,7 @@ function cancelPayment(encrypted_sales_receipts) {
}, },
body: JSON.stringify({ body: JSON.stringify({
order_id: document.querySelector("input[name=order_id]").value, order_id: document.querySelector("input[name=order_id]").value,
expires_at: document.querySelector("input[name=expires_at]").value,
amount: document.querySelector("input[name=amount]").value, amount: document.querySelector("input[name=amount]").value,
unit_size: document.querySelector("input[name=unit_size]").value, unit_size: document.querySelector("input[name=unit_size]").value,
price_per_unit: document.querySelector("input[name=price_per_unit]") price_per_unit: document.querySelector("input[name=price_per_unit]")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment