@yosle/tropipayjs 0.1.28 → 0.2.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/index.d.ts CHANGED
@@ -40,6 +40,7 @@ interface UserHookSubscribed extends UserHook {
40
40
  updatedAt: string;
41
41
  }
42
42
  interface PaymentLinkPayload {
43
+ accountId: number;
43
44
  reference: string;
44
45
  concept: string;
45
46
  favorite: boolean;
@@ -413,7 +414,9 @@ declare class ServerSideUtils {
413
414
  private tropipay;
414
415
  constructor(tropipayInstance: Tropipay);
415
416
  /**
416
- * Verify Topipay's signature on webhooks.
417
+ * DEPRECATED Verify Topipay's signature on API V2 webhooks.
418
+ * @deprecated This method is deprecated and will be removed in future versions.
419
+ * Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
417
420
  * @param credentials Credential object or Tropipay instance
418
421
  * @param {String} originalCurrencyAmount
419
422
  * @param bankOrderCode
@@ -452,6 +455,17 @@ declare class ServerSideUtils {
452
455
  * @return {Promise<string>} the valid base64 image
453
456
  */
454
457
  static isValidImage(base64Image: string): boolean;
458
+ /**
459
+ * Verify Topipay's signature on API V3 webhooks.
460
+ * @param {string} originalCurrencyAmount
461
+ * @param {string} bankOrderCode
462
+ * @param {string} signature signaturev3 field to be verified
463
+ * @returns {boolean}
464
+ */
465
+ static verifySignatureV3(credentials: {
466
+ clientId: string;
467
+ clientSecret: string;
468
+ } | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
455
469
  }
456
470
 
457
471
  declare const SERVER_MODE: ServerMode$1;
package/index.js CHANGED
@@ -220,7 +220,7 @@ class PaymentCard {
220
220
  await this.tropipay.login();
221
221
  }
222
222
  try {
223
- const paylink = await this.tropipay.request.post("/api/v2/paymentcards", payload, {
223
+ const paylink = await this.tropipay.request.post("/api/v3/paymentcards", payload, {
224
224
  headers: {
225
225
  "Content-Type": "application/json",
226
226
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -243,7 +243,7 @@ class PaymentCard {
243
243
  await this.tropipay.login();
244
244
  }
245
245
  try {
246
- const paymentcards = await this.tropipay.request.get(`/api/v2/paymentcards`, {
246
+ const paymentcards = await this.tropipay.request.get(`/api/v3/paymentcards`, {
247
247
  headers: {
248
248
  "Content-Type": "application/json",
249
249
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -268,7 +268,7 @@ class PaymentCard {
268
268
  await this.tropipay.login();
269
269
  }
270
270
  try {
271
- const paymentcard = await this.tropipay.request.get(`/api/v2/paymentcards/${id}`, {
271
+ const paymentcard = await this.tropipay.request.get(`/api/v3/paymentcards/${id}`, {
272
272
  headers: {
273
273
  "Content-Type": "application/json",
274
274
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -294,7 +294,7 @@ class PaymentCard {
294
294
  await this.tropipay.login();
295
295
  }
296
296
  try {
297
- const paymentcard = await this.tropipay.request.delete(`/api/v2/paymentcards/`, {
297
+ const paymentcard = await this.tropipay.request.delete(`/api/v3/paymentcards/`, {
298
298
  headers: {
299
299
  "Content-Type": "application/json",
300
300
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -360,7 +360,7 @@ class DepositAccounts {
360
360
  await this.tropipay.login();
361
361
  }
362
362
  try {
363
- const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts`, {
363
+ const deposit = await this.tropipay.request.get(`/api/v3/deposit_accounts`, {
364
364
  headers: {
365
365
  "Content-Type": "application/json",
366
366
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -383,7 +383,7 @@ class DepositAccounts {
383
383
  await this.tropipay.login();
384
384
  }
385
385
  try {
386
- const deposit = await this.tropipay.request.post("/api/v2/deposit_accounts", depositAccountObj, {
386
+ const deposit = await this.tropipay.request.post("/api/v3/deposit_accounts", depositAccountObj, {
387
387
  headers: {
388
388
  "Content-Type": "application/json",
389
389
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -407,7 +407,7 @@ class DepositAccounts {
407
407
  await this.tropipay.login();
408
408
  }
409
409
  try {
410
- const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts/${id}`, {
410
+ const deposit = await this.tropipay.request.get(`/api/v3/deposit_accounts/${id}`, {
411
411
  headers: {
412
412
  "Content-Type": "application/json",
413
413
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -430,7 +430,7 @@ class DepositAccounts {
430
430
  await this.tropipay.login();
431
431
  }
432
432
  try {
433
- const deposit = await this.tropipay.request.put(`/api/v2/deposit_accounts/`, {
433
+ const deposit = await this.tropipay.request.put(`/api/v3/deposit_accounts/`, {
434
434
  headers: {
435
435
  "Content-Type": "application/json",
436
436
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -453,7 +453,7 @@ class DepositAccounts {
453
453
  await this.tropipay.login();
454
454
  }
455
455
  try {
456
- const deposit = await this.tropipay.request.delete(`/api/v2/deposit_accounts/${id}`, {
456
+ const deposit = await this.tropipay.request.delete(`/api/v3/deposit_accounts/${id}`, {
457
457
  headers: {
458
458
  "Content-Type": "application/json",
459
459
  Authorization: `Bearer ${Tropipay.accessToken}`,
@@ -519,7 +519,7 @@ class Tropipay {
519
519
  this.serverMode = config.serverMode || "Development";
520
520
  const tpp_env = this.serverMode === "Production"
521
521
  ? "https://www.tropipay.com"
522
- : "https://tropipay-dev.herokuapp.com";
522
+ : "https://sandbox.tropipay.me";
523
523
  this.request = axios__default["default"].create({
524
524
  baseURL: config.customTropipayUrl || tpp_env,
525
525
  headers: {
@@ -533,12 +533,11 @@ class Tropipay {
533
533
  baseURL: config.customTropipayUrl || tpp_env,
534
534
  headers: {
535
535
  "Content-Type": "application/json",
536
- Accept: "application/json"
536
+ Accept: "application/json",
537
537
  },
538
538
  });
539
539
  // Add request interceptor for Token expired
540
540
  this.request.interceptors.request.use(async (config) => {
541
- console.log("Executing interceptor!!");
542
541
  const currentTimestamp = Math.floor(Date.now() / 1000);
543
542
  if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
544
543
  console.debug("Token expired, attempting to log in");
@@ -563,7 +562,7 @@ class Tropipay {
563
562
  async login() {
564
563
  try {
565
564
  // normal credetials login
566
- const { data } = await this.loginRequest.post("/api/v2/access/token", {
565
+ const { data } = await this.loginRequest.post("/api/v3/access/token", {
567
566
  client_id: this.clientId,
568
567
  client_secret: this.clientSecret,
569
568
  grant_type: "client_credentials",
@@ -579,7 +578,6 @@ class Tropipay {
579
578
  return data;
580
579
  }
581
580
  catch (error) {
582
- console.log("RAW login error ", error);
583
581
  Tropipay.accessToken = null;
584
582
  Tropipay.refreshToken = null;
585
583
  Tropipay.expiresIn = null;
@@ -770,7 +768,9 @@ class ServerSideUtils {
770
768
  this.tropipay = tropipayInstance;
771
769
  }
772
770
  /**
773
- * Verify Topipay's signature on webhooks.
771
+ * DEPRECATED Verify Topipay's signature on API V2 webhooks.
772
+ * @deprecated This method is deprecated and will be removed in future versions.
773
+ * Use the `verifySignatureV3` method from the `ServerSideUtils` class instead.
774
774
  * @param credentials Credential object or Tropipay instance
775
775
  * @param {String} originalCurrencyAmount
776
776
  * @param bankOrderCode
@@ -860,6 +860,28 @@ class ServerSideUtils {
860
860
  throw new Error(`Error checking base64 image`);
861
861
  }
862
862
  }
863
+ /**
864
+ * Verify Topipay's signature on API V3 webhooks.
865
+ * @param {string} originalCurrencyAmount
866
+ * @param {string} bankOrderCode
867
+ * @param {string} signature signaturev3 field to be verified
868
+ * @returns {boolean}
869
+ */
870
+ static verifySignatureV3(credentials, originalCurrencyAmount, bankOrderCode, signature) {
871
+ const sha1Secret = crypto__namespace
872
+ .createHash("sha1")
873
+ .update(credentials.clientSecret)
874
+ .digest("hex");
875
+ const dataToHash = bankOrderCode +
876
+ credentials.clientId +
877
+ sha1Secret +
878
+ originalCurrencyAmount;
879
+ const localSignature = crypto__namespace
880
+ .createHash("sha256")
881
+ .update(dataToHash)
882
+ .digest("hex");
883
+ return localSignature === signature;
884
+ }
863
885
  }
864
886
 
865
887
  const SERVER_MODE = "Development"; // Move the constant here
@@ -36,6 +36,7 @@ export interface UserHookSubscribed extends UserHook {
36
36
  updatedAt: string;
37
37
  }
38
38
  export interface PaymentLinkPayload {
39
+ accountId: number;
39
40
  reference: string;
40
41
  concept: string;
41
42
  favorite: boolean;
@@ -46,6 +46,7 @@ declare enum Reasons {
46
46
  SENDING_YOU_A_KISS = 80
47
47
  }
48
48
  export interface PaymentLinkPayload {
49
+ accountId: number;
49
50
  reference: string;
50
51
  concept: string;
51
52
  favorite: boolean;
@@ -60,9 +61,6 @@ export interface PaymentLinkPayload {
60
61
  urlFailed: string;
61
62
  urlNotification: string;
62
63
  serviceDate: string;
63
- /**
64
- * fgfsgdfgdfgd
65
- */
66
64
  client?: {
67
65
  name: string;
68
66
  lastName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.28",
3
+ "version": "0.2.0",
4
4
  "description": "Javascript / Typescript SDK for the Tropipay API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,4 +46,4 @@
46
46
  "type": "individual",
47
47
  "url": "https://tppay.me/l94qaa3h"
48
48
  }
49
- }
49
+ }
@@ -27,7 +27,7 @@ export class Tropipay {
27
27
  readonly clientSecret: string;
28
28
  readonly scopes: String[];
29
29
  public request: Axios;
30
- public loginRequest: Axios;
30
+ public loginRequest: Axios;
31
31
  public static accessToken: string | null;
32
32
  public static refreshToken: string | null;
33
33
  public static expiresIn: number | null;
@@ -73,11 +73,12 @@ export class Tropipay {
73
73
  this.clientSecret = config.clientSecret;
74
74
  this.serverMode = config.serverMode || "Development";
75
75
 
76
- const tpp_env = this.serverMode === "Production"
77
- ? "https://www.tropipay.com"
78
- : "https://tropipay-dev.herokuapp.com";
76
+ const tpp_env =
77
+ this.serverMode === "Production"
78
+ ? "https://www.tropipay.com"
79
+ : "https://sandbox.tropipay.me";
79
80
  this.request = axios.create({
80
- baseURL: config.customTropipayUrl || tpp_env,
81
+ baseURL: config.customTropipayUrl || tpp_env,
81
82
  headers: {
82
83
  "Content-Type": "application/json",
83
84
  Accept: "application/json",
@@ -85,21 +86,20 @@ export class Tropipay {
85
86
  },
86
87
  });
87
88
 
88
- // Create a separate instance for login requests
89
- this.loginRequest = axios.create({
90
- baseURL: config.customTropipayUrl || tpp_env,
91
- headers: {
92
- "Content-Type": "application/json",
93
- Accept: "application/json"
94
- },
95
- });
89
+ // Create a separate instance for login requests
90
+ this.loginRequest = axios.create({
91
+ baseURL: config.customTropipayUrl || tpp_env,
92
+ headers: {
93
+ "Content-Type": "application/json",
94
+ Accept: "application/json",
95
+ },
96
+ });
96
97
 
97
- // Add request interceptor for Token expired
98
- this.request.interceptors.request.use(
98
+ // Add request interceptor for Token expired
99
+ this.request.interceptors.request.use(
99
100
  async (config) => {
100
- console.log("Executing interceptor!!");
101
101
  const currentTimestamp = Math.floor(Date.now() / 1000);
102
-
102
+
103
103
  if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
104
104
  console.debug("Token expired, attempting to log in");
105
105
  try {
@@ -107,34 +107,28 @@ export class Tropipay {
107
107
  } catch (error) {
108
108
  throw handleExceptions(error as Error);
109
109
  }
110
- }
110
+ }
111
111
  // Update the Authorization header in the config
112
- config.headers.Authorization = `Bearer ${Tropipay.accessToken}`;
112
+ config.headers.Authorization = `Bearer ${Tropipay.accessToken}`;
113
113
  return config;
114
114
  },
115
115
  (error) => {
116
116
  return Promise.reject(error);
117
117
  }
118
118
  );
119
-
120
119
 
121
120
  this.hooks = new TropipayHooks(this);
122
121
  this.paymentCards = new PaymentCard(this);
123
122
  this.mediationPaymentCard = new MediationPaymentCard(this);
124
123
 
125
124
  this.depositAccounts = new DepositAccounts(this);
126
-
127
-
128
-
129
-
130
125
  }
131
126
 
132
127
  public async login() {
133
128
  try {
134
-
135
129
  // normal credetials login
136
130
  const { data } = await this.loginRequest.post<LoginResponse>(
137
- "/api/v2/access/token",
131
+ "/api/v3/access/token",
138
132
  {
139
133
  client_id: this.clientId,
140
134
  client_secret: this.clientSecret,
@@ -149,13 +143,10 @@ export class Tropipay {
149
143
  }
150
144
  );
151
145
 
152
-
153
146
  Tropipay.accessToken = data.access_token;
154
147
  Tropipay.expiresIn = data.expires_in;
155
148
  return data;
156
149
  } catch (error) {
157
-
158
- console.log("RAW login error ", error)
159
150
  Tropipay.accessToken = null;
160
151
  Tropipay.refreshToken = null;
161
152
  Tropipay.expiresIn = null;
@@ -18,7 +18,7 @@ export default class DepositAccounts {
18
18
  }
19
19
  try {
20
20
  const deposit = await this.tropipay.request.get(
21
- `/api/v2/deposit_accounts`,
21
+ `/api/v3/deposit_accounts`,
22
22
  {
23
23
  headers: {
24
24
  "Content-Type": "application/json",
@@ -43,7 +43,7 @@ export default class DepositAccounts {
43
43
  }
44
44
  try {
45
45
  const deposit = await this.tropipay.request.post(
46
- "/api/v2/deposit_accounts",
46
+ "/api/v3/deposit_accounts",
47
47
  depositAccountObj,
48
48
  {
49
49
  headers: {
@@ -70,7 +70,7 @@ export default class DepositAccounts {
70
70
  }
71
71
  try {
72
72
  const deposit = await this.tropipay.request.get(
73
- `/api/v2/deposit_accounts/${id}`,
73
+ `/api/v3/deposit_accounts/${id}`,
74
74
  {
75
75
  headers: {
76
76
  "Content-Type": "application/json",
@@ -96,7 +96,7 @@ export default class DepositAccounts {
96
96
  }
97
97
  try {
98
98
  const deposit = await this.tropipay.request.put(
99
- `/api/v2/deposit_accounts/`,
99
+ `/api/v3/deposit_accounts/`,
100
100
  {
101
101
  headers: {
102
102
  "Content-Type": "application/json",
@@ -122,7 +122,7 @@ export default class DepositAccounts {
122
122
  }
123
123
  try {
124
124
  const deposit = await this.tropipay.request.delete(
125
- `/api/v2/deposit_accounts/${id}`,
125
+ `/api/v3/deposit_accounts/${id}`,
126
126
  {
127
127
  headers: {
128
128
  "Content-Type": "application/json",
@@ -64,6 +64,7 @@ export interface UserHookSubscribed extends UserHook {
64
64
  }
65
65
 
66
66
  export interface PaymentLinkPayload {
67
+ accountId: number;
67
68
  reference: string;
68
69
  concept: string;
69
70
  favorite: boolean;
@@ -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;