Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #71 from Tolfix/dev
Browse files Browse the repository at this point in the history
v2.0
  • Loading branch information
Tolfx authored Jan 22, 2022
2 parents 482cd22 + 016d0aa commit b189944
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 39 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cpg-api",
"version": "v1.9",
"version": "v2.0",
"description": "Central Payment Gateway",
"main": "./build/Main.js",
"dependencies": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.1.4",
"mongoose-auto-increment": "^5.0.1",
"node-fetch": "^2.6.6",
"node-fetch": ">=3.1.1",
"nodemailer": "^6.7.0",
"npm": "^7.20.5",
"paypal-rest-sdk": "^1.8.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Email/Templates/CSS/GetTableStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ border-collapse: collapse;
padding: 7px 5px;
border-top: 1px solid #E6E6E6;
}
`
` as const;
12 changes: 7 additions & 5 deletions src/Email/Templates/General/Footer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export default `
<div style="font-size: 21px;
color: #999;
padding: 20px 5px 10px;
text-align: center;">
<a href="https://github.com/Tolfix/cpg-api">cpg-api</a> &copy;
<div style="
font-size: 21px;
color: #999;
padding: 20px 5px 10px;
text-align: center;
">
&copy; <a href="https://github.com/Tolfix/cpg-api">CPG-API</a>
</div>
`;
6 changes: 4 additions & 2 deletions src/Email/Templates/General/Header.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Company_Logo_Url, Company_Name } from "../../../Config";
import { Company_Logo_Url, Company_Name, Company_Website } from "../../../Config";

export default async () => `
<div style="margin-bottom: 5px;
padding: 10px 0;
text-align: center;">
<div class="logo">
<img width="256" src="${await Company_Logo_Url()}" alt="${await Company_Name()}" />
<a href="${await Company_Website()}" target="_blank">
<img width="256" src="${await Company_Logo_Url()}" alt="${await Company_Name()}" />
</a>
</div>
</div>
`;
24 changes: 12 additions & 12 deletions src/Email/Templates/General/UseStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ export default async (s: string) =>
</style>
</head>
<body>
${await Header()}
<div style="background-color: #F4F4F4;
padding: 10px;
margin: 10px auto;
max-width: 650px;
width: auto;
line-height: 20px;">
<div style="
background-color: #F4F4F4;
padding: 10px;
margin: 10px auto;
max-width: 650px;
width: auto;
line-height: 20px;"
>
${await Header()}
<div style="
background-color: #FFF;
padding: 20px; }
content p:last-child {
margin: 0;"
content p:last-child {
margin: 0;"
>
${s}
</div>
${Footer}
</div>
${Footer}
</body>
</html>
`
Expand Down
22 changes: 11 additions & 11 deletions src/Email/Templates/Invoices/Invoice.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
OCR number: ${(invoice.dates.invoice_date as string).replaceAll("-", "")}${invoice.id}
</p>
<p>
Your payment method is: ${invoice.payment_method}
Your payment method is: ${(invoice.payment_method).firstLetterUpperCase().replaceAll("_", " ")}
</p>
<p>
Tax due: ${invoice.tax_rate}%
Expand All @@ -36,20 +36,20 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
Click me to pay.
</a>
` : ''}
${invoice.payment_method === "credit_card" ? `<br />
${invoice.payment_method === "credit_card" ? `
<a href="${Full_Domain}/v2/stripe/pay/${invoice.uid}" target="_blank">
Click me to pay.
</a>
<p>
<strong>
To pay automatic invoice, you need to setup your payment method. It will automatic pay when a invoice is 14 days ahead. <br />
<a href="${Full_Domain}/v2/stripe/setup/${customer.uid}" target="_blank">
Click here to setup your payment method.
</a>
</strong>
</p>
` : ''}
</p>
<p>
<strong>
To pay automatic invoice, you need to setup your payment method. It will automatic pay when a invoice is 14 days ahead. <br />
<a href="${Full_Domain}/v2/stripe/setup/${customer.id}" target="_blank">
Click here to setup your payment method.
</a>
</strong>
</p>
` : ''}
<table style="${GetTableStyle}">
<thead>
Expand Down
6 changes: 3 additions & 3 deletions src/Email/Templates/Orders/NewOrderCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
{
result += stripIndents`
<tr>
<td>+ ${c?.name}</td>
<td>+ 1</td>
<td>+ ${c?.price} ${await Company_Currency()}</td>
<td>+ ${p?.name} - ${c?.name}</td>
<td>1</td>
<td>${c?.price} ${await Company_Currency()}</td>
</tr>`
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Lib/Invoices/CreatePDFInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "../../Config";
import qrcode from "qrcode";
import GetText from "../../Translation/GetText";
import GetOCRNumber from "./GetOCRNumber";

export default function createPDFInvoice(invoice: IInvoice): Promise<string>
{
Expand Down Expand Up @@ -72,7 +73,7 @@ export default function createPDFInvoice(invoice: IInvoice): Promise<string>
"city": Customer.billing.city,
"country": Customer.billing.country,
"custom1": `<br/><strong>Customer ID:</strong> ${Customer.id}`,
"custom2": `<br/><strong>OCR Number:</strong> ${(invoice.dates.invoice_date as string).replaceAll("-", "")}${invoice.id}`,
"custom2": `<br/><strong>OCR Number:</strong> ${GetOCRNumber(invoice)}`,
"custom3": `
<br/>
<div style="
Expand All @@ -88,7 +89,7 @@ export default function createPDFInvoice(invoice: IInvoice): Promise<string>
Swish
<div>
<img
src="data:image/png;base64,${await createSwishQRCode(Swish_Payee_Number, (invoice.amount)+(invoice.amount)*(invoice.tax_rate/100), `Invoice ${invoice.id}`)}"
src="data:image/png;base64,${await createSwishQRCode(Swish_Payee_Number, (invoice.amount)+(invoice.amount)*(invoice.tax_rate/100), `OCR ${GetOCRNumber(invoice)}`)}"
width="64">
</div>
` : ''}
Expand Down
11 changes: 11 additions & 0 deletions src/Lib/Invoices/GetOCRNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IInvoice } from "../../Interfaces/Invoice.interface";

/**
* @description
* Template looks somewhat like this: YYMMDD(ID)
* YY = year
* MM = month
* DD = day
* ID = invoice id
*/
export default (i: IInvoice) => `${(i.dates.invoice_date as string).replaceAll("-", "")}${i.id}`
2 changes: 1 addition & 1 deletion src/Lib/Orders/newInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function createInvoiceFromOrder(order: IOrder)
for await(let product of Products)
{
if(Promotion_Code)
// @ts-ignore
// @ts-ignore
product = await getNewPriceOfPromotionCode(Promotion_Code, product);
const category = await getCategoryByProduct(product);
items.push({
Expand Down
1 change: 1 addition & 0 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Logger.info("Adding .env variables");

import "./Mods/Map.mod";
import "./Mods/Number.mod";
import "./Mods/String.mod";

Logger.info(`Loading ./Events/Node.events`);
import "./Events/Node.events";
Expand Down
17 changes: 17 additions & 0 deletions src/Mods/String.mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export{};

declare global
{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface String
{
firstLetterUpperCase(): string
}
}

Object.defineProperty(String.prototype, "firstLetterUpperCase", {
value: function()
{
return this.charAt(0).toUpperCase() + this.slice(1);
}
});

0 comments on commit b189944

Please sign in to comment.