diff --git a/pass/app/Crypto.js b/pass/app/Crypto.js index af4533d23f66d0ce0d49672546b5f8d1dbe7f9f9..0dd03b82d82bc336636daea8b6c546f71b23dc1e 100644 --- a/pass/app/Crypto.js +++ b/pass/app/Crypto.js @@ -20,13 +20,20 @@ class Crypto { } 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); - console.log(cache_key); + let 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 let cached_key = await this.#redis.get(cache_key); let private_key = new NodeRSA(); 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(); sha512.update(seed); seed = sha512.digest().toHex(); @@ -58,13 +65,20 @@ class Crypto { 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 if (!this.#dayjs().isBefore(expiration_month, "month")) { 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 = /^[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; diff --git a/pass/app/Order.js b/pass/app/Order.js index 156acd29edbbae744228d8e9c0f2aa2dc82ce073..fcca840583e2b9af23aefabd13d82b20234f7f13 100644 --- a/pass/app/Order.js +++ b/pass/app/Order.js @@ -33,6 +33,19 @@ class Order { 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 */ @@ -67,15 +80,7 @@ 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") - ); + this.#order_path = Order.GET_ORDER_FILE_BASE_PATH(this.#order_date); this.#amount = parseInt(amount); this.#unit_size = parseInt(unit_size); @@ -167,13 +172,14 @@ 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) { // 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"); if (fs.existsSync(order_file)) { order_data = JSON.parse(fs.readFileSync(order_file)); @@ -196,7 +202,6 @@ class Order { ); } loaded_order.set_create_mode(false); - console.log(loaded_order.getEncryptedSalesReceipts()); resolve(loaded_order); }); }); diff --git a/pass/config/default.json b/pass/config/default.json index db5328c67858930255b802673a2d94774103e413..7de70918a296560acc289518c3852f74c6f89c07 100644 --- a/pass/config/default.json +++ b/pass/config/default.json @@ -6,45 +6,8 @@ "data_path": "/data" }, "keys": { - "charset": [ - "a", - "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 + "length": 8, + "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"] }, "crypto": { "hmac_integrity_seed": "<insert_secret_for_hmac_seed>", diff --git a/pass/resources/js/checkout_paypal.js b/pass/resources/js/checkout_paypal.js index 64147e13ed0afe2b17ec0357819293d3263fed49..19a5be6d6ace2ae43b9c563e5d61777074a063f6 100644 --- a/pass/resources/js/checkout_paypal.js +++ b/pass/resources/js/checkout_paypal.js @@ -63,6 +63,8 @@ function execute_payment_paypal(encrypted_sales_receipts) { }, body: JSON.stringify({ 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, unit_size: document.querySelector("input[name=unit_size]") .value, @@ -110,6 +112,7 @@ function cancelPayment(encrypted_sales_receipts) { }, body: JSON.stringify({ 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, unit_size: document.querySelector("input[name=unit_size]").value, price_per_unit: document.querySelector("input[name=price_per_unit]")