@yosle/tropipayjs 0.1.28 → 0.2.1

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,36 +1,37 @@
1
1
  export interface PaymentLinkPayload {
2
- reference: string;
3
- concept: string;
4
- favorite: boolean;
5
- amount: number;
6
- currency: string;
7
- description: string;
8
- singleUse: boolean;
9
- reasonId: number;
10
- expirationDays: number;
11
- lang: string;
12
- urlSuccess: string;
13
- urlFailed: string;
14
- urlNotification: string;
15
- serviceDate: string;
16
- client: {
17
- name: string;
18
- lastName: string;
19
- address: string;
20
- phone: string;
21
- email: string;
22
- countryId: number;
23
- termsAndConditions: boolean;
24
- };
25
- directPayment: boolean;
26
- paymentMethods?: string[];
2
+ accountId: number;
3
+ reference: string;
4
+ concept: string;
5
+ favorite: boolean;
6
+ amount: number;
7
+ currency: string;
8
+ description: string;
9
+ singleUse: boolean;
10
+ reasonId: number;
11
+ expirationDays: number;
12
+ lang: string;
13
+ urlSuccess: string;
14
+ urlFailed: string;
15
+ urlNotification: string;
16
+ serviceDate: string;
17
+ client: {
18
+ name: string;
19
+ lastName: string;
20
+ address: string;
21
+ phone: string;
22
+ email: string;
23
+ countryId: number;
24
+ termsAndConditions: boolean;
25
+ };
26
+ directPayment: boolean;
27
+ paymentMethods?: string[];
27
28
  }
28
29
  export interface PaymentLink extends PaymentLinkPayload {
29
- expirationDate: string;
30
- hasClient: boolean;
31
- updatedAt: string;
32
- createdAt: string;
33
- qrImage: string;
34
- shortUrl: string;
35
- paymentUrl: string;
30
+ expirationDate: string;
31
+ hasClient: boolean;
32
+ updatedAt: string;
33
+ createdAt: string;
34
+ qrImage: string;
35
+ shortUrl: string;
36
+ paymentUrl: string;
36
37
  }
@@ -50,6 +50,7 @@ enum Reasons {
50
50
  }
51
51
 
52
52
  export interface PaymentLinkPayload {
53
+ accountId: number;
53
54
  reference: string;
54
55
  concept: string;
55
56
  favorite: boolean;
@@ -64,9 +65,6 @@ export interface PaymentLinkPayload {
64
65
  urlFailed: string;
65
66
  urlNotification: string;
66
67
  serviceDate: string;
67
- /**
68
- * fgfsgdfgdfgd
69
- */
70
68
  client?: {
71
69
  name: string;
72
70
  lastName: string;
@@ -20,7 +20,7 @@ export default class PaymentCard {
20
20
  }
21
21
  try {
22
22
  const paylink = await this.tropipay.request.post(
23
- "/api/v2/paymentcards",
23
+ "/api/v3/paymentcards",
24
24
  payload,
25
25
  {
26
26
  headers: {
@@ -46,7 +46,7 @@ export default class PaymentCard {
46
46
  }
47
47
  try {
48
48
  const paymentcards = await this.tropipay.request.get(
49
- `/api/v2/paymentcards`,
49
+ `/api/v3/paymentcards`,
50
50
  {
51
51
  headers: {
52
52
  "Content-Type": "application/json",
@@ -74,7 +74,7 @@ export default class PaymentCard {
74
74
  }
75
75
  try {
76
76
  const paymentcard = await this.tropipay.request.get(
77
- `/api/v2/paymentcards/${id}`,
77
+ `/api/v3/paymentcards/${id}`,
78
78
  {
79
79
  headers: {
80
80
  "Content-Type": "application/json",
@@ -103,7 +103,7 @@ export default class PaymentCard {
103
103
  }
104
104
  try {
105
105
  const paymentcard = await this.tropipay.request.delete(
106
- `/api/v2/paymentcards/`,
106
+ `/api/v3/paymentcards/`,
107
107
  {
108
108
  headers: {
109
109
  "Content-Type": "application/json",
@@ -11,7 +11,9 @@ export class ServerSideUtils {
11
11
  }
12
12
 
13
13
  /**
14
- * Verify Topipay's signature on webhooks.
14
+ * DEPRECATED Verify Topipay's signature on API V2 webhooks.
15
+ * @deprecated This method is deprecated and will be removed in future versions.
16
+ * Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
15
17
  * @param credentials Credential object or Tropipay instance
16
18
  * @param {String} originalCurrencyAmount
17
19
  * @param bankOrderCode
@@ -123,4 +125,41 @@ export class ServerSideUtils {
123
125
  throw new Error(`Error checking base64 image`);
124
126
  }
125
127
  }
128
+
129
+ /**
130
+ * Verify Topipay's signature on API V3 webhooks.
131
+ * @param {string} originalCurrencyAmount
132
+ * @param {string} bankOrderCode
133
+ * @param {string} signature signaturev3 field to be verified
134
+ * @returns {boolean}
135
+ */
136
+ public static verifySignatureV3(
137
+ credentials:
138
+ | {
139
+ clientId: string;
140
+ clientSecret: string;
141
+ }
142
+ | Tropipay,
143
+ originalCurrencyAmount: string,
144
+ bankOrderCode: string,
145
+ signature: string
146
+ ): boolean {
147
+ const sha1Secret = crypto
148
+ .createHash("sha1")
149
+ .update(credentials.clientSecret)
150
+ .digest("hex");
151
+
152
+ const dataToHash =
153
+ bankOrderCode +
154
+ credentials.clientId +
155
+ sha1Secret +
156
+ originalCurrencyAmount;
157
+
158
+ const localSignature = crypto
159
+ .createHash("sha256")
160
+ .update(dataToHash)
161
+ .digest("hex");
162
+
163
+ return localSignature === signature;
164
+ }
126
165
  }
@@ -3,7 +3,9 @@ export declare class ServerSideUtils {
3
3
  private tropipay;
4
4
  constructor(tropipayInstance: Tropipay);
5
5
  /**
6
- * Verify Topipay's signature on webhooks.
6
+ * DEPRECATED Verify Topipay's signature on API V2 webhooks.
7
+ * @deprecated This method is deprecated and will be removed in future versions.
8
+ * Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
7
9
  * @param credentials Credential object or Tropipay instance
8
10
  * @param {String} originalCurrencyAmount
9
11
  * @param bankOrderCode
@@ -42,4 +44,15 @@ export declare class ServerSideUtils {
42
44
  * @return {Promise<string>} the valid base64 image
43
45
  */
44
46
  static isValidImage(base64Image: string): boolean;
47
+ /**
48
+ * Verify Topipay's signature on API V3 webhooks.
49
+ * @param {string} originalCurrencyAmount
50
+ * @param {string} bankOrderCode
51
+ * @param {string} signature signaturev3 field to be verified
52
+ * @returns {boolean}
53
+ */
54
+ static verifySignatureV3(credentials: {
55
+ clientId: string;
56
+ clientSecret: string;
57
+ } | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
45
58
  }
@@ -1 +0,0 @@
1
- declare function sum(a: number, b: number): number;