paperless-client 1.0.1 → 1.0.2

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.
@@ -1,7 +1,10 @@
1
1
  import { parseBody } from "./lib.js";
2
2
  export async function checkPayment(origin, muid, token) {
3
3
  try {
4
- const response = await fetch(`${origin}/api/v1/gateway/check-payment?muid=${muid}&token=${token}`);
4
+ const url = new URL(`${origin}/api/v1/gateway/check-payment`);
5
+ url.searchParams.append('muid', muid);
6
+ url.searchParams.append('token', token);
7
+ const response = await fetch(url, { method: 'POST' });
5
8
  if (!response.ok)
6
9
  return { success: false, data: await parseBody(response) };
7
10
  const data = await parseBody(response, true);
package/dist/index.d.ts CHANGED
@@ -5,9 +5,25 @@ export { type CallbackDataType } from './callback_data.ts';
5
5
  export type GetPaymentUrlOptionsType = Omit<InitiatePaymentOptionsType, 'muid' | 'access_app_key'>;
6
6
  export default class PaperlessClient {
7
7
  #private;
8
+ /**
9
+ * @param muid It will be provided upon registration
10
+ * @param app_access_key It will be provided upon registration
11
+ * @param host The origin of the server
12
+ */
8
13
  constructor(muid: string, app_access_key: string, host: string);
9
- getPaymentUrl(options: GetPaymentUrlOptionsType): Promise<string>;
10
- checkPaymentStatus(token: string): Promise<{
14
+ /**
15
+ * merchant_order_id and merchant_ref_id should be unique for each payment.
16
+ * marchant_order_id is the order id is used by Peperless to identify the order. Max 20 characters.
17
+ * merchant_ref_id is used by the merchant to identify the order in the dashboard.
18
+ */
19
+ newPayment(options: GetPaymentUrlOptionsType): Promise<{
20
+ url: string;
21
+ token: string;
22
+ }>;
23
+ /**
24
+ * @param token The token received from the newPayment method
25
+ */
26
+ checkPayment(token: string): Promise<{
11
27
  muid: string;
12
28
  ref_id: string;
13
29
  token: string;
package/dist/index.js CHANGED
@@ -9,12 +9,22 @@ export default class PaperlessClient {
9
9
  #muid;
10
10
  #app_access_key;
11
11
  #host;
12
+ /**
13
+ * @param muid It will be provided upon registration
14
+ * @param app_access_key It will be provided upon registration
15
+ * @param host The origin of the server
16
+ */
12
17
  constructor(muid, app_access_key, host) {
13
18
  this.#muid = muid;
14
19
  this.#app_access_key = app_access_key;
15
20
  this.#host = host;
16
21
  }
17
- async getPaymentUrl(options) {
22
+ /**
23
+ * merchant_order_id and merchant_ref_id should be unique for each payment.
24
+ * marchant_order_id is the order id is used by Peperless to identify the order. Max 20 characters.
25
+ * merchant_ref_id is used by the merchant to identify the order in the dashboard.
26
+ */
27
+ async newPayment(options) {
18
28
  const checkServerResponse = await checkServer(this.#host);
19
29
  if (!checkServerResponse.success) {
20
30
  throw new Error('Server check failed', {
@@ -31,9 +41,15 @@ export default class PaperlessClient {
31
41
  cause: initiatePaymentResponse.data
32
42
  });
33
43
  }
34
- return gatewayUrl(initiatePaymentResponse.data.token, checkServerResponse.data.gateway_url);
44
+ return {
45
+ url: gatewayUrl(initiatePaymentResponse.data.token, checkServerResponse.data.gateway_url),
46
+ token: initiatePaymentResponse.data.token
47
+ };
35
48
  }
36
- async checkPaymentStatus(token) {
49
+ /**
50
+ * @param token The token received from the newPayment method
51
+ */
52
+ async checkPayment(token) {
37
53
  const checkPaymentResponse = await checkPayment(this.#host, this.#muid, token);
38
54
  if (!checkPaymentResponse.success) {
39
55
  throw new Error('Payment check failed', {
@@ -4,7 +4,7 @@ export async function initiatePayment(url, options) {
4
4
  const requestUrl = new URL(url);
5
5
  for (const key in options) {
6
6
  const value = options[key];
7
- if (!value)
7
+ if (value === undefined)
8
8
  continue;
9
9
  requestUrl.searchParams.append(key, value);
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperless-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A client for interacting with the Paperless payment API.",
5
5
  "author": "Rifat Mahmud",
6
6
  "license": "MIT",