From 37347abfe1bae551c705bbfe1f51ee41f3e66cec Mon Sep 17 00:00:00 2001
From: Revenor
Date: Mon, 7 Mar 2022 17:55:59 +0000
Subject: [PATCH 01/15] chore: Cleaned up a bit of the code.
---
src/Middlewares/EnsureAdmin.ts | 12 ++++++------
src/Middlewares/EnsureAuth.ts | 2 +-
src/Plugins/PluginHandler.ts | 6 ++----
src/Server/Server.ts | 4 +++-
src/Translation/GetText.ts | 6 ++++--
src/Translation/en/Lang_en.ts | 6 +++---
src/Translation/sv/Lang_sv.ts | 6 +++---
7 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/src/Middlewares/EnsureAdmin.ts b/src/Middlewares/EnsureAdmin.ts
index e8080a7f..0199cc9b 100644
--- a/src/Middlewares/EnsureAdmin.ts
+++ b/src/Middlewares/EnsureAdmin.ts
@@ -37,13 +37,13 @@ export default function EnsureAdmin(eR = false)
password = login.split(":")[1];
login = login.split(":")[0];
}
-
- eR ? null : Logger.warning(`Authoring admin with username: ${login}`);
+
+ !eR ? Logger.warning(`Authoring admin with username: ${login}`) : null;
const match = bcrypt.compare(password, (CacheAdmin.get(getAdminByUsername(login) ?? "ADM_")?.["password"]) ?? "")
if(!match)
{
- eR ? null : Logger.warning(`Authorization failed for admin with username: ${login}`);
+ !eR ? Logger.warning(`Authorization failed for admin with username: ${login}`) : null;
return eR ? Promise.resolve(false) : APIError("Unauthorized admin", 403)(res);
}
@@ -53,7 +53,7 @@ export default function EnsureAdmin(eR = false)
if(b64auth[0].toLocaleLowerCase() === "bearer")
{
const token = (Buffer.isBuffer(b64auth[1]) ? Buffer.from(b64auth[1], 'base64') : b64auth[1]).toString();
- eR ? null : Logger.warning(`Authoring admin with token: ${token}`);
+ !eR ? Logger.warning(`Authoring admin with token: ${token}`) : null;
try
{
@@ -61,11 +61,11 @@ export default function EnsureAdmin(eR = false)
if(!payload)
{
- eR ? null : Logger.warning(`Authorization failed for admin with token: ${token}`);
+ !eR ? Logger.warning(`Authorization failed for admin with token: ${token}`) : null;
return eR ? Promise.resolve(false) : APIError("Unauthorized admin", 403)(res);
}
- eR ? null : Logger.warning(`Authorized admin with token: ${token}`);
+ eR ? Logger.warning(`Authorized admin with token: ${token}`) : null;
return eR ? Promise.resolve(true) : next?.();
}
diff --git a/src/Middlewares/EnsureAuth.ts b/src/Middlewares/EnsureAuth.ts
index d8d812f9..0a6296ab 100644
--- a/src/Middlewares/EnsureAuth.ts
+++ b/src/Middlewares/EnsureAuth.ts
@@ -56,7 +56,7 @@ export default function EnsureAuth(eR = false)
//@ts-ignore
req.customer = payload.data;
// @ts-ignore
- eR ? null : Logger.api(`Authorizing`, payload.data);
+ !eR ? Logger.api(`Authorizing`, payload.data) : null;
return eR ? Promise.resolve(true) : next?.();
}
diff --git a/src/Plugins/PluginHandler.ts b/src/Plugins/PluginHandler.ts
index 5a1e3dab..5d8cd5fc 100644
--- a/src/Plugins/PluginHandler.ts
+++ b/src/Plugins/PluginHandler.ts
@@ -1,5 +1,5 @@
import Logger from "../Lib/Logger";
-import { Plugins } from "../Config";
+import {Plugins} from "../Config";
import npm from "npm";
import fs from "fs";
import GetText from "../Translation/GetText";
@@ -68,8 +68,6 @@ export function isPluginInstalled(plugin: string)
export function getPlugins()
{
// get all installed npm packages
- const packages = Plugins;
// get plugins starting with cpg-plugin
- const plugins = packages.filter(p => p.startsWith("cpg-plugin"));
- return plugins;
+ return Plugins.filter(p => p.startsWith("cpg-plugin"));
}
\ No newline at end of file
diff --git a/src/Server/Server.ts b/src/Server/Server.ts
index 6337186b..ebb70ab9 100644
--- a/src/Server/Server.ts
+++ b/src/Server/Server.ts
@@ -1,3 +1,5 @@
+// noinspection JSUnusedLocalSymbols
+
import express from "express";
import cors from "cors";
import session from "express-session";
@@ -6,7 +8,7 @@ import { Default_Language, Express_Session_Secret, Full_Domain, PORT } from "../
import Logger from "../Lib/Logger";
import RouteHandler from "../Handlers/Route.handler";
import { reCache } from "../Cache/reCache";
-import { ICustomer } from "../Interfaces/Customer.interface";
+import { ICustomer } from "@interface/Customer.interface";
import { APIError } from "../Lib/Response";
import ApolloServer from "../Database/GraphQL/ApolloServer";
import GetText from "../Translation/GetText";
diff --git a/src/Translation/GetText.ts b/src/Translation/GetText.ts
index c03ad40b..0005b54e 100644
--- a/src/Translation/GetText.ts
+++ b/src/Translation/GetText.ts
@@ -1,6 +1,8 @@
+// noinspection JSValidateJSDoc
+
import { Default_Language } from "../Config";
-import { IAllLanguages } from "../Interfaces/Lang/AllLang.interface";
-import { IGetText } from "../Interfaces/Lang/GetText.interface";
+import { IAllLanguages } from "@interface/Lang/AllLang.interface";
+import { IGetText } from "@interface/Lang/GetText.interface";
export default (lang: keyof IAllLanguages = Default_Language): IGetText =>
{
diff --git a/src/Translation/en/Lang_en.ts b/src/Translation/en/Lang_en.ts
index 1dbe9ca7..3ba07971 100644
--- a/src/Translation/en/Lang_en.ts
+++ b/src/Translation/en/Lang_en.ts
@@ -1,7 +1,7 @@
import { Request } from "express";
-import { ICustomer } from "../../Interfaces/Customer.interface";
-import { IGetText } from "../../Interfaces/Lang/GetText.interface";
-import { IOrder } from "../../Interfaces/Orders.interface";
+import { ICustomer } from "@interface/Customer.interface";
+import { IGetText } from "@interface/Lang/GetText.interface";
+import { IOrder } from "@interface/Orders.interface";
export = {
txt_Uid_Description: "Unique ID for object, generated by the system.",
diff --git a/src/Translation/sv/Lang_sv.ts b/src/Translation/sv/Lang_sv.ts
index fa02d830..2ecb490b 100644
--- a/src/Translation/sv/Lang_sv.ts
+++ b/src/Translation/sv/Lang_sv.ts
@@ -1,7 +1,7 @@
import { Request } from "express";
-import { ICustomer } from "../../Interfaces/Customer.interface";
-import { IGetText } from "../../Interfaces/Lang/GetText.interface";
-import { IOrder } from "../../Interfaces/Orders.interface";
+import { ICustomer } from "@interface/Customer.interface";
+import { IGetText } from "@interface/Lang/GetText.interface";
+import { IOrder } from "@interface/Orders.interface";
export = {
txt_Uid_Description: "Unique ID for object, generated by the system.",
From 4249202606843afcf524e00e3b6bda744935a5a5 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 19:36:36 +0100
Subject: [PATCH 02/15] docs: :memo: Better typings
---
src/Payments/Currencies/Paypal.currencies.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Payments/Currencies/Paypal.currencies.ts b/src/Payments/Currencies/Paypal.currencies.ts
index de4c6373..eaf5aa27 100644
--- a/src/Payments/Currencies/Paypal.currencies.ts
+++ b/src/Payments/Currencies/Paypal.currencies.ts
@@ -33,7 +33,7 @@ const data = {
export const PaypalCurrencies = data.currencies;
-export function validCurrencyPaypal(currency: typeof data["currencies"])
+export function validCurrencyPaypal(currency: typeof PaypalCurrencies)
{
// @ts-ignore
return data.currencies.includes(currency);
From eb7e01568e91f785c4f7d1372c29fba24d21b611 Mon Sep 17 00:00:00 2001
From: Revenor
Date: Mon, 7 Mar 2022 18:54:28 +0000
Subject: [PATCH 03/15] feat: Added a currency symbol function.
BREAKING CHANGE: Customer Modal importing issues
---
src/Types/PaymentTypes.ts | 203 +++++++++++++++++++++++++++++++++++++-
1 file changed, 198 insertions(+), 5 deletions(-)
diff --git a/src/Types/PaymentTypes.ts b/src/Types/PaymentTypes.ts
index 688f23a9..2e8ff39b 100644
--- a/src/Types/PaymentTypes.ts
+++ b/src/Types/PaymentTypes.ts
@@ -1,8 +1,201 @@
export type TPaymentTypes = "one_time" | "recurring" | "free";
export const A_PaymentTypes = ["one_time", "recurring", "free"] as const;
-// Every currencie code is in ISO 4217
-export type TPaymentCurrency = "usd" | "eur" | "gbp" | "cad" | "aud" | "jpy" | "nzd" | "chf" | "sek" | "dkk" | "nok" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb" | "eur" | "zar" | "brl" | "rub" | "krw" | "ils" | "php" | "vnd" | "myr" | "idr" | "cny" | "twd" | "huf" | "czk" | "pln" | "hkd" | "sgd" | "thb";
-export const A_PaymentCurrency = [
- "usd", "eur", "gbp", "cad", "aud", "jpy", "nzd", "chf", "sek", "dkk", "nok", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb", "eur", "zar", "brl", "rub", "krw", "ils", "php", "vnd", "myr", "idr", "cny", "twd", "huf", "czk", "pln", "hkd", "sgd", "thb"
-] as const;
\ No newline at end of file
+// Every currency's code is in ISO 4217
+export type TPaymentCurrency =
+ "AED"
+ | "AFN"
+ | "ALL"
+ | "AMD"
+ | "ANG"
+ | "AOA"
+ | "ARS"
+ | "AUD"
+ | "AWG"
+ | "AZN"
+ | "BAM"
+ | "BBD"
+ | "BDT"
+ | "BGN"
+ | "BHD"
+ | "BIF"
+ | "BMD"
+ | "BND"
+ | "BOB"
+ | "BOV"
+ | "BRL"
+ | "BSD"
+ | "BTN"
+ | "BWP"
+ | "BYR"
+ | "BZD"
+ | "CAD"
+ | "CDF"
+ | "CHE"
+ | "CHF"
+ | "CHW"
+ | "CLF"
+ | "CLP"
+ | "CNY"
+ | "COP"
+ | "COU"
+ | "CRC"
+ | "CUC"
+ | "CUP"
+ | "CVE"
+ | "CZK"
+ | "DJF"
+ | "DKK"
+ | "DOP"
+ | "DZD"
+ | "EGP"
+ | "ERN"
+ | "ETB"
+ | "EUR"
+ | "FJD"
+ | "FKP"
+ | "GBP"
+ | "GEL"
+ | "GHS"
+ | "GIP"
+ | "GMD"
+ | "GNF"
+ | "GTQ"
+ | "GYD"
+ | "HKD"
+ | "HNL"
+ | "HRK"
+ | "HTG"
+ | "HUF"
+ | "IDR"
+ | "ILS"
+ | "INR"
+ | "IQD"
+ | "IRR"
+ | "ISK"
+ | "JMD"
+ | "JOD"
+ | "JPY"
+ | "KES"
+ | "KGS"
+ | "KHR"
+ | "KMF"
+ | "KPW"
+ | "KRW"
+ | "KWD"
+ | "KYD"
+ | "KZT"
+ | "LAK"
+ | "LBP"
+ | "LKR"
+ | "LRD"
+ | "LSL"
+ | "LTL"
+ | "LVL"
+ | "LYD"
+ | "MAD"
+ | "MDL"
+ | "MGA"
+ | "MKD"
+ | "MMK"
+ | "MNT"
+ | "MOP"
+ | "MRO"
+ | "MUR"
+ | "MVR"
+ | "MWK"
+ | "MXN"
+ | "MXV"
+ | "MYR"
+ | "MZN"
+ | "NAD"
+ | "NGN"
+ | "NIO"
+ | "NOK"
+ | "NPR"
+ | "NZD"
+ | "OMR"
+ | "PAB"
+ | "PEN"
+ | "PGK"
+ | "PHP"
+ | "PKR"
+ | "PLN"
+ | "PYG"
+ | "QAR"
+ | "RON"
+ | "RSD"
+ | "RUB"
+ | "RWF"
+ | "SAR"
+ | "SBD"
+ | "SCR"
+ | "SDG"
+ | "SEK"
+ | "SGD"
+ | "SHP"
+ | "SLL"
+ | "SOS"
+ | "SRD"
+ | "SSP"
+ | "STD"
+ | "SYP"
+ | "SZL"
+ | "THB"
+ | "TJS"
+ | "TMT"
+ | "TND"
+ | "TOP"
+ | "TRY"
+ | "TTD"
+ | "TWD"
+ | "TZS"
+ | "UAH"
+ | "UGX"
+ | "USD"
+ | "USN"
+ | "USS"
+ | "UYI"
+ | "UYU"
+ | "UZS"
+ | "VEF"
+ | "VND"
+ | "VUV"
+ | "WST"
+ | "XAF"
+ | "XAG"
+ | "XAU"
+ | "XBA"
+ | "XBB"
+ | "XBC"
+ | "XBD"
+ | "XCD"
+ | "XDR"
+ | "XFU"
+ | "XOF"
+ | "XPD"
+ | "XPF"
+ | "XPT"
+ | "XTS"
+ | "XXX"
+ | "YER"
+ | "ZAR"
+ | "ZMW";
+
+
+export const currencyCodes = ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "USS", "UYI", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XFU", "XOF", "XPD", "XPF", "XPT", "XTS", "XXX", "YER", "ZAR", "ZMW"];
+
+
+// Create an ENUM using the currencycodes above. Have the symbol of the currency as the value
+export function GetCurrencySymbol(code: TPaymentCurrency)
+{
+ return (0).toLocaleString(
+ "en-us",
+ {
+ style: 'currency',
+ currency: code,
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0
+ }
+ ).replace(/\d/g, '').trim()
+}
From 7841e3cfc7189e465b2377b00abcca3178564121 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 20:15:33 +0100
Subject: [PATCH 04/15] fix: :zap: Fixed unsed imports
---
src/Payments/Paypal.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Payments/Paypal.ts b/src/Payments/Paypal.ts
index b419a0d8..bb4e7c0c 100644
--- a/src/Payments/Paypal.ts
+++ b/src/Payments/Paypal.ts
@@ -1,5 +1,5 @@
import paypal from "paypal-rest-sdk";
-import { Company_Currency, DebugMode, Domain, Full_Domain, Http_Schema, Paypal_Client_Id, Paypal_Client_Secret, PORT } from "../Config";
+import { Company_Currency, DebugMode, Full_Domain, Paypal_Client_Id, Paypal_Client_Secret } from "../Config";
import CustomerModel from "../Database/Models/Customers/Customer.model";
import TransactionsModel from "../Database/Models/Transactions.model";
import { IInvoice } from "../Interfaces/Invoice.interface";
From 68135e08051b262f1fb97dc80e1a8e1e57697992 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 20:16:02 +0100
Subject: [PATCH 05/15] feat: :tada: Checking if customer valid currency
---
.../Routes/v2/Customers/Customers.controller.ts | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/Server/Routes/v2/Customers/Customers.controller.ts b/src/Server/Routes/v2/Customers/Customers.controller.ts
index fb60266d..41a981f0 100644
--- a/src/Server/Routes/v2/Customers/Customers.controller.ts
+++ b/src/Server/Routes/v2/Customers/Customers.controller.ts
@@ -11,6 +11,7 @@ import { Company_Currency, Company_Name } from "../../../../Config";
import mainEvent from "../../../../Events/Main.event";
import { sanitizeMongoose } from "../../../../Lib/Sanitize";
import WelcomeTemplate from "../../../../Email/Templates/Customer/Welcome.template";
+import { currencyCodes, TPaymentCurrency } from "../../../../Types/PaymentTypes";
const API = new BaseModelAPI(idCustomer, CustomerModel);
@@ -39,6 +40,20 @@ function insert(req: Request, res: Response)
req.body.currency = currency;
}
+ // Check if our currency is valid
+ // req.body.currency = igh7183
+ const validCurrency = (currency: string) =>
+ {
+ currency = currency.toUpperCase();
+ if(currencyCodes.includes(currency as TPaymentCurrency))
+ return true;
+
+ return false;
+ }
+
+ if(!validCurrency(req.body.currency))
+ req.body.currency = await Company_Currency();
+
API.create(req.body)
.then(async (result) =>
{
From 48727f9cc033d52d5510823a4cfb0ef3f891c48c Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 20:17:27 +0100
Subject: [PATCH 06/15] fix: :fire: Fixed importing issue
---
src/Database/Models/Customers/Customer.model.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Database/Models/Customers/Customer.model.ts b/src/Database/Models/Customers/Customer.model.ts
index 44d50453..4bd4c069 100644
--- a/src/Database/Models/Customers/Customer.model.ts
+++ b/src/Database/Models/Customers/Customer.model.ts
@@ -4,7 +4,7 @@ import { Default_Language, MongoDB_URI } from "../../../Config";
import { ICustomer, ICustomerMethods } from "../../../Interfaces/Customer.interface";
import Logger from "../../../Lib/Logger";
import GetText from "../../../Translation/GetText";
-import { A_PaymentCurrency } from "../../../Types/PaymentTypes";
+import { currencyCodes } from "../../../Types/PaymentTypes";
const CustomerSchema = new Schema
(
@@ -101,7 +101,7 @@ const CustomerSchema = new Schema
currency: {
type: String,
- enum: A_PaymentCurrency,
+ enum: currencyCodes,
required: true,
},
From ba08f44bfa66aeb54095c8ca8ee6a83c5be91ffc Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 20:17:48 +0100
Subject: [PATCH 07/15] feat: :art: Currency symbols on templates
---
src/Email/Templates/Invoices/Invoice.template.ts | 5 +++--
src/Email/Templates/Orders/NewOrderCreated.ts | 5 +++--
src/Email/Templates/Transaction/NewTransaction.template.ts | 3 ++-
src/Lib/Quotes/CreateQuotePdf.ts | 2 +-
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/Email/Templates/Invoices/Invoice.template.ts b/src/Email/Templates/Invoices/Invoice.template.ts
index 38588956..9196260c 100644
--- a/src/Email/Templates/Invoices/Invoice.template.ts
+++ b/src/Email/Templates/Invoices/Invoice.template.ts
@@ -3,6 +3,7 @@ import { Company_Currency, Full_Domain } from "../../../Config";
import { ICustomer } from "../../../Interfaces/Customer.interface";
import { IInvoice } from "../../../Interfaces/Invoice.interface";
import getFullName from "../../../Lib/Customers/getFullName";
+import { GetCurrencySymbol, TPaymentCurrency } from "../../../Types/PaymentTypes";
import GetTableStyle from "../CSS/GetTableStyle";
import UseStyles from "../General/UseStyles";
@@ -76,7 +77,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
${item.notes} |
${item.quantity} |
- ${item.amount} ${!customer.currency ? await Company_Currency() : customer.currency} |
+ ${item.amount} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
`))).join('')}
@@ -85,7 +86,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
Total:
- ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${!customer.currency ? await Company_Currency() : customer.currency} (${invoice.tax_rate}%)
+ ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} (${invoice.tax_rate}%)
diff --git a/src/Email/Templates/Orders/NewOrderCreated.ts b/src/Email/Templates/Orders/NewOrderCreated.ts
index 00c0cd4d..74298e42 100644
--- a/src/Email/Templates/Orders/NewOrderCreated.ts
+++ b/src/Email/Templates/Orders/NewOrderCreated.ts
@@ -5,6 +5,7 @@ import { ICustomer } from "../../../Interfaces/Customer.interface";
import { IOrder } from "../../../Interfaces/Orders.interface";
import getFullName from "../../../Lib/Customers/getFullName";
import getProductById from "../../../Lib/Products/getProductById";
+import { GetCurrencySymbol, TPaymentCurrency } from "../../../Types/PaymentTypes";
import GetTableStyle from "../CSS/GetTableStyle";
import UseStyles from "../General/UseStyles";
@@ -48,7 +49,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
${p?.name} |
${product.quantity} |
- ${p?.price} ${!customer.currency ? await Company_Currency() : customer.currency} |
+ ${p?.price} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
`;
if(p_c.length > 0)
@@ -59,7 +60,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
+ ${p?.name} - ${c?.name} |
1 |
- ${c?.price} ${!customer.currency ? await Company_Currency() : customer.currency} |
+ ${c?.price} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
`
}
}
diff --git a/src/Email/Templates/Transaction/NewTransaction.template.ts b/src/Email/Templates/Transaction/NewTransaction.template.ts
index d8d12b12..c5357fde 100644
--- a/src/Email/Templates/Transaction/NewTransaction.template.ts
+++ b/src/Email/Templates/Transaction/NewTransaction.template.ts
@@ -4,6 +4,7 @@ import { ICustomer } from "../../../Interfaces/Customer.interface";
import { ITransactions } from "../../../Interfaces/Transactions.interface";
import PrintCompanyInformation from "../../../Lib/Company/PrintCompanyInformation";
import getFullName from "../../../Lib/Customers/getFullName";
+import { GetCurrencySymbol, TPaymentCurrency } from "../../../Types/PaymentTypes";
import UseStyles from "../General/UseStyles";
export = async (t: ITransactions, c: ICustomer, charged = false) => UseStyles(stripIndents`
@@ -25,7 +26,7 @@ export = async (t: ITransactions, c: ICustomer, charged = false) => UseStyles(st
${await PrintCompanyInformation()}
- Amount: ${t.amount} ${!c.currency ? await Company_Currency() : c.currency}
+ Amount: ${t.amount} ${GetCurrencySymbol((!c.currency ? await Company_Currency() : c.currency) as TPaymentCurrency)}
`);
\ No newline at end of file
diff --git a/src/Lib/Quotes/CreateQuotePdf.ts b/src/Lib/Quotes/CreateQuotePdf.ts
index aa94dc5f..a591e5f5 100644
--- a/src/Lib/Quotes/CreateQuotePdf.ts
+++ b/src/Lib/Quotes/CreateQuotePdf.ts
@@ -42,7 +42,7 @@ export default function createQuotePdf(quote: IQuotes): Promise
},
"taxNotation": "vat",
"settings": {
- "currency": (await Company_Currency()).toUpperCase(),
+ "currency": (!Customer.currency ? await Company_Currency() : Customer.currency).toUpperCase(),
"margin-top": 25,
"margin-right": 25,
"margin-left": 25,
From 5639bf52dca27994cf4bb12207e2d513bc3981b6 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 20:18:10 +0100
Subject: [PATCH 08/15] Updated version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 4ae1eff4..ce175098 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cpg-api",
- "version": "v2.4",
+ "version": "v2.5",
"description": "Central Payment Gateway",
"main": "./build/Main.js",
"dependencies": {
From 88062e3701b9f53fdc84725f24e30114e3d4e768 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:12:23 +0100
Subject: [PATCH 09/15] fix: :fire: Fixed key
---
src/Server/Routes/v2/Customers/Customers.config.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Server/Routes/v2/Customers/Customers.config.ts b/src/Server/Routes/v2/Customers/Customers.config.ts
index e3e1e902..00a159b2 100644
--- a/src/Server/Routes/v2/Customers/Customers.config.ts
+++ b/src/Server/Routes/v2/Customers/Customers.config.ts
@@ -75,7 +75,7 @@ export = class CustomerRouter
// Which can look like this: personal.first_name
// But it could be: personal: { first_name: "John" }
// So we need to check if the key is a string
- if(typeof key === "string")
+ if(typeof key === "string" && key.includes("."))
{
// If the key is a string, we need to split it
// And check if the first part is in the customer object
From cdc2d43a25c8e01c0fcf6eac7a8f1b1456337963 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:53:43 +0100
Subject: [PATCH 10/15] feat: :sparkles: Added currency to more models
Added currency to inoivces/orders/transactions
---
src/Database/Models/Invoices.model.ts | 7 +++++++
src/Database/Models/Orders.model.ts | 8 +++++++-
src/Database/Models/Transactions.model.ts | 7 +++++++
src/Interfaces/Invoice.interface.ts | 2 ++
src/Interfaces/Orders.interface.ts | 3 ++-
src/Interfaces/Transactions.interface.ts | 2 ++
6 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/Database/Models/Invoices.model.ts b/src/Database/Models/Invoices.model.ts
index 108efea9..9aad53e7 100644
--- a/src/Database/Models/Invoices.model.ts
+++ b/src/Database/Models/Invoices.model.ts
@@ -4,6 +4,7 @@ import { Default_Language, MongoDB_URI } from "../../Config";
import { A_InvoiceStatus, IInvoice } from "../../Interfaces/Invoice.interface";
import Logger from "../../Lib/Logger";
import GetText from "../../Translation/GetText";
+import { currencyCodes } from "../../Types/PaymentTypes";
const InvoiceSchema = new Schema
(
@@ -92,6 +93,12 @@ const InvoiceSchema = new Schema
default: false,
},
+ currency: {
+ type: String,
+ enum: currencyCodes,
+ default: 'USD',
+ },
+
}
);
diff --git a/src/Database/Models/Orders.model.ts b/src/Database/Models/Orders.model.ts
index 40e93662..a59f9783 100644
--- a/src/Database/Models/Orders.model.ts
+++ b/src/Database/Models/Orders.model.ts
@@ -5,7 +5,7 @@ import { A_OrderStatus, IOrder } from "../../Interfaces/Orders.interface";
import Logger from "../../Lib/Logger";
import GetText from "../../Translation/GetText";
import { A_CC_Payments, A_RecurringMethod } from "../../Types/PaymentMethod";
-import { A_PaymentTypes } from "../../Types/PaymentTypes";
+import { A_PaymentTypes, currencyCodes } from "../../Types/PaymentTypes";
const OrderSchema = new Schema
(
@@ -95,6 +95,12 @@ const OrderSchema = new Schema
require: false
},
+ currency: {
+ type: String,
+ enum: currencyCodes,
+ default: 'USD',
+ },
+
}
);
diff --git a/src/Database/Models/Transactions.model.ts b/src/Database/Models/Transactions.model.ts
index 6fe29144..1bb06501 100644
--- a/src/Database/Models/Transactions.model.ts
+++ b/src/Database/Models/Transactions.model.ts
@@ -5,6 +5,7 @@ import { IDTransactions } from "../../Interfaces/Transactions.interface";
import Logger from "../../Lib/Logger";
import GetText from "../../Translation/GetText";
import { A_CC_Payments } from "../../Types/PaymentMethod";
+import { currencyCodes } from "../../Types/PaymentTypes";
const TransactionsSchema = new Schema
(
@@ -47,6 +48,12 @@ const TransactionsSchema = new Schema
default: 0,
},
+ currency: {
+ type: String,
+ enum: currencyCodes,
+ default: 'USD',
+ },
+
}
);
diff --git a/src/Interfaces/Invoice.interface.ts b/src/Interfaces/Invoice.interface.ts
index 86c49c41..baa9f9a1 100644
--- a/src/Interfaces/Invoice.interface.ts
+++ b/src/Interfaces/Invoice.interface.ts
@@ -1,3 +1,4 @@
+import { TPaymentCurrency } from "../Types/PaymentTypes";
import { IConfigurableOptions } from "./ConfigurableOptions.interface";
import { ICustomer } from "./Customer.interface";
import { TOrderStatus } from "./Orders.interface";
@@ -56,6 +57,7 @@ export interface IInvoice
tax_rate: number;
notes: string;
paid: boolean;
+ currency: TPaymentCurrency;
notified: boolean;
}
diff --git a/src/Interfaces/Orders.interface.ts b/src/Interfaces/Orders.interface.ts
index 29740288..33c79027 100644
--- a/src/Interfaces/Orders.interface.ts
+++ b/src/Interfaces/Orders.interface.ts
@@ -1,5 +1,5 @@
import { TRecurringMethod } from "../Types/PaymentMethod";
-import { TPaymentTypes } from "../Types/PaymentTypes";
+import { TPaymentCurrency, TPaymentTypes } from "../Types/PaymentTypes";
import { IConfigurableOptions } from "./ConfigurableOptions.interface";
import { ICustomer } from "./Customer.interface";
import { IInvoice } from "./Invoice.interface";
@@ -45,6 +45,7 @@ export interface IOrder
price_override?: number;
dates: IOrderDates;
invoices: Array;
+ currency: TPaymentCurrency;
promotion_code?: IPromotionsCodes["id"];
}
diff --git a/src/Interfaces/Transactions.interface.ts b/src/Interfaces/Transactions.interface.ts
index ec193dce..039ee9bf 100644
--- a/src/Interfaces/Transactions.interface.ts
+++ b/src/Interfaces/Transactions.interface.ts
@@ -1,4 +1,5 @@
import { Document } from "mongoose";
+import { TPaymentCurrency } from "../Types/PaymentTypes";
import { ICustomer } from "./Customer.interface";
import { IInvoice } from "./Invoice.interface";
@@ -18,6 +19,7 @@ export interface ITransactions
date: Date | string;
payment_method: IInvoice["payment_method"];
amount: IInvoice["amount"];
+ currency: TPaymentCurrency;
fees: number;
}
From a9801fb098fb2ae9c48d0d958528cac291095794 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:54:21 +0100
Subject: [PATCH 11/15] feat: :fire: Fixed currency on templates
---
src/Email/Templates/Invoices/Invoice.template.ts | 8 ++++----
src/Email/Templates/Invoices/LateInvoice.Template.ts | 7 ++++---
src/Email/Templates/Orders/NewOrderCreated.ts | 9 ++++-----
.../Templates/Transaction/NewTransaction.template.ts | 2 +-
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/Email/Templates/Invoices/Invoice.template.ts b/src/Email/Templates/Invoices/Invoice.template.ts
index 9196260c..c66663c0 100644
--- a/src/Email/Templates/Invoices/Invoice.template.ts
+++ b/src/Email/Templates/Invoices/Invoice.template.ts
@@ -1,9 +1,9 @@
import { stripIndents } from "common-tags";
-import { Company_Currency, Full_Domain } from "../../../Config";
+import { Full_Domain } from "../../../Config";
import { ICustomer } from "../../../Interfaces/Customer.interface";
import { IInvoice } from "../../../Interfaces/Invoice.interface";
import getFullName from "../../../Lib/Customers/getFullName";
-import { GetCurrencySymbol, TPaymentCurrency } from "../../../Types/PaymentTypes";
+import { GetCurrencySymbol } from "../../../Types/PaymentTypes";
import GetTableStyle from "../CSS/GetTableStyle";
import UseStyles from "../General/UseStyles";
@@ -77,7 +77,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
${item.notes} |
${item.quantity} |
- ${item.amount} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
+ ${item.amount} ${GetCurrencySymbol(invoice.currency)} |
`))).join('')}
@@ -86,7 +86,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
Total:
- ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} (${invoice.tax_rate}%)
+ ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${GetCurrencySymbol(invoice.currency)} (${invoice.tax_rate}%)
diff --git a/src/Email/Templates/Invoices/LateInvoice.Template.ts b/src/Email/Templates/Invoices/LateInvoice.Template.ts
index 600047b3..81bfea50 100644
--- a/src/Email/Templates/Invoices/LateInvoice.Template.ts
+++ b/src/Email/Templates/Invoices/LateInvoice.Template.ts
@@ -1,8 +1,9 @@
import { stripIndents } from "common-tags";
-import { Company_Currency, Full_Domain } from "../../../Config";
+import { Full_Domain } from "../../../Config";
import { ICustomer } from "../../../Interfaces/Customer.interface";
import { IInvoice } from "../../../Interfaces/Invoice.interface";
import getFullName from "../../../Lib/Customers/getFullName";
+import { GetCurrencySymbol } from "../../../Types/PaymentTypes";
import GetTableStyle from "../CSS/GetTableStyle";
import UseStyles from "../General/UseStyles";
@@ -64,7 +65,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
${item.notes} |
${item.quantity} |
- ${item.amount} ${!customer.currency ? await Company_Currency() : customer.currency} |
+ ${item.amount} ${GetCurrencySymbol(invoice.currency)} |
`))).join('')}
@@ -73,7 +74,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
Total:
- ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${!customer.currency ? await Company_Currency() : customer.currency} (${invoice.tax_rate}%)
+ ${invoice.amount+invoice.amount*invoice.tax_rate/100} ${GetCurrencySymbol(invoice.currency)} (${invoice.tax_rate}%)
diff --git a/src/Email/Templates/Orders/NewOrderCreated.ts b/src/Email/Templates/Orders/NewOrderCreated.ts
index 74298e42..4f957513 100644
--- a/src/Email/Templates/Orders/NewOrderCreated.ts
+++ b/src/Email/Templates/Orders/NewOrderCreated.ts
@@ -1,11 +1,10 @@
import { stripIndents } from "common-tags";
-import { Company_Currency } from "../../../Config";
import ConfigurableOptionsModel from "../../../Database/Models/ConfigurableOptions.model";
import { ICustomer } from "../../../Interfaces/Customer.interface";
import { IOrder } from "../../../Interfaces/Orders.interface";
import getFullName from "../../../Lib/Customers/getFullName";
import getProductById from "../../../Lib/Products/getProductById";
-import { GetCurrencySymbol, TPaymentCurrency } from "../../../Types/PaymentTypes";
+import { GetCurrencySymbol } from "../../../Types/PaymentTypes";
import GetTableStyle from "../CSS/GetTableStyle";
import UseStyles from "../General/UseStyles";
@@ -49,7 +48,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
${p?.name} |
${product.quantity} |
- ${p?.price} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
+ ${p?.price} ${GetCurrencySymbol(order.currency)} |
`;
if(p_c.length > 0)
@@ -60,7 +59,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
+ ${p?.name} - ${c?.name} |
1 |
- ${c?.price} ${GetCurrencySymbol((!customer.currency ? await Company_Currency() : customer.currency) as TPaymentCurrency)} |
+ ${c?.price} ${GetCurrencySymbol(order.currency)} |
`
}
}
@@ -96,7 +95,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
total += p_c.reduce((a, b) => a + b);
return total;
- }))).reduce((acc, cur) => acc + cur, 0)} ${(!customer.currency ? await Company_Currency() : customer.currency).toLocaleUpperCase()}
+ }))).reduce((acc, cur) => acc + cur, 0)} ${(order.currency).toLocaleUpperCase()}
`);
\ No newline at end of file
diff --git a/src/Email/Templates/Transaction/NewTransaction.template.ts b/src/Email/Templates/Transaction/NewTransaction.template.ts
index c5357fde..d0c910fd 100644
--- a/src/Email/Templates/Transaction/NewTransaction.template.ts
+++ b/src/Email/Templates/Transaction/NewTransaction.template.ts
@@ -26,7 +26,7 @@ export = async (t: ITransactions, c: ICustomer, charged = false) => UseStyles(st
${await PrintCompanyInformation()}
- Amount: ${t.amount} ${GetCurrencySymbol((!c.currency ? await Company_Currency() : c.currency) as TPaymentCurrency)}
+ Amount: ${t.amount} ${GetCurrencySymbol(t.currency)}
`);
\ No newline at end of file
From 52a79dd7be4d182f8aa0ed3d98268d8cda46ebc7 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:54:51 +0100
Subject: [PATCH 12/15] style: :art: Small changes
---
src/Interfaces/Customer.interface.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/Interfaces/Customer.interface.ts b/src/Interfaces/Customer.interface.ts
index d2442ed1..0e245657 100644
--- a/src/Interfaces/Customer.interface.ts
+++ b/src/Interfaces/Customer.interface.ts
@@ -1,3 +1,4 @@
+import { TPaymentCurrency } from "../Types/PaymentTypes";
import { ICompanyConfig } from "./Admin/Configs.interface";
import { IImage } from "./Images.interface";
@@ -27,7 +28,7 @@ export interface ICustomer
password: string;
createdAt: Date;
profile_picture: IImage["id"] | null;
- currency: string | ICompanyConfig["currency"];
+ currency: TPaymentCurrency | ICompanyConfig["currency"];
extra: {
[key: string]: any;
};
From ebeed100d5d6d76ffa1417d495abebd0bbceeb37 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:55:18 +0100
Subject: [PATCH 13/15] feat: :sparkles: Added currency into workflow
---
src/Lib/Orders/newInvoice.ts | 2 +-
src/Payments/Paypal.ts | 1 +
src/Payments/Stripe.ts | 2 ++
src/Server/Routes/v2/Orders/Orders.config.ts | 22 +++++++++++---------
4 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/Lib/Orders/newInvoice.ts b/src/Lib/Orders/newInvoice.ts
index 84498d2e..6dc69934 100644
--- a/src/Lib/Orders/newInvoice.ts
+++ b/src/Lib/Orders/newInvoice.ts
@@ -15,7 +15,6 @@ import Logger from "../Logger";
import PromotionCodeModel from "../../Database/Models/PromotionsCode.model";
import { sanitizeMongoose } from "../Sanitize";
-
// Create a method that checks if the order next recycle is within 14 days
export function isWithinNext14Days(date: Date | string): boolean
{
@@ -103,6 +102,7 @@ export async function createInvoiceFromOrder(order: IOrder)
tax_rate: Products?.reduce((acc, cur) => cur.tax_rate, 0),
notes: "",
paid: false,
+ currency: order.currency,
notified: false,
})).save();
diff --git a/src/Payments/Paypal.ts b/src/Payments/Paypal.ts
index bb4e7c0c..6439a767 100644
--- a/src/Payments/Paypal.ts
+++ b/src/Payments/Paypal.ts
@@ -136,6 +136,7 @@ export async function retrievePaypalTransaction(payerId: string, paymentId: stri
fees: 0,
invoice_uid: invoice.id,
customer_uid: invoice.customer_uid,
+ currency: invoice.currency ?? await Company_Currency(),
date: getDate(),
uid: idTransicitons(),
}).save());
diff --git a/src/Payments/Stripe.ts b/src/Payments/Stripe.ts
index 93bd0774..a220fa77 100644
--- a/src/Payments/Stripe.ts
+++ b/src/Payments/Stripe.ts
@@ -177,6 +177,7 @@ export const ChargeCustomer = async (invoice_id: IInvoice["id"]) =>
fees: 0,
invoice_uid: invoice.id,
customer_uid: invoice.customer_uid,
+ currency: invoice.currency ?? await Company_Currency(),
date: getDate(),
uid: idTransicitons(),
}).save());
@@ -219,6 +220,7 @@ export const markInvoicePaid = async (intent: stripe.Response;
-}>, _products: IProduct[], payment_method: string, billing_type: string, billing_cycle?: TRecurringMethod)
+}>, _products: IProduct[], payment_method: string, billing_type: string, currency: TPaymentCurrency, billing_cycle?: TRecurringMethod)
{
const order = await (new OrderModel({
customer_uid: customer.id,
@@ -58,6 +58,7 @@ async function createOrder(customer: ICustomer, products: Array<{
, "YYYY-MM-DD"),
last_recycle: dateFormat.format(new Date(), "YYYY-MM-DD")
},
+ currency: currency,
uid: idOrder(),
}).save());
@@ -154,6 +155,7 @@ export = class OrderRoute
uid: idOrder(),
// @ts-ignore
invoices: [],
+ currency: !customer.currency ? await Company_Currency() : customer.currency,
promotion_code: promotion_code?.id,
}
@@ -210,7 +212,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_monthly, payment_method, "recurring", "monthly");
+ }), recurring_monthly, payment_method, "recurring", _order_.currency, "monthly");
if(recurring_quarterly.length > 0)
createOrder(customer, recurring_quarterly.map(p =>
@@ -219,7 +221,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_quarterly, payment_method, "recurring", "quarterly");
+ }), recurring_quarterly, payment_method, "recurring", _order_.currency, "quarterly");
if(recurring_semi_annually.length > 0)
createOrder(customer, recurring_semi_annually.map(p =>
@@ -228,7 +230,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_semi_annually, payment_method, "recurring", "semi_annually");
+ }), recurring_semi_annually, payment_method, "recurring", _order_.currency, "semi_annually");
if(recurring_biennially.length > 0)
createOrder(customer, recurring_biennially.map(p =>
@@ -237,7 +239,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_biennially, payment_method, "recurring", "biennially");
+ }), recurring_biennially, payment_method, "recurring", _order_.currency, "biennially");
if(recurring_triennially.length > 0)
createOrder(customer, recurring_triennially.map(p =>
@@ -246,7 +248,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_triennially, payment_method, "recurring", "triennially");
+ }), recurring_triennially, payment_method, "recurring", _order_.currency, "triennially");
if(one_timers.length > 0)
createOrder(customer, one_timers.map(p =>
@@ -255,7 +257,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), one_timers, payment_method, "one_time");
+ }), one_timers, payment_method, "one_time", _order_.currency);
if(recurring_yearly.length > 0)
createOrder(customer, recurring_yearly.map(p =>
@@ -264,7 +266,7 @@ export = class OrderRoute
product_id: p.id,
quantity: 1
}
- }), recurring_yearly, payment_method, "recurring", "yearly");
+ }), recurring_yearly, payment_method, "recurring", _order_.currency, "yearly");
const invoice = await createInvoiceFromOrder(_order_);
From eeff8ad448c85559a58efff85ab569e437356756 Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:55:34 +0100
Subject: [PATCH 14/15] feat: :zap: Added new route for currencies
---
.../Routes/v3/Currencies/Currencies.config.ts | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 src/Server/Routes/v3/Currencies/Currencies.config.ts
diff --git a/src/Server/Routes/v3/Currencies/Currencies.config.ts b/src/Server/Routes/v3/Currencies/Currencies.config.ts
new file mode 100644
index 00000000..8332a1cc
--- /dev/null
+++ b/src/Server/Routes/v3/Currencies/Currencies.config.ts
@@ -0,0 +1,36 @@
+import { Application, Router } from "express";
+import { APIError, APISuccess } from "../../../../Lib/Response";
+import { PaypalCurrencies } from "../../../../Payments/Currencies/Paypal.currencies";
+import { currencyCodes, GetCurrencySymbol, TPaymentCurrency } from "../../../../Types/PaymentTypes";
+
+export = class CurrenciesRouter
+{
+ private server: Application;
+ private router = Router();
+
+ constructor(server: Application, version: string)
+ {
+ this.server = server;
+ this.server.use(`/${version}/currencies`, this.router);
+
+ this.router.get("/", (req, res) =>
+ {
+ return APISuccess(currencyCodes)(res);
+ });
+
+ this.router.get("/paypals", (req, res) =>
+ {
+ return APISuccess(PaypalCurrencies)(res);
+ });
+
+ this.router.get("/:code/symbol", (req, res) =>
+ {
+ const code = currencyCodes.find(c => c === req.params.code.toUpperCase()) as TPaymentCurrency;
+ if(!code)
+ return APIError("Invalid code")(res);
+ return APISuccess(GetCurrencySymbol(code))(res);
+ })
+
+ }
+
+}
\ No newline at end of file
From 16e168e80ab14a7d6bdff844dc3188546963b92e Mon Sep 17 00:00:00 2001
From: Tolfx
Date: Mon, 7 Mar 2022 21:55:50 +0100
Subject: [PATCH 15/15] Updated version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index ce175098..6973c740 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cpg-api",
- "version": "v2.5",
+ "version": "v2.6",
"description": "Central Payment Gateway",
"main": "./build/Main.js",
"dependencies": {