Skip to content

Commit 1f840f4

Browse files
authored
Merge pull request #14 from lehuygiang28/update_docs
Update documentation and fix broken anchor
2 parents 4b23377 + 520c5ed commit 1f840f4

21 files changed

+401
-93
lines changed

README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<br/>
1111

1212
<p align="center">
13-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/v/vnpay" alt="NPM Version" /></a>
14-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/l/vnpay" alt="Package License"><a>
15-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/dm/vnpay" alt="NPM Downloads"></a>
13+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/v/vnpay" alt="NPM Version" /></a>
14+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/l/vnpay" alt="Package License"><a>
15+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/d18m/vnpay" alt="NPM Downloads"></a>
1616
</p>
1717

1818
<strong>Thư viện mã nguồn mở hỗ trợ thanh toán qua [VNPay](https://vnpay.vn).</strong>
@@ -40,22 +40,37 @@ $ yarn add vnpay
4040
Cài đặt `vnpay` với `pnpm`:
4141

4242
```bash
43-
$ pnpm add vnpay
43+
$ pnpm install vnpay
4444
```
4545

4646
## Sử dụng:
4747

4848
#### Khởi tạo
4949

5050
```typescript
51-
import { VNPay } from 'vnpay';
51+
import { VNPay, ignoreLogger } from 'vnpay';
5252

5353
const vnpay = new VNPay({
5454
tmnCode: '2QXUI4B4',
5555
secureSecret: 'secret',
5656
vnpayHost: 'https://sandbox.vnpayment.vn',
57-
testMode: true, // optional
58-
hashAlgorithm: 'SHA512', // optional
57+
testMode: true, // tùy chọn
58+
hashAlgorithm: 'SHA512', // tùy chọn
59+
60+
/**
61+
* Sử dụng enableLog để bật/tắt logger
62+
* Nếu enableLog là false, loggerFn sẽ không được sử dụng trong bất kỳ phương thức nào
63+
*/
64+
enableLog: true, // tùy chọn
65+
66+
/**
67+
* Hàm `loggerFn` sẽ được gọi để ghi log
68+
* Mặc định, loggerFn sẽ ghi log ra console
69+
* Bạn có thể ghi đè loggerFn để ghi log ra nơi khác
70+
*
71+
* `ignoreLogger` là một hàm không làm gì cả
72+
*/
73+
loggerFn: ignoreLogger, // tùy chọn
5974
});
6075
```
6176

@@ -74,5 +89,9 @@ Trước khi bắt đầu, hãy đảm bảo rằng bạn đã đọc [hướng
7489
### Người đóng góp
7590

7691
<a href="https://github.com/lehuygiang28/vnpay/graphs/contributors">
77-
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" />
92+
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" alt="List of Contributors"/>
7893
</a>
94+
95+
## Giấy phép
96+
97+
**[MIT](LICENSE) © [Lê Huy Giang](https://github.com/lehuygiang28)**

README_en-US.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<br/>
1111

1212
<p align="center">
13-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/v/vnpay" alt="NPM Version" /></a>
14-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/l/vnpay" alt="Package License"><a>
15-
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/dm/vnpay" alt="NPM Downloads"></a>
13+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/v/vnpay" alt="NPM Version" /></a>
14+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/l/vnpay" alt="Package License"><a>
15+
<a href="https://www.npmjs.com/package/vnpay" target="_blank"><img src="https://img.shields.io/npm/d18m/vnpay" alt="NPM Downloads"></a>
1616
</p>
1717

1818
<strong>An open-source library support to payment with [VNPay](https://vnpay.vn).</strong>
@@ -40,22 +40,38 @@ $ yarn add vnpay
4040
Install `vnpay` with `pnpm`:
4141

4242
```bash
43-
$ pnpm add vnpay
43+
$ pnpm install vnpay
4444
```
4545

4646
## Usage:
4747

4848
#### Initialize
4949

5050
```typescript
51-
import { VNPay } from 'vnpay';
51+
import { VNPay, ignoreLogger } from 'vnpay';
5252

5353
const vnpay = new VNPay({
5454
tmnCode: '2QXUI4B4',
5555
secureSecret: 'secret',
5656
vnpayHost: 'https://sandbox.vnpayment.vn',
5757
testMode: true, // optional
5858
hashAlgorithm: 'SHA512', // optional
59+
60+
/**
61+
* On/off logger
62+
* If enableLog is false, loggerFn will not be used in any method
63+
*/
64+
enableLog: true, // optional
65+
66+
/**
67+
* `loggerFn` will be called to write log when enableLog is true
68+
* By default, loggerFn will write log to console
69+
* If you want to write log to other place, you can provide other function here
70+
*
71+
* `ignoreLogger` is a function do nothing
72+
*
73+
*/
74+
loggerFn: ignoreLogger, // optional
5975
});
6076
```
6177

@@ -74,5 +90,9 @@ Before contributing, please read our [Contribution Guidelines](.github/CONTRIBUT
7490
### Contributors
7591

7692
<a href="https://github.com/lehuygiang28/vnpay/graphs/contributors">
77-
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" />
93+
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" alt="List of Contributors"/>
7894
</a>
95+
96+
## License
97+
98+
**[MIT](LICENSE) © [Lê Huy Giang](https://github.com/lehuygiang28)**

docs/docs/01_intro.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Thư viện [VNPay](https://github.com/lehuygiang28/vnpay) là một dự án m
1111

1212
## Tài liệu
1313

14-
- Tìm hiểu cách sử dụng thư viện VNPay tại [đây](installation.md).
14+
- Tìm hiểu cách sử dụng thư viện VNPay tại [đây](/installation).
1515
- Bạn cũng có thể tìm hiểu cách VNPay hoạt động tại [đây](https://sandbox.vnpayment.vn/apis/).
1616

1717
- `vnpay` trên [GitHub](https://github.com/lehuygiang28/vnpay)
@@ -31,3 +31,7 @@ _[github.com/lehuygiang28](https://github.com/lehuygiang28)_
3131
<a href="https://github.com/lehuygiang28/vnpay/graphs/contributors" target="_blank">
3232
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" class="contributors_img" />
3333
</a>
34+
35+
## Giấy phép
36+
37+
**[MIT](https://github.com/lehuygiang28/vnpay/blob/main/LICENSE) © [Lê Huy Giang](https://github.com/lehuygiang28)**

docs/docs/02_installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $ yarn add vnpay
1717
### PNPM
1818

1919
```bash
20-
$ pnpm add vnpay
20+
$ pnpm install vnpay
2121
```
2222

2323
## Sử dụng thư viện
@@ -31,7 +31,7 @@ import { VNPay } from 'vnpay';
3131
### Khởi tạo đối tượng {#init-vnpay}
3232

3333
```typescript
34-
import { ignoreLogger } from 'vnpay';
34+
import { VNPay, ignoreLogger } from 'vnpay';
3535

3636
const vnpay = new VNPay({
3737
tmnCode: 'YOUR_TMNCODE',

docs/docs/04_create-payment-url.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Xem thêm các thuộc tính khác tại [VNPay](https://sandbox.vnpayment.vn/ap
5858

5959
## Sử dụng
6060

61-
### Sử dụng logger {#use-logger}
61+
### Sử dụng logger {#using-logger}
6262

6363
```typescript
6464
import { ProductCode, VnpLocale, consoleLogger } from 'vnpay';

docs/docs/05_ipn/02_verify-ipn-call.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { VerifyIpnCall } from 'vnpay';
1212
const verify: VerifyIpnCall = vnpay.verifyIpnCall(req.query);
1313
```
1414

15-
## Các thuộc tính của đối tượng `VerifyIpnCall`
15+
## Các thuộc tính của đối tượng `VerifyIpnCall` {#properties-of-the-verify-ipn-call}
1616

1717
Thông tin sau khi xác thực và của VNPay trả về
1818

@@ -34,7 +34,7 @@ Các tham số mà VNPay trả về cũng nằm trong đối tượng `VerifyIpn
3434
### Sử dụng logger
3535

3636
- Tương tự như khi tạo URL thanh toán, bạn có thể sử dụng logger để ghi log thông tin xác thực IPN
37-
[xem tại đây](create-payment-url.md#use-logger).
37+
[xem tại đây](/create-payment-url#using-logger).
3838

3939
### Với Express
4040

docs/docs/06_verify-return-url.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const verify: VerifyReturnUrl = vnpay.verifyReturnUrl(req.query);
1717
Thông tin sau khi xác thực và của VNPay trả về
1818

1919
:::info
20-
Giống với các thuộc tính của đối tượng [`VerifyIpnCall`](./verify-ipn-call.md#các-thuộc-tính-của-đối-tượng-verifyipncall)
20+
Giống với các thuộc tính của đối tượng [`VerifyIpnCall`](/ipn/verify-ipn-call#properties-of-the-verify-ipn-call)
2121
:::
2222

2323
## Sử dụng
2424

2525
### Sử dụng logger
2626

2727
- Tương tự như khi tạo URL thanh toán, bạn có thể sử dụng logger để ghi log thông tin xác thực return URL
28-
[xem tại đây](./create-payment-url.md#use-logger).
28+
[xem tại đây](/create-payment-url#using-logger).
2929

3030
### Với Express MVC
3131

docs/docs/07_query-dr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Các tham số mà [VNPay trả về](https://sandbox.vnpayment.vn/apis/docs/tru
6666

6767
### Với logger
6868

69-
- Để có thể sử dụng logger, bạn cần phải khởi tạo [`VNPay`](./installation.md#init-vnpay) với `enableLog``true`.
69+
- Để có thể sử dụng logger, bạn cần phải khởi tạo [`VNPay`](/installation#init-vnpay) với `enableLog``true`.
7070

7171
```typescript
7272
import { QueryDr, QueryDrResponse, getDateInGMT7, dateFormat } from 'vnpay';

docs/i18n/en/docusaurus-plugin-content-docs/current/intro.md renamed to docs/i18n/en/docusaurus-plugin-content-docs/current/01_intro.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The [VNPay](https://github.com/lehuygiang28/vnpay) library is an open source pro
1111

1212
## Documentation
1313

14-
- Learn how to use the VNPay library [here](installation.md).
14+
- Learn how to use the VNPay library [here](/installation).
1515
- You can also learn how VNPay works [here](https://sandbox.vnpayment.vn/apis/).
1616

1717
- `vnpay` on [GitHub](https://github.com/lehuygiang28/vnpay)
@@ -31,3 +31,7 @@ _[github.com/lehuygiang28](https://github.com/lehuygiang28)_
3131
<a href="https://github.com/lehuygiang28/vnpay/graphs/contributors" target="_blank">
3232
<img src="https://contrib.rocks/image?repo=lehuygiang28/vnpay&max=20" class="contributors_img" />
3333
</a>
34+
35+
## License
36+
37+
**[MIT](https://github.com/lehuygiang28/vnpay/blob/main/LICENSE) © [Lê Huy Giang](https://github.com/lehuygiang28)**
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Installation
2+
3+
## Installation with package managers
4+
5+
### NPM
6+
7+
```bash
8+
$ npm install vnpay
9+
```
10+
11+
### Yarn
12+
13+
```bash
14+
$ yarn add vnpay
15+
```
16+
17+
### PNPM
18+
19+
```bash
20+
$ pnpm install vnpay
21+
```
22+
23+
## Usage
24+
25+
### Import the library
26+
27+
```typescript
28+
import { VNPay } from 'vnpay';
29+
```
30+
31+
### Initialize the instance {#init-vnpay}
32+
33+
```typescript
34+
import { VNPay, ignoreLogger } from 'vnpay';
35+
36+
const vnpay = new VNPay({
37+
tmnCode: 'YOUR_TMNCODE',
38+
secureSecret: 'YOUR_SECURE_SECRET',
39+
vnpayHost: 'https://sandbox.vnpayment.vn',
40+
testMode: true, // optional, overrides vnpayHost to sandbox if true
41+
hashAlgorithm: 'SHA512', // optional
42+
43+
/**
44+
* On/off logger
45+
* If enableLog is false, loggerFn will not be used in any method
46+
*/
47+
enableLog: true, // optional
48+
49+
/**
50+
* `loggerFn` will be called to write log when enableLog is true
51+
* By default, loggerFn will write log to console
52+
* If you want to write log to other place, you can provide other function here
53+
*
54+
* `ignoreLogger` is a function do nothing
55+
*
56+
*/
57+
loggerFn: ignoreLogger, // optional
58+
});
59+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Bank List {#get-bank-list}
2+
3+
:::info
4+
Bank list, used for `vnp_BankCode`
5+
:::
6+
7+
## Get Bank List
8+
9+
```typescript
10+
import { Bank } from 'vnpay';
11+
12+
/* ... */
13+
14+
const bankList: Bank[] = await vnpay.getBankList();
15+
```
16+
17+
## Properties of `Bank` Object
18+
19+
| Property | Type | Description |
20+
| --------------- | -------- | -------------- |
21+
| `bank_code` | `string` | Bank code |
22+
| `bank_name` | `string` | Bank name |
23+
| `logo_link` | `string` | Bank logo link |
24+
| `bank_type` | `number` | Bank type |
25+
| `display_order` | `number` | Display order |
26+
27+
:::info
28+
See more [here](https://sandbox.vnpayment.vn/apis/docs/chuyen-doi-thuat-toan/changeTypeHash.html#tao-url-thanh-toan)
29+
:::

docs/i18n/en/docusaurus-plugin-content-docs/current/create-payment-url.md renamed to docs/i18n/en/docusaurus-plugin-content-docs/current/04_create-payment-url.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
sidebar_position: 3
3-
---
4-
51
# Create Payment URL
62

73
Create a payment URL for VNPay.
@@ -39,7 +35,59 @@ const paymentUrl = vnpay.buildPaymentUrl({
3935

4036
See more properties at [VNPay](https://sandbox.vnpayment.vn/apis/docs/thanh-toan-pay/pay.html#danh-s%C3%A1ch-tham-s%E1%BB%91).
4137

42-
## Use in Express
38+
## Usage
39+
40+
### Using logger {#using-logger}
41+
42+
```typescript
43+
import { ProductCode, VnpLocale, consoleLogger } from 'vnpay';
44+
45+
/* ... */
46+
47+
const paymentUrl = vnpay.buildPaymentUrl(
48+
{
49+
vnp_Amount: 10000,
50+
vnp_IpAddr: '1.1.1.1',
51+
vnp_TxnRef: '123456',
52+
vnp_OrderInfo: 'Payment for order 123456',
53+
vnp_OrderType: ProductCode.Other,
54+
vnp_ReturnUrl: `http://localhost:${port}/vnpay-return`,
55+
},
56+
{
57+
logger: {
58+
type: 'pick', // The mode to select log fields, can be 'pick', 'omit' or 'all'
59+
fields: ['createdAt', 'method', 'paymentUrl'], // Select the fields to log
60+
loggerFn: consoleLogger, // Log data to console, can be replaced with another function
61+
},
62+
},
63+
);
64+
```
65+
66+
### Using custom logger
67+
68+
```typescript
69+
import { ProductCode, VnpLocale } from 'vnpay';
70+
71+
/* ... */
72+
73+
const paymentUrl = vnpay.buildPaymentUrl(
74+
{
75+
vnp_Amount: 10000,
76+
vnp_IpAddr: '1.1.1.1',
77+
vnp_TxnRef: '123456',
78+
vnp_OrderInfo: 'Payment for order 123456',
79+
vnp_OrderType: ProductCode.Other,
80+
vnp_ReturnUrl: `http://localhost:${port}/vnpay-return`,
81+
},
82+
{
83+
logger: {
84+
type: 'pick', // The mode to select log fields, can be 'pick', 'omit' or 'all'
85+
fields: ['createdAt', 'method', 'paymentUrl'], // Select the fields to log
86+
loggerFn: (data) => logToDatabase(data), // Function to log data to database, you need to implement it
87+
},
88+
},
89+
);
90+
```
4391

4492
### With MVC
4593

0 commit comments

Comments
 (0)