paperless-client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/callback_data.d.ts +9 -0
- package/dist/callback_data.js +1 -0
- package/dist/check_payment.d.ts +36 -0
- package/dist/check_payment.js +19 -0
- package/dist/check_server.d.ts +12 -0
- package/dist/check_server.js +19 -0
- package/dist/format_description.d.ts +5 -0
- package/dist/format_description.js +8 -0
- package/dist/getway_url.d.ts +1 -0
- package/dist/getway_url.js +3 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +48 -0
- package/dist/initiate_payment.d.ts +38 -0
- package/dist/initiate_payment.js +26 -0
- package/dist/lib.d.ts +1 -0
- package/dist/lib.js +11 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rifat Mahmud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# paperless-client
|
|
2
|
+
|
|
3
|
+
A Node.js client for seamlessly interacting with the Paperless payment API. Built with TypeScript.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install `paperless-client` using npm, pnpm, or yarn:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install paperless-client
|
|
11
|
+
# or
|
|
12
|
+
pnpm add paperless-client
|
|
13
|
+
# or
|
|
14
|
+
yarn add paperless-client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Here is a quick example of how to initiate a payment and check its status.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import PaperlessClient, { formatDescription } from 'paperless-client'
|
|
23
|
+
|
|
24
|
+
// 1. Initialize the client
|
|
25
|
+
const client = new PaperlessClient(
|
|
26
|
+
'YOUR_MUID',
|
|
27
|
+
'YOUR_APP_ACCESS_KEY',
|
|
28
|
+
'YOUR_MERCHANT_REF_ID',
|
|
29
|
+
'https://payment-sandbox.paperlessltd.com' // or production URL
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
// 2. Generate a Payment URL
|
|
33
|
+
async function initiate() {
|
|
34
|
+
const url = await client.getPaymentUrl({
|
|
35
|
+
merchant_order_id: '105',
|
|
36
|
+
customer_name: 'John Doe',
|
|
37
|
+
customer_email: 'john@example.com',
|
|
38
|
+
customer_phone: '01700000000',
|
|
39
|
+
product_desc: formatDescription([
|
|
40
|
+
{ name: 'Product 1', count: 2, perItemPrice: 100 }
|
|
41
|
+
]),
|
|
42
|
+
amount: '200',
|
|
43
|
+
currency: 'BDT',
|
|
44
|
+
approve_url: 'https://example.com/approve',
|
|
45
|
+
cancel_url: 'https://example.com/cancel',
|
|
46
|
+
decline_url: 'https://example.com/decline'
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
console.log('Redirect user to ->', url)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 3. Check Payment Status
|
|
53
|
+
async function checkStatus(token: string) {
|
|
54
|
+
const status = await client.checkPaymentStatus(token)
|
|
55
|
+
console.log('Transaction Status:', status.txn_status)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type CheckPaymentResponseType = {
|
|
2
|
+
success: false;
|
|
3
|
+
data: any;
|
|
4
|
+
} | {
|
|
5
|
+
success: true;
|
|
6
|
+
data: {
|
|
7
|
+
muid: string;
|
|
8
|
+
ref_id: string;
|
|
9
|
+
token: string;
|
|
10
|
+
merchant_req_amount: string;
|
|
11
|
+
merchant_ref_id: string;
|
|
12
|
+
merchant_currency: string;
|
|
13
|
+
merchant_amount_bdt: string;
|
|
14
|
+
conversion_rate: string;
|
|
15
|
+
service_ratio: string;
|
|
16
|
+
card_charge_bdt: string;
|
|
17
|
+
emi_ratio: string;
|
|
18
|
+
emi_charge: string;
|
|
19
|
+
bank_amount_bdt: string;
|
|
20
|
+
discount_bdt: string;
|
|
21
|
+
merchant_order_id: string;
|
|
22
|
+
request_ip: string;
|
|
23
|
+
txn_status: 1000 | 1001 | 1009 | null;
|
|
24
|
+
extra_json: null;
|
|
25
|
+
card_details: null;
|
|
26
|
+
is_foreign: 0 | 1;
|
|
27
|
+
payment_card: string;
|
|
28
|
+
card_code: number;
|
|
29
|
+
payment_method: string;
|
|
30
|
+
init_time: string;
|
|
31
|
+
txn_time: string;
|
|
32
|
+
statusCode: number;
|
|
33
|
+
customer_details: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function checkPayment(origin: string, muid: string, token: string): Promise<CheckPaymentResponseType>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseBody } from "./lib.js";
|
|
2
|
+
export async function checkPayment(origin, muid, token) {
|
|
3
|
+
try {
|
|
4
|
+
const response = await fetch(`${origin}/api/v1/gateway/check-payment?muid=${muid}&token=${token}`);
|
|
5
|
+
if (!response.ok)
|
|
6
|
+
return { success: false, data: await parseBody(response) };
|
|
7
|
+
const data = await parseBody(response, true);
|
|
8
|
+
if (data === null) {
|
|
9
|
+
return { success: false, data: 'Failed to parse response' };
|
|
10
|
+
}
|
|
11
|
+
return { success: true, data };
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
data: 'An error occurred while checking payment status'
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CheckStatusResponseType = {
|
|
2
|
+
success: false;
|
|
3
|
+
data: any;
|
|
4
|
+
} | {
|
|
5
|
+
success: true;
|
|
6
|
+
data: {
|
|
7
|
+
selectedServer: boolean;
|
|
8
|
+
initiate_payment_url: string;
|
|
9
|
+
gateway_url: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function checkServer(origin: string): Promise<CheckStatusResponseType>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseBody } from "./lib.js";
|
|
2
|
+
export async function checkServer(origin) {
|
|
3
|
+
try {
|
|
4
|
+
const response = await fetch(`${origin}/api/v1/gateway/check-server`);
|
|
5
|
+
if (!response.ok)
|
|
6
|
+
return { success: false, data: await parseBody(response) };
|
|
7
|
+
const data = await response.json().catch(() => null);
|
|
8
|
+
if (data === null) {
|
|
9
|
+
return { success: false, data: 'Failed to parse response' };
|
|
10
|
+
}
|
|
11
|
+
return { success: true, data };
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
data: 'An error occurred while checking server status'
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function formatDescription(description) {
|
|
2
|
+
let descArr = [];
|
|
3
|
+
for (const item of description) {
|
|
4
|
+
const desc = `{${item.count} X ${item.name} [${item.perItemPrice}]=[${item.count * item.perItemPrice}]}`;
|
|
5
|
+
descArr.push(desc);
|
|
6
|
+
}
|
|
7
|
+
return descArr.join(' ');
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function gatewayUrl(token: string, gatewayUrlTemp: string): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type InitiatePaymentOptionsType } from './initiate_payment.ts';
|
|
2
|
+
import { formatDescription } from './format_description.ts';
|
|
3
|
+
export { formatDescription };
|
|
4
|
+
export { type CallbackDataType } from './callback_data.ts';
|
|
5
|
+
export type GetPaymentUrlOptionsType = Omit<InitiatePaymentOptionsType, 'muid' | 'access_app_key' | 'merchant_ref_id'>;
|
|
6
|
+
export default class PaperlessClient {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(muid: string, app_access_key: string, merchant_ref_id: string, host: string);
|
|
9
|
+
getPaymentUrl(options: GetPaymentUrlOptionsType): Promise<string>;
|
|
10
|
+
checkPaymentStatus(token: string): Promise<{
|
|
11
|
+
muid: string;
|
|
12
|
+
ref_id: string;
|
|
13
|
+
token: string;
|
|
14
|
+
merchant_req_amount: string;
|
|
15
|
+
merchant_ref_id: string;
|
|
16
|
+
merchant_currency: string;
|
|
17
|
+
merchant_amount_bdt: string;
|
|
18
|
+
conversion_rate: string;
|
|
19
|
+
service_ratio: string;
|
|
20
|
+
card_charge_bdt: string;
|
|
21
|
+
emi_ratio: string;
|
|
22
|
+
emi_charge: string;
|
|
23
|
+
bank_amount_bdt: string;
|
|
24
|
+
discount_bdt: string;
|
|
25
|
+
merchant_order_id: string;
|
|
26
|
+
request_ip: string;
|
|
27
|
+
txn_status: 1000 | 1001 | 1009 | null;
|
|
28
|
+
extra_json: null;
|
|
29
|
+
card_details: null;
|
|
30
|
+
is_foreign: 0 | 1;
|
|
31
|
+
payment_card: string;
|
|
32
|
+
card_code: number;
|
|
33
|
+
payment_method: string;
|
|
34
|
+
init_time: string;
|
|
35
|
+
txn_time: string;
|
|
36
|
+
statusCode: number;
|
|
37
|
+
customer_details: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { checkServer } from "./check_server.js";
|
|
2
|
+
import { initiatePayment } from "./initiate_payment.js";
|
|
3
|
+
import { gatewayUrl } from "./getway_url.js";
|
|
4
|
+
import { checkPayment } from "./check_payment.js";
|
|
5
|
+
import { formatDescription } from "./format_description.js";
|
|
6
|
+
export { formatDescription };
|
|
7
|
+
export {} from "./callback_data.js";
|
|
8
|
+
export default class PaperlessClient {
|
|
9
|
+
#muid;
|
|
10
|
+
#app_access_key;
|
|
11
|
+
#merchant_ref_id;
|
|
12
|
+
#host;
|
|
13
|
+
constructor(muid, app_access_key, merchant_ref_id, host) {
|
|
14
|
+
this.#muid = muid;
|
|
15
|
+
this.#app_access_key = app_access_key;
|
|
16
|
+
this.#merchant_ref_id = merchant_ref_id;
|
|
17
|
+
this.#host = host;
|
|
18
|
+
}
|
|
19
|
+
async getPaymentUrl(options) {
|
|
20
|
+
const checkServerResponse = await checkServer(this.#host);
|
|
21
|
+
if (!checkServerResponse.success) {
|
|
22
|
+
throw new Error('Server check failed', {
|
|
23
|
+
cause: checkServerResponse.data
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const initiatePaymentResponse = await initiatePayment(checkServerResponse.data.initiate_payment_url, {
|
|
27
|
+
...options,
|
|
28
|
+
muid: this.#muid,
|
|
29
|
+
access_app_key: this.#app_access_key,
|
|
30
|
+
merchant_ref_id: this.#merchant_ref_id
|
|
31
|
+
});
|
|
32
|
+
if (!initiatePaymentResponse.success) {
|
|
33
|
+
throw new Error('Payment initiation failed', {
|
|
34
|
+
cause: initiatePaymentResponse.data
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return gatewayUrl(initiatePaymentResponse.data.token, checkServerResponse.data.gateway_url);
|
|
38
|
+
}
|
|
39
|
+
async checkPaymentStatus(token) {
|
|
40
|
+
const checkPaymentResponse = await checkPayment(this.#host, this.#muid, token);
|
|
41
|
+
if (!checkPaymentResponse.success) {
|
|
42
|
+
throw new Error('Payment check failed', {
|
|
43
|
+
cause: checkPaymentResponse.data
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return checkPaymentResponse.data;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type InitiatePaymentOptionsType = {
|
|
2
|
+
muid: string;
|
|
3
|
+
access_app_key: string;
|
|
4
|
+
merchant_order_id: string;
|
|
5
|
+
merchant_ref_id: string;
|
|
6
|
+
customer_name: string;
|
|
7
|
+
customer_email: string;
|
|
8
|
+
customer_add?: string;
|
|
9
|
+
customer_phone: string;
|
|
10
|
+
customer_city?: string;
|
|
11
|
+
customer_postcode?: string;
|
|
12
|
+
customer_country?: string;
|
|
13
|
+
shipping_name?: string;
|
|
14
|
+
shipping_email?: string;
|
|
15
|
+
shipping_add?: string;
|
|
16
|
+
shipping_city?: string;
|
|
17
|
+
shipping_postcode?: string;
|
|
18
|
+
shipping_country?: string;
|
|
19
|
+
product_desc: string;
|
|
20
|
+
amount: string;
|
|
21
|
+
currency: string;
|
|
22
|
+
approve_url: string;
|
|
23
|
+
cancel_url: string;
|
|
24
|
+
decline_url: string;
|
|
25
|
+
};
|
|
26
|
+
export type InitiatePaymentResponseType = {
|
|
27
|
+
success: false;
|
|
28
|
+
data: any;
|
|
29
|
+
} | {
|
|
30
|
+
success: true;
|
|
31
|
+
data: {
|
|
32
|
+
statusCode: string;
|
|
33
|
+
statusMsg: string;
|
|
34
|
+
token: string;
|
|
35
|
+
merchant_callback_url_update: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function initiatePayment(url: string, options: InitiatePaymentOptionsType): Promise<InitiatePaymentResponseType>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseBody } from "./lib.js";
|
|
2
|
+
export async function initiatePayment(url, options) {
|
|
3
|
+
try {
|
|
4
|
+
const requestUrl = new URL(url);
|
|
5
|
+
for (const key in options) {
|
|
6
|
+
const value = options[key];
|
|
7
|
+
if (!value)
|
|
8
|
+
continue;
|
|
9
|
+
requestUrl.searchParams.append(key, value);
|
|
10
|
+
}
|
|
11
|
+
const response = await fetch(requestUrl, { method: 'POST' });
|
|
12
|
+
if (!response.ok)
|
|
13
|
+
return { success: false, data: await parseBody(response) };
|
|
14
|
+
const data = await response.json().catch(() => null);
|
|
15
|
+
if (data === null) {
|
|
16
|
+
return { success: false, data: 'Failed to parse response' };
|
|
17
|
+
}
|
|
18
|
+
return { success: true, data };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
data: 'An error occurred while initiating payment'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseBody(response: Response, onlyJson?: boolean): Promise<any>;
|
package/dist/lib.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "paperless-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A client for interacting with the Paperless payment API.",
|
|
5
|
+
"author": "Rifat Mahmud",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^25.8.0",
|
|
21
|
+
"typescript": "^6.0.3"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/RifatMahmudno-1/paperless-client.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/RifatMahmudno-1/paperless-client/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/RifatMahmudno-1/paperless-client#readme",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"start": "node ./src/index.ts",
|
|
33
|
+
"dev": "node --watch-path=./src --watch-preserve-output ./src/index.ts",
|
|
34
|
+
"build": "tsc"
|
|
35
|
+
}
|
|
36
|
+
}
|