Skip to content

Commit 922c71a

Browse files
committed
docs(i18n): 📝 update en translations
1 parent 5d35de7 commit 922c71a

File tree

13 files changed

+335
-70
lines changed

13 files changed

+335
-70
lines changed

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

docs/i18n/en/docusaurus-plugin-content-docs/current/config-ipn.md renamed to docs/i18n/en/docusaurus-plugin-content-docs/current/05_ipn/01_config-ipn.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
sidebar_position: 4
3-
---
4-
51
# Setting up IPN url
62

73
When the payment is completed, VNPay will send an IPN (Instant Payment Notification) call to the IPN URL that you have set up. To verify the IPN call, you can use the VNPay library.

docs/i18n/en/docusaurus-plugin-content-docs/current/verify-ipn-call.md renamed to docs/i18n/en/docusaurus-plugin-content-docs/current/05_ipn/02_verify-ipn-call.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
sidebar_position: 5
3-
---
4-
51
# Verify IPN Call
62

73
When the payment is completed, VNPay will send an IPN (Instant Payment Notification) call to the IPN URL that you have set up. To verify the IPN call, you can use the VNPay library.
@@ -16,7 +12,7 @@ import { VerifyIpnCall } from 'vnpay';
1612
const verify: VerifyIpnCall = vnpay.verifyIpnCall(req.query);
1713
```
1814

19-
## Properties of the `VerifyIpnCall`
15+
## Properties of the `VerifyIpnCall` {#properties-of-the-verify-ipn-call}
2016

2117
Information after verification and returned by VNPay
2218

@@ -33,7 +29,14 @@ See more properties VNPay will return at [VNPay](https://sandbox.vnpayment.vn/ap
3329
The parameters that VNPay returns are also in the `VerifyIpnCall`.
3430
:::
3531

36-
## Use in Express
32+
## Usage
33+
34+
### Using logger
35+
36+
- Similar to when creating a payment URL, you can use a logger to log IPN verification information
37+
[see here](/create-payment-url#using-logger).
38+
39+
### With Express
3740

3841
Steps to verify the return URL in Express:
3942

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "IPN",
3+
"collapsible": true,
4+
"collapsed": false
5+
}

docs/i18n/en/docusaurus-plugin-content-docs/current/verify-return-url.md renamed to docs/i18n/en/docusaurus-plugin-content-docs/current/06_verify-return-url.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
sidebar_position: 6
3-
---
4-
51
# Verify Return URL
62

73
When the customer successfully makes a payment, VNPay will redirect the customer to the return notification URL (`vnp_ReturnUrl`) that you have provided.
@@ -21,7 +17,7 @@ const verify: VerifyReturnUrl = vnpay.verifyReturnUrl(req.query);
2117
Information after verification and returned by VNPay
2218

2319
:::info
24-
Similar to the properties of the [`VerifyIpnCall`](./verify-ipn-call.md#properties-of-the-verifyipncall)
20+
Similar to the properties of the [`VerifyIpnCall`](/ipn/verify-ipn-call#properties-of-the-verify-ipn-call)
2521
:::
2622

2723
## Use in Express
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Query Transaction Result (queryDr) {#query-dr}
2+
3+
This is an API for the merchant system to query the payment result of a transaction at the VNPAY system.
4+
5+
:::warning
6+
7+
- `queryDr` is currently suitable for `PAY` payments
8+
- `token`, `installment`, `periodic` are not yet compatible
9+
10+
:::
11+
12+
## QueryDR
13+
14+
```typescript
15+
import { QueryDr, QueryDrResponse, getDateInGMT7, dateFormat } from 'vnpay';
16+
17+
/* ... */
18+
19+
/**
20+
* The date must be in GMT+7 timezone
21+
* And formatted as `yyyyMMddHHmmss`
22+
* Use the `getDateInGMT7` and `dateFormat` functions to convert
23+
*/
24+
const date = dateFormat(getDateInGMT7(new Date('2024/05/21')));
25+
26+
const res: QueryDrResponse = await vnpay.queryDr({
27+
vnp_RequestId: generateRandomString(16),
28+
vnp_IpAddr: '1.1.1.1',
29+
vnp_TxnRef: '1716257871703',
30+
vnp_TransactionNo: 14422574,
31+
vnp_OrderInfo: 'Payment for order',
32+
vnp_TransactionDate: date,
33+
vnp_CreateDate: date,
34+
} as QueryDr);
35+
```
36+
37+
## Properties
38+
39+
### `QueryDr` {#query-dr-properties}
40+
41+
| Property | Type | Description |
42+
| --------------------- | -------- | --------------------------------------------------------------------------------------- |
43+
| `vnp_RequestId` | `string` | Request ID for transaction result query. This ID must be unique for each query request. |
44+
| `vnp_IpAddr` | `string` | IP address of the client. |
45+
| `vnp_TxnRef` | `string` | Transaction code of the merchant system. |
46+
| `vnp_TransactionNo` | `number` | Transaction code of the VNPAY system. |
47+
| `vnp_OrderInfo` | `string` | Order information. |
48+
| `vnp_TransactionDate` | `number` | Transaction time. |
49+
| `vnp_CreateDate` | `number` | Transaction creation time. |
50+
51+
### `QueryDrResponse` {#query-dr-response-properties}
52+
53+
| Property | Type | Description |
54+
| ---------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55+
| isSuccess | boolean | Result of the request |
56+
| isVerified | boolean | Verification result of data integrity when received from VNPay |
57+
| message | string | Verification message |
58+
| ... | ... | Other parameters that VNPay will return, refer [here](https://sandbox.vnpayment.vn/apis/docs/truy-van-hoan-tien/querydr&refund.html#danh-sach-tham-so-querydr-VNPAY-response) |
59+
60+
See more properties that VNPay will return at [VNPay](https://sandbox.vnpayment.vn/apis/docs/truy-van-hoan-tien/querydr&refund.html#danh-sach-tham-so-querydr-VNPAY-response).
61+
:::tip
62+
The parameters that [VNPay returns](https://sandbox.vnpayment.vn/apis/docs/truy-van-hoan-tien/querydr&refund.html#danh-sach-tham-so-querydr-VNPAY-response) are also in the `QueryDrResponse` object.
63+
:::
64+
65+
## Usage
66+
67+
### With logger
68+
69+
- To be able to use the logger, you need to initialize [`VNPay`](/installation#init-vnpay) with `enableLog` set to `true`.
70+
71+
```typescript
72+
import { QueryDr, QueryDrResponse, getDateInGMT7, dateFormat } from 'vnpay';
73+
74+
/* ... */
75+
76+
/**
77+
* The date must be in GMT+7 timezone
78+
* And formatted as `yyyyMMddHHmmss`
79+
* Use the `getDateInGMT7` and `dateFormat` functions to convert
80+
*/
81+
const date = dateFormat(getDateInGMT7(new Date('2024/05/21')));
82+
83+
const res: QueryDrResponse = await vnpay.queryDr(
84+
{
85+
vnp_RequestId: generateRandomString(16),
86+
vnp_IpAddr: '1.1.1.1',
87+
vnp_TxnRef: '1716257871703',
88+
vnp_TransactionNo: 14422574,
89+
vnp_OrderInfo: 'Payment for order',
90+
vnp_TransactionDate: date,
91+
vnp_CreateDate: date,
92+
} as QueryDr,
93+
{
94+
logger: {
95+
type: 'all',
96+
loggerFn: (data) => {
97+
console.log(data.message);
98+
// Or send log to server, database, ...
99+
},
100+
},
101+
},
102+
);
103+
```

0 commit comments

Comments
 (0)