@yosle/tropipayjs 0.2.1 → 0.2.3

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,264 +1,212 @@
1
- import { ServerMode } from "../constants/TropipayConstants";
2
-
3
- export type AccountBalance = {
4
- balance: number;
5
- pendingIn: number;
6
- pendingOut: number;
7
- };
8
-
9
- export interface TropipayConfig {
10
- clientId: string;
11
- clientSecret: string;
12
- scopes?: string[];
13
- serverMode?: ServerMode;
14
- // Custom tropipay environment for testing
15
- customTropipayUrl?: string;
16
- }
17
-
18
- export type TropipayCredentials = { clientId: string; clientSecret: string };
19
- export type HookEventType =
20
- | "transaction_completed"
21
- | "transaction_charged"
22
- | "transaction_guarded"
23
- | "user_signup"
24
- | "user_kyc"
25
- | "payment_in_state_change"
26
- | "payment_out_state_change"
27
- | "beneficiary_added"
28
- | "beneficiary_updated"
29
- | "beneficiary_deleted"
30
- | "transaction_new"
31
- | "transaction_preauthorized"
32
- | "transaction_pendingin"
33
- | "transaction_processing"
34
- | "transaction_error"
35
- | "transaction_bloqued"
36
- | "transaction_guarded_send"
37
- | "transaction_guarded_mediation"
38
- | "user_after_update"
39
- | "user_after_create"
40
- | "userDetail_after_create"
41
- | "userDetail_after_update"
42
- | "tpv_callback_ok"
43
- | "fraud_state_on_change";
44
-
45
- export type HookTargetType = "web" | "email";
46
- export interface UserHook {
47
- event: HookEventType;
48
- target: string;
49
- value: string;
50
- }
51
- export interface UserHookSubscribed extends UserHook {
52
- createdAt: string;
53
- updatedAt: string;
54
- }
55
-
56
- export interface UserHook {
57
- event: HookEventType;
58
- target: string;
59
- value: string;
60
- }
61
- export interface UserHookSubscribed extends UserHook {
62
- createdAt: string;
63
- updatedAt: string;
64
- }
65
-
66
- /**
67
- * Interface for creating payment links/cards
68
- * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
69
- */
70
- export interface PaymentLinkPayload {
71
- /** Account ID where the funds will be received if compatible */
72
- accountId?: number;
73
-
74
- /** Reference code for the payment, preferred to be unique */
75
- reference: string;
76
-
77
- /** Short description of the payment */
78
- concept: string;
79
-
80
- /** Whether to mark this payment link as favorite */
81
- favorite: boolean;
82
-
83
- /** Amount to charge in the specified currency */
84
- amount: number;
85
-
86
- /** Currency code (EUR, USD, etc.) */
87
- currency: string;
88
-
89
- /** Detailed description of the payment */
90
- description: string;
91
-
92
- /** If true, the payment link can only be used once */
93
- singleUse: boolean;
94
-
95
- /** Reason ID for the payment */
96
- reasonId: number;
97
-
98
- /** Number of days until the payment link expires */
99
- expirationDays: number;
100
-
101
- /** Language code for the payment page (en, es, etc.) */
102
- lang: string;
103
-
104
- /** URL to redirect after successful payment */
105
- urlSuccess: string;
106
-
107
- /** URL to redirect after failed payment */
108
- urlFailed: string;
109
-
110
- /** Webhook URL for payment notifications */
111
- urlNotification: string;
112
-
113
- /** Date when the service will be provided (ISO format) */
114
- serviceDate: string;
115
-
116
- /** Client information for the payment */
117
- client?: {
118
- /** Client's first name */
119
- name?: string;
120
-
121
- /** Client's last name */
122
- lastName?: string;
123
-
124
- /** Client's address */
125
- address?: string;
126
-
127
- /** Client's phone number */
128
- phone?: string;
129
-
130
- /** Client's email address */
131
- email?: string;
132
-
133
- /** Client's country ID */
134
- countryId?: number;
135
-
136
- /** Client's country ISO code */
137
- countryIso?: string;
138
-
139
- /** Client's city */
140
- city: string;
141
-
142
- /** Client's postal code */
143
- postCode: string;
144
-
145
- /** Whether client accepted terms and conditions */
146
- termsAndConditions: boolean;
147
- } | null;
148
-
149
- /** @deprecated If true, redirects directly to payment page */
150
- directPayment: boolean;
151
-
152
- /** List of allowed payment methods */
153
- paymentMethods?: string[];
154
-
155
- /** Base64 encoded image for the payment page */
156
- imageBase?: string;
157
-
158
- /** Whether to save the payment token for future use */
159
- saveToken?: boolean;
160
- }
161
-
162
- export interface PaymentLink extends PaymentLinkPayload {
163
- expirationDate: string;
164
- hasClient: boolean;
165
- updatedAt: string;
166
- createdAt: string;
167
- qrImage: string;
168
- shortUrl: string;
169
- paymentUrl: string;
170
- }
171
-
172
- export interface MediationPaymentCardConfig {
173
- amount: number;
174
- currency: "EUR" | "USD";
175
- concept: string;
176
- description: string;
177
- reference: string;
178
- singleUse: boolean;
179
- lang: string;
180
- productUrl?: string;
181
- buyer: null | any;
182
- seller: {
183
- sellerId?: number;
184
- type?: number;
185
- email?: string;
186
- };
187
- feePercent?: number;
188
- feeFixed?: number;
189
- sendMail: boolean;
190
- }
191
-
192
- export type LoginResponse = {
193
- access_token: string;
194
- refresh_token: string;
195
- token_type: "Bearer";
196
- expires_in: number;
197
- scope: string;
198
- };
199
-
200
- export type LoginError = {
201
- error: string;
202
- };
203
-
204
- export type Country = {
205
- id: number;
206
- name: string;
207
- sepaZone: boolean;
208
- state: number;
209
- slug: string;
210
- slugn: number;
211
- callingCode: number;
212
- isDestination: boolean;
213
- isRisky: boolean;
214
- currentCurrency: string | null;
215
- createdAt: string;
216
- updatedAt: string;
217
- isFavorite: boolean;
218
- position: any;
219
- };
220
-
221
- export type Deposit = {
222
- id: number;
223
- accountNumber: string;
224
- alias: string;
225
- swift: string;
226
- type: number;
227
- country: number | null;
228
- firstName: string;
229
- default: null;
230
- state: number;
231
- userId: string;
232
- countryDestinationId: number;
233
- lastName: string;
234
- documentNumber: number;
235
- userRelationTypeId: number;
236
- city: string;
237
- postalCode: string;
238
- address: string;
239
- phone: string;
240
- checked: boolean;
241
- province: string;
242
- beneficiaryType: number;
243
- relatedUserId: null | string;
244
- currency: string;
245
- correspondent?: any;
246
- location: any;
247
- office: any;
248
- officeValue: any;
249
- paymentType: number;
250
- paymentEntityBeneficiaryId: number;
251
- paymentEntityAccountId: number;
252
- verified: any;
253
- paymentEntityInfo: any;
254
- documentTypeId: any;
255
- documentExpirationDate: Date;
256
- createdAt: Date;
257
- updatedAt: Date;
258
- countryDestination: Country;
259
- };
260
-
261
- export type AccountDeposits = {
262
- count: number;
263
- rows: Deposit[];
264
- };
1
+ import { ServerMode } from "../constants/TropipayConstants";
2
+
3
+ export type AccountBalance = {
4
+ balance: number;
5
+ pendingIn: number;
6
+ pendingOut: number;
7
+ };
8
+
9
+ export interface TropipayConfig {
10
+ clientId: string;
11
+ clientSecret: string;
12
+ scopes?: string[];
13
+ serverMode?: ServerMode;
14
+ // Custom tropipay environment for testing
15
+ customTropipayUrl?: string;
16
+ }
17
+
18
+ export type TropipayCredentials = { clientId: string; clientSecret: string };
19
+ export type HookEventType =
20
+ | "transaction_completed"
21
+ | "transaction_charged"
22
+ | "transaction_guarded"
23
+ | "user_signup"
24
+ | "user_kyc"
25
+ | "payment_in_state_change"
26
+ | "payment_out_state_change"
27
+ | "beneficiary_added"
28
+ | "beneficiary_updated"
29
+ | "beneficiary_deleted"
30
+ | "transaction_new"
31
+ | "transaction_preauthorized"
32
+ | "transaction_pendingin"
33
+ | "transaction_processing"
34
+ | "transaction_error"
35
+ | "transaction_bloqued"
36
+ | "transaction_guarded_send"
37
+ | "transaction_guarded_mediation"
38
+ | "user_after_update"
39
+ | "user_after_create"
40
+ | "userDetail_after_create"
41
+ | "userDetail_after_update"
42
+ | "tpv_callback_ok"
43
+ | "fraud_state_on_change";
44
+
45
+ export type HookTargetType = "web" | "email";
46
+ export interface UserHook {
47
+ event: HookEventType;
48
+ target: string;
49
+ value: string;
50
+ }
51
+ export interface UserHookSubscribed extends UserHook {
52
+ createdAt: string;
53
+ updatedAt: string;
54
+ }
55
+
56
+ export interface UserHook {
57
+ event: HookEventType;
58
+ target: string;
59
+ value: string;
60
+ }
61
+ export interface UserHookSubscribed extends UserHook {
62
+ createdAt: string;
63
+ updatedAt: string;
64
+ }
65
+
66
+ export interface PaymentLinkPayload {
67
+ reference: string;
68
+ concept: string;
69
+ favorite: boolean;
70
+ amount: number;
71
+ currency: string;
72
+ description: string;
73
+ singleUse: boolean;
74
+ reasonId: number;
75
+ expirationDays: number;
76
+ lang: string;
77
+ urlSuccess: string;
78
+ urlFailed: string;
79
+ urlNotification: string;
80
+ serviceDate: string;
81
+ client?: {
82
+ name?: string;
83
+ lastName?: string;
84
+ address?: string;
85
+ phone?: string;
86
+ email?: string;
87
+ countryId?: number;
88
+ countryIso?: string;
89
+ city: string;
90
+ postCode: string;
91
+ termsAndConditions: boolean;
92
+ } | null;
93
+ directPayment: boolean;
94
+ paymentMethods?: string[];
95
+ imageBase?: string;
96
+ saveToken?: boolean;
97
+ }
98
+
99
+ export interface PaymentLink extends PaymentLinkPayload {
100
+ expirationDate: string;
101
+ hasClient: boolean;
102
+ updatedAt: string;
103
+ createdAt: string;
104
+ qrImage: string;
105
+ shortUrl: string;
106
+ paymentUrl: string;
107
+ }
108
+
109
+ export interface MediationPaymentCardConfig {
110
+ amount: number;
111
+ currency: "EUR" | "USD";
112
+ concept: string;
113
+ description: string;
114
+ reference: string;
115
+ singleUse: boolean;
116
+ lang: string;
117
+ productUrl?: string;
118
+ buyer: null | any;
119
+ seller: {
120
+ sellerId?: number;
121
+ type?: number;
122
+ email?: string;
123
+ };
124
+ feePercent?: number;
125
+ feeFixed?: number;
126
+ sendMail: boolean;
127
+ }
128
+
129
+ export type LoginResponse = {
130
+ access_token: string;
131
+ refresh_token: string;
132
+ token_type: "Bearer";
133
+ expires_in: number;
134
+ scope: string;
135
+ };
136
+
137
+ export type LoginError = {
138
+ error: string;
139
+ };
140
+
141
+ export type Country = {
142
+ id: number;
143
+ name: string;
144
+ sepaZone: boolean;
145
+ state: number;
146
+ slug: string;
147
+ slugn: number;
148
+ callingCode: number;
149
+ isDestination: boolean;
150
+ isRisky: boolean;
151
+ currentCurrency: string | null;
152
+ createdAt: string;
153
+ updatedAt: string;
154
+ isFavorite: boolean;
155
+ position: any;
156
+ };
157
+
158
+ export type Deposit = {
159
+ id: number;
160
+ accountNumber: string;
161
+ alias: string;
162
+ swift: string;
163
+ type: number;
164
+ country: number | null;
165
+ firstName: string;
166
+ default: null;
167
+ state: number;
168
+ userId: string;
169
+ countryDestinationId: number;
170
+ lastName: string;
171
+ documentNumber: number;
172
+ userRelationTypeId: number;
173
+ city: string;
174
+ postalCode: string;
175
+ address: string;
176
+ phone: string;
177
+ checked: boolean;
178
+ province: string;
179
+ beneficiaryType: number;
180
+ relatedUserId: null | string;
181
+ currency: string;
182
+ correspondent?: any;
183
+ location: any;
184
+ office: any;
185
+ officeValue: any;
186
+ paymentType: number;
187
+ paymentEntityBeneficiaryId: number;
188
+ paymentEntityAccountId: number;
189
+ verified: any;
190
+ paymentEntityInfo: any;
191
+ documentTypeId: any;
192
+ documentExpirationDate: Date;
193
+ createdAt: Date;
194
+ updatedAt: Date;
195
+ countryDestination: Country;
196
+ };
197
+
198
+ export type AccountDeposits = {
199
+ count: number;
200
+ rows: Deposit[];
201
+ };
202
+
203
+ export type RefundResponse = {
204
+ id: number;
205
+ orderCode: string;
206
+ amount: number;
207
+ currency: string;
208
+ state: string;
209
+ type: string;
210
+ createdAt: string;
211
+ completedAt: string;
212
+ };
@@ -1,37 +1,36 @@
1
1
  export interface PaymentLinkPayload {
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[];
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[];
28
27
  }
29
28
  export interface PaymentLink extends PaymentLinkPayload {
30
- expirationDate: string;
31
- hasClient: boolean;
32
- updatedAt: string;
33
- createdAt: string;
34
- qrImage: string;
35
- shortUrl: string;
36
- paymentUrl: string;
29
+ expirationDate: string;
30
+ hasClient: boolean;
31
+ updatedAt: string;
32
+ createdAt: string;
33
+ qrImage: string;
34
+ shortUrl: string;
35
+ paymentUrl: string;
37
36
  }
@@ -50,7 +50,6 @@ enum Reasons {
50
50
  }
51
51
 
52
52
  export interface PaymentLinkPayload {
53
- accountId: number;
54
53
  reference: string;
55
54
  concept: string;
56
55
  favorite: boolean;
@@ -65,6 +64,9 @@ export interface PaymentLinkPayload {
65
64
  urlFailed: string;
66
65
  urlNotification: string;
67
66
  serviceDate: string;
67
+ /**
68
+ * fgfsgdfgdfgd
69
+ */
68
70
  client?: {
69
71
  name: string;
70
72
  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/v3/paymentcards",
23
+ "/api/v2/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/v3/paymentcards`,
49
+ `/api/v2/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/v3/paymentcards/${id}`,
77
+ `/api/v2/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/v3/paymentcards/`,
106
+ `/api/v2/paymentcards/`,
107
107
  {
108
108
  headers: {
109
109
  "Content-Type": "application/json",
@@ -11,9 +11,7 @@ export class ServerSideUtils {
11
11
  }
12
12
 
13
13
  /**
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.
14
+ * Verify Topipay's signature on webhooks.
17
15
  * @param credentials Credential object or Tropipay instance
18
16
  * @param {String} originalCurrencyAmount
19
17
  * @param bankOrderCode
@@ -125,41 +123,4 @@ export class ServerSideUtils {
125
123
  throw new Error(`Error checking base64 image`);
126
124
  }
127
125
  }
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
- }
165
126
  }
package/tsconfig.json CHANGED
@@ -24,12 +24,12 @@
24
24
  /* Modules */
25
25
  "module": "esnext" /* Specify what module code is generated. */,
26
26
  "rootDir": "./src" /* Specify the root folder within your source files. */,
27
- "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
27
+ "moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
28
28
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
29
29
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
30
30
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
31
31
  // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
32
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
32
+ "types": ["node", "jest"], /* Specify type package names to be included without being referenced in a source file. */
33
33
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
34
34
  // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
35
35
  // "resolveJsonModule": true, /* Enable importing .json files. */