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

Commit b189944

Browse files
authored
Merge pull request #71 from Tolfix/dev
v2.0
2 parents 482cd22 + 016d0aa commit b189944

12 files changed

Lines changed: 73 additions & 39 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpg-api",
3-
"version": "v1.9",
3+
"version": "v2.0",
44
"description": "Central Payment Gateway",
55
"main": "./build/Main.js",
66
"dependencies": {
@@ -36,7 +36,7 @@
3636
"jsonwebtoken": "^8.5.1",
3737
"mongoose": "^6.1.4",
3838
"mongoose-auto-increment": "^5.0.1",
39-
"node-fetch": "^2.6.6",
39+
"node-fetch": ">=3.1.1",
4040
"nodemailer": "^6.7.0",
4141
"npm": "^7.20.5",
4242
"paypal-rest-sdk": "^1.8.1",

src/Email/Templates/CSS/GetTableStyle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ border-collapse: collapse;
1616
padding: 7px 5px;
1717
border-top: 1px solid #E6E6E6;
1818
}
19-
`
19+
` as const;
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
export default `
2-
<div style="font-size: 21px;
3-
color: #999;
4-
padding: 20px 5px 10px;
5-
text-align: center;">
6-
<a href="https://github.com/Tolfix/cpg-api">cpg-api</a> &copy;
2+
<div style="
3+
font-size: 21px;
4+
color: #999;
5+
padding: 20px 5px 10px;
6+
text-align: center;
7+
">
8+
&copy; <a href="https://github.com/Tolfix/cpg-api">CPG-API</a>
79
</div>
810
`;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { Company_Logo_Url, Company_Name } from "../../../Config";
1+
import { Company_Logo_Url, Company_Name, Company_Website } from "../../../Config";
22

33
export default async () => `
44
<div style="margin-bottom: 5px;
55
padding: 10px 0;
66
text-align: center;">
77
<div class="logo">
8-
<img width="256" src="${await Company_Logo_Url()}" alt="${await Company_Name()}" />
8+
<a href="${await Company_Website()}" target="_blank">
9+
<img width="256" src="${await Company_Logo_Url()}" alt="${await Company_Name()}" />
10+
</a>
911
</div>
1012
</div>
1113
`;

src/Email/Templates/General/UseStyles.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ export default async (s: string) =>
1212
</style>
1313
</head>
1414
<body>
15-
${await Header()}
16-
17-
<div style="background-color: #F4F4F4;
18-
padding: 10px;
19-
margin: 10px auto;
20-
max-width: 650px;
21-
width: auto;
22-
line-height: 20px;">
15+
<div style="
16+
background-color: #F4F4F4;
17+
padding: 10px;
18+
margin: 10px auto;
19+
max-width: 650px;
20+
width: auto;
21+
line-height: 20px;"
22+
>
23+
${await Header()}
2324
<div style="
2425
background-color: #FFF;
2526
padding: 20px; }
26-
content p:last-child {
27-
margin: 0;"
27+
content p:last-child {
28+
margin: 0;"
2829
>
2930
${s}
3031
</div>
32+
${Footer}
3133
</div>
32-
33-
${Footer}
3434
</body>
3535
</html>
3636
`

src/Email/Templates/Invoices/Invoice.template.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
1919
OCR number: ${(invoice.dates.invoice_date as string).replaceAll("-", "")}${invoice.id}
2020
</p>
2121
<p>
22-
Your payment method is: ${invoice.payment_method}
22+
Your payment method is: ${(invoice.payment_method).firstLetterUpperCase().replaceAll("_", " ")}
2323
</p>
2424
<p>
2525
Tax due: ${invoice.tax_rate}%
@@ -36,20 +36,20 @@ export default async (invoice: IInvoice, customer: ICustomer) => await UseStyles
3636
Click me to pay.
3737
</a>
3838
` : ''}
39-
${invoice.payment_method === "credit_card" ? `<br />
39+
${invoice.payment_method === "credit_card" ? `
4040
<a href="${Full_Domain}/v2/stripe/pay/${invoice.uid}" target="_blank">
4141
Click me to pay.
4242
</a>
43+
<p>
44+
<strong>
45+
To pay automatic invoice, you need to setup your payment method. It will automatic pay when a invoice is 14 days ahead. <br />
46+
<a href="${Full_Domain}/v2/stripe/setup/${customer.uid}" target="_blank">
47+
Click here to setup your payment method.
48+
</a>
49+
</strong>
50+
</p>
51+
` : ''}
4352
</p>
44-
<p>
45-
<strong>
46-
To pay automatic invoice, you need to setup your payment method. It will automatic pay when a invoice is 14 days ahead. <br />
47-
<a href="${Full_Domain}/v2/stripe/setup/${customer.id}" target="_blank">
48-
Click here to setup your payment method.
49-
</a>
50-
</strong>
51-
</p>
52-
` : ''}
5353
5454
<table style="${GetTableStyle}">
5555
<thead>

src/Email/Templates/Orders/NewOrderCreated.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
5757
{
5858
result += stripIndents`
5959
<tr>
60-
<td>+ ${c?.name}</td>
61-
<td>+ 1</td>
62-
<td>+ ${c?.price} ${await Company_Currency()}</td>
60+
<td>+ ${p?.name} - ${c?.name}</td>
61+
<td>1</td>
62+
<td>${c?.price} ${await Company_Currency()}</td>
6363
</tr>`
6464
}
6565
}

src/Lib/Invoices/CreatePDFInvoice.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from "../../Config";
2323
import qrcode from "qrcode";
2424
import GetText from "../../Translation/GetText";
25+
import GetOCRNumber from "./GetOCRNumber";
2526

2627
export default function createPDFInvoice(invoice: IInvoice): Promise<string>
2728
{
@@ -72,7 +73,7 @@ export default function createPDFInvoice(invoice: IInvoice): Promise<string>
7273
"city": Customer.billing.city,
7374
"country": Customer.billing.country,
7475
"custom1": `<br/><strong>Customer ID:</strong> ${Customer.id}`,
75-
"custom2": `<br/><strong>OCR Number:</strong> ${(invoice.dates.invoice_date as string).replaceAll("-", "")}${invoice.id}`,
76+
"custom2": `<br/><strong>OCR Number:</strong> ${GetOCRNumber(invoice)}`,
7677
"custom3": `
7778
<br/>
7879
<div style="
@@ -88,7 +89,7 @@ export default function createPDFInvoice(invoice: IInvoice): Promise<string>
8889
Swish
8990
<div>
9091
<img
91-
src="data:image/png;base64,${await createSwishQRCode(Swish_Payee_Number, (invoice.amount)+(invoice.amount)*(invoice.tax_rate/100), `Invoice ${invoice.id}`)}"
92+
src="data:image/png;base64,${await createSwishQRCode(Swish_Payee_Number, (invoice.amount)+(invoice.amount)*(invoice.tax_rate/100), `OCR ${GetOCRNumber(invoice)}`)}"
9293
width="64">
9394
</div>
9495
` : ''}

src/Lib/Invoices/GetOCRNumber.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { IInvoice } from "../../Interfaces/Invoice.interface";
2+
3+
/**
4+
* @description
5+
* Template looks somewhat like this: YYMMDD(ID)
6+
* YY = year
7+
* MM = month
8+
* DD = day
9+
* ID = invoice id
10+
*/
11+
export default (i: IInvoice) => `${(i.dates.invoice_date as string).replaceAll("-", "")}${i.id}`

src/Lib/Orders/newInvoice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function createInvoiceFromOrder(order: IOrder)
4747
for await(let product of Products)
4848
{
4949
if(Promotion_Code)
50-
// @ts-ignore
50+
// @ts-ignore
5151
product = await getNewPriceOfPromotionCode(Promotion_Code, product);
5252
const category = await getCategoryByProduct(product);
5353
items.push({

0 commit comments

Comments
 (0)