prospay-sdk 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.
@@ -0,0 +1,325 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { HttpService } from '@nestjs/axios';
3
+ import { lastValueFrom } from 'rxjs';
4
+
5
+ export interface CreateCustomerDto {
6
+ productId: string;
7
+ productCustomerId: string;
8
+ orgName: string;
9
+ customerType: string;
10
+ contacts: {
11
+ email: string;
12
+ mobileNumber: string;
13
+ };
14
+ }
15
+
16
+ export interface UpdateCustomerDto {
17
+ productId?: string;
18
+ creditPeriodInDays?: string;
19
+ uin?: string;
20
+ preferences?: {
21
+ isMainOrg?: boolean;
22
+ mainOrgCustomerId?: string;
23
+ shareWallet?: boolean;
24
+ customerIdForWallet?: string;
25
+ shareKYC?: boolean;
26
+ customerIdForKYC?: string;
27
+ paymentType?: string;
28
+ };
29
+ isDeliveryAllowed?: boolean;
30
+ billingType?: string;
31
+ invoiceGenerationPeriod?: string;
32
+ CIN?: string;
33
+ status?: string;
34
+ creditlimit?: number;
35
+ contacts?: {
36
+ email?: string;
37
+ mobileNumber?: string;
38
+ };
39
+ industryType?: string;
40
+ KYC?: {
41
+ businessType?: string;
42
+ isGSTRegistered?: boolean;
43
+ GST?: string;
44
+ customerConsent?: boolean;
45
+ };
46
+ address?: {
47
+ line1?: string;
48
+ line2?: string;
49
+ city?: string;
50
+ state?: string;
51
+ pincode?: string;
52
+ stateCode?: string;
53
+ };
54
+ }
55
+
56
+ export interface UpdateCustomerStatusDto {
57
+ productId: string;
58
+ status: string;
59
+ }
60
+
61
+ export interface ProspayCreateCustomerResponse {
62
+ status: number;
63
+ message: string;
64
+ data: {
65
+ customerId: string;
66
+ customerData: any;
67
+ virtualAccountNo: string | null;
68
+ uin: string | null;
69
+ qrString: string | null;
70
+ isDeliveryAllowed: boolean;
71
+ creditPeriodInDays: string;
72
+ };
73
+ }
74
+
75
+ export interface ProspayErrorResponse {
76
+ message: string;
77
+ }
78
+
79
+ export interface ProspayUpdateCustomerResponse {
80
+ status: number;
81
+ message: string;
82
+ data: {
83
+ uin: string;
84
+ creditPeriodInDays: string;
85
+ customerId: string;
86
+ customerData: any;
87
+ kycData: any;
88
+ creditLimit: {
89
+ walletId: string;
90
+ oldCreditLimit: number;
91
+ newCreditLimit: number;
92
+ newAvailableBalance: number;
93
+ currency: string;
94
+ updatedAt: string;
95
+ };
96
+ };
97
+ }
98
+
99
+ export interface ProspayUpdateCustomerStatusResponse {
100
+ status: number;
101
+ message: string;
102
+ data: {
103
+ uin: string;
104
+ creditPeriodInDays: number;
105
+ customerId: string;
106
+ customerData: any;
107
+ };
108
+ }
109
+
110
+ export interface ProspayGetCustomerByIdResponseItem {
111
+ onBoardedDate: string;
112
+ kycStatus: string | null;
113
+ virtualAccountNo: {
114
+ customer: any;
115
+ };
116
+ qrString: string | null;
117
+ creditPeriodInDays: number;
118
+ productId: string;
119
+ productCustomerId: string;
120
+ customerId: string;
121
+ isMainOrg: boolean;
122
+ mainOrgCustomerId: string | null;
123
+ businessType: string | null;
124
+ payment_type: string;
125
+ billingType: string;
126
+ productOrgId: string;
127
+ invoiceGenerationPeriod: string;
128
+ cin: string | null;
129
+ uin: string | null;
130
+ orgId: string;
131
+ tenantId: string;
132
+ isGstRegistered: boolean | null;
133
+ name: string;
134
+ industryType: string | null;
135
+ contact: {
136
+ email: string;
137
+ mobileNumber: string;
138
+ };
139
+ customerType: string[];
140
+ isDeliveryAllowed: boolean;
141
+ status: string;
142
+ productName: string;
143
+ orgName: string;
144
+ businessSegment: string;
145
+ bankDetails: {
146
+ bankName: string | null;
147
+ ifscCode: string | null;
148
+ accountNo: string | null;
149
+ accountHolderName: string | null;
150
+ account_type: string | null;
151
+ UPI_id: string | null;
152
+ bankBranch: string | null;
153
+ };
154
+ aadhar: string | null;
155
+ businessPAN: string | null;
156
+ signatoryPAN: string | null;
157
+ GST: string | null;
158
+ tan: string | null;
159
+ DL: string | null;
160
+ signatoryPanfromGST: string | null;
161
+ businessPanfromGST: string | null;
162
+ signatoryPanfromAadhar: string | null;
163
+ address: {
164
+ addressLine1: string | null;
165
+ addressLine2: string | null;
166
+ state: string | null;
167
+ pinCode: string | null;
168
+ city: string | null;
169
+ stateCode: string | null;
170
+ };
171
+ hoDetails: any;
172
+ kyc: any;
173
+ creditlimit: number;
174
+ creditbalance: number;
175
+ }
176
+
177
+ export interface ProspayGetCustomerByIdResponse {
178
+ status: number;
179
+ message: string;
180
+ data: ProspayGetCustomerByIdResponseItem[];
181
+ cached: boolean;
182
+ }
183
+
184
+ export interface SearchCustomersParams {
185
+ filter?: string; // e.g. "all"
186
+ mobileNumber?: string;
187
+ productCustomerId?: string;
188
+ customerType?: string;
189
+ }
190
+
191
+ export interface ProspaySearchCustomersResponse {
192
+ status: number;
193
+ message: string;
194
+ data: any; // structure not provided; keeping broad until sample is shared
195
+ }
196
+
197
+ @Injectable()
198
+ export class ProspayCustomerService {
199
+ constructor(private readonly http: HttpService) {}
200
+
201
+ /**
202
+ * Create a new customer.
203
+ * Maps to:
204
+ * POST /customer/api/v3.0/customers
205
+ */
206
+ async createCustomer(
207
+ authToken: string,
208
+ payload: CreateCustomerDto,
209
+ ): Promise<ProspayCreateCustomerResponse> {
210
+ const response$ = this.http.post(
211
+ '/customer/api/v3.0/customers',
212
+ payload,
213
+ {
214
+ headers: {
215
+ Authorization: authToken,
216
+ 'Content-Type': 'application/json',
217
+ },
218
+ },
219
+ );
220
+
221
+ const response = await lastValueFrom(response$);
222
+ return response.data;
223
+ }
224
+
225
+ /**
226
+ * Update an existing customer by Prospay customer ID.
227
+ * Maps to:
228
+ * PATCH /customer/api/v3.0/customers/{customerId}/
229
+ */
230
+ async updateCustomer(
231
+ authToken: string,
232
+ customerId: string,
233
+ payload: UpdateCustomerDto,
234
+ ): Promise<ProspayUpdateCustomerResponse> {
235
+ const response$ = this.http.patch(
236
+ `/customer/api/v3.0/customers/${customerId}/`,
237
+ payload,
238
+ {
239
+ headers: {
240
+ Authorization: authToken,
241
+ 'Content-Type': 'application/json',
242
+ },
243
+ },
244
+ );
245
+
246
+ const response = await lastValueFrom(response$);
247
+ return response.data;
248
+ }
249
+
250
+ /**
251
+ * Update customer status (enabled/disabled).
252
+ * Maps to:
253
+ * PATCH /customer/api/v3.0/customers/{customerId}/
254
+ * with body:
255
+ * { "productId": "...", "status": "enabled" | "disabled" | ... }
256
+ */
257
+ async updateCustomerStatus(
258
+ authToken: string,
259
+ customerId: string,
260
+ payload: UpdateCustomerStatusDto,
261
+ ): Promise<ProspayUpdateCustomerStatusResponse> {
262
+ const response$ = this.http.patch(
263
+ `/customer/api/v3.0/customers/${customerId}/`,
264
+ payload,
265
+ {
266
+ headers: {
267
+ Authorization: authToken,
268
+ 'Content-Type': 'application/json',
269
+ },
270
+ },
271
+ );
272
+
273
+ const response = await lastValueFrom(response$);
274
+ return response.data;
275
+ }
276
+
277
+ /**
278
+ * Get customer by Prospay customer ID.
279
+ * Maps to:
280
+ * GET /customer/api/v3.0/customers/{customerId}?filter=all
281
+ */
282
+ async getCustomerById(
283
+ authToken: string,
284
+ customerId: string,
285
+ ): Promise<ProspayGetCustomerByIdResponse> {
286
+ const response$ = this.http.get(
287
+ `/customer/api/v3.0/customers/${customerId}`,
288
+ {
289
+ params: { filter: 'all' },
290
+ headers: {
291
+ Authorization: authToken,
292
+ },
293
+ },
294
+ );
295
+
296
+ const response = await lastValueFrom(response$);
297
+ return response.data;
298
+ }
299
+
300
+ /**
301
+ * Search customers using query params.
302
+ * Example params: filter=all, mobileNumber=..., productCustomerId=..., customerType=...
303
+ * Maps to:
304
+ * GET /customer/api/v3.0/customers/search
305
+ */
306
+ async searchCustomers(
307
+ authToken: string,
308
+ params: SearchCustomersParams,
309
+ ): Promise<ProspaySearchCustomersResponse> {
310
+ const response$ = this.http.get(
311
+ '/customer/api/v3.0/customers/search',
312
+ {
313
+ params,
314
+ headers: {
315
+ Authorization: authToken,
316
+ },
317
+ },
318
+ );
319
+
320
+ const response = await lastValueFrom(response$);
321
+ return response.data;
322
+ }
323
+ }
324
+
325
+
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ import 'reflect-metadata';
2
+ import { Module, DynamicModule } from '@nestjs/common';
3
+ import { HttpModule } from '@nestjs/axios';
4
+ import { ProspayAuthService } from './auth/auth.service';
5
+ import { ProspayCustomerService } from './customer/customer.service';
6
+ import { ProspayTransactionService } from './transaction/transaction.service';
7
+ import { ProspayInvoiceService } from './invoice/invoice.service';
8
+ import { PROSPAY_SDK_OPTIONS, ProspaySdkOptions } from './sdk.config';
9
+
10
+ @Module({})
11
+ export class ProspaySdkModule {
12
+ static register(options: ProspaySdkOptions): DynamicModule {
13
+ const baseUrl = options.baseUrl ?? 'https://sandbox.prospay.tech';
14
+
15
+ return {
16
+ module: ProspaySdkModule,
17
+ imports: [
18
+ HttpModule.register({
19
+ baseURL: baseUrl,
20
+ timeout: 5000,
21
+ }),
22
+ ],
23
+ providers: [
24
+ {
25
+ provide: PROSPAY_SDK_OPTIONS,
26
+ useValue: options,
27
+ },
28
+ ProspayAuthService,
29
+ ProspayCustomerService,
30
+ ProspayTransactionService,
31
+ ProspayInvoiceService,
32
+ ],
33
+ exports: [ProspayAuthService, ProspayCustomerService, ProspayTransactionService, ProspayInvoiceService],
34
+ };
35
+ }
36
+ }
37
+
38
+ export * from '@nestjs/common';
39
+ export * from './auth/auth.service';
40
+ export * from './customer/customer.service';
41
+ export * from './transaction/transaction.service';
42
+ export * from './invoice/invoice.service';
43
+ export * from './sdk.config';
44
+
@@ -0,0 +1,161 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { HttpService } from '@nestjs/axios';
3
+ import { lastValueFrom } from 'rxjs';
4
+
5
+ export interface GenerateBulkInvoiceDto {
6
+ templateName: string;
7
+ productId: string;
8
+ startDate: string; // YYYY-MM-DD
9
+ endDate: string; // YYYY-MM-DD
10
+ buyer_customerId: string;
11
+ seller_customerId: string;
12
+ due_date: string; // YYYY-MM-DD
13
+ invoice_no: string;
14
+ invoice_date: string; // e.g. DD-MM-YYYY
15
+ invoice_period: string;
16
+ }
17
+
18
+ export interface ProspayGenerateInvoiceResponse {
19
+ status: string; // e.g. "ok"
20
+ message: string; // e.g. "Process initiated for generating invoice"
21
+ refId: string;
22
+ }
23
+
24
+ export interface BulkInvoiceItem {
25
+ endDate: string;
26
+ startDate: string;
27
+ buyer_customerId: string;
28
+ seller_customerId: string;
29
+ productId: string;
30
+ due_date: string;
31
+ invoice_no: string;
32
+ invoice_date: string;
33
+ invoice_period: string;
34
+ }
35
+
36
+ export interface GenerateBulkInvoiceBatchDto {
37
+ templateName: string;
38
+ data: BulkInvoiceItem[];
39
+ }
40
+
41
+ export interface GenerateInvoiceDto {
42
+ templateName: string;
43
+ productId: string;
44
+ startDate: string; // YYYY-MM-DD
45
+ endDate: string; // YYYY-MM-DD
46
+ buyer_customerId: string;
47
+ seller_customerId: string;
48
+ due_date: string; // YYYY-MM-DD
49
+ invoice_no: string;
50
+ invoice_date: string; // e.g. DD-MM-YYYY
51
+ invoice_period: string;
52
+ }
53
+
54
+ export interface InvoiceStatusStatistics {
55
+ total: number;
56
+ success: number;
57
+ failed: number;
58
+ processing: number;
59
+ }
60
+
61
+ export interface InvoiceStatusItem {
62
+ invoiceId: string | null;
63
+ status: string;
64
+ createdAt: string;
65
+ customerId: string;
66
+ pdfUrl?: string;
67
+ completedAt?: string;
68
+ error?: string;
69
+ errorDetails?: any;
70
+ }
71
+
72
+ export interface ProspayInvoiceStatusResponse {
73
+ refId: string;
74
+ overallStatus: string;
75
+ templateName: string | null;
76
+ productId: string;
77
+ statistics: InvoiceStatusStatistics;
78
+ invoices: InvoiceStatusItem[];
79
+ }
80
+
81
+ @Injectable()
82
+ export class ProspayInvoiceService {
83
+ constructor(private readonly http: HttpService) {}
84
+
85
+ /**
86
+ * Generate bulk invoice.
87
+ * Maps to:
88
+ * POST /invoices/api/v2.0/generateBulkInvoice
89
+ */
90
+ async generateBulkInvoice(
91
+ authToken: string,
92
+ payload: GenerateBulkInvoiceDto,
93
+ callbackUrl?: string,
94
+ ): Promise<ProspayGenerateInvoiceResponse> {
95
+ const response$ = this.http.post(
96
+ '/invoices/api/v2.0/generateBulkInvoice',
97
+ payload,
98
+ {
99
+ headers: {
100
+ Authorization: authToken,
101
+ 'Content-Type': 'application/json',
102
+ ...(callbackUrl ? { 'callback-url': callbackUrl } : {}),
103
+ },
104
+ },
105
+ );
106
+
107
+ const response = await lastValueFrom(response$);
108
+ return response.data;
109
+ }
110
+
111
+ /**
112
+ * Generate a single invoice.
113
+ * Maps to:
114
+ * POST /invoices/api/v2.0/generateInvoice
115
+ */
116
+ async generateInvoice(
117
+ authToken: string,
118
+ payload: GenerateInvoiceDto,
119
+ callbackUrl?: string,
120
+ ): Promise<ProspayGenerateInvoiceResponse> {
121
+ const response$ = this.http.post(
122
+ '/invoices/api/v2.0/generateInvoice',
123
+ payload,
124
+ {
125
+ headers: {
126
+ Authorization: authToken,
127
+ 'Content-Type': 'application/json',
128
+ ...(callbackUrl ? { 'callback-url': callbackUrl } : {}),
129
+ },
130
+ },
131
+ );
132
+
133
+ const response = await lastValueFrom(response$);
134
+ return response.data;
135
+ }
136
+
137
+ /**
138
+ * Get invoice generation status by refId.
139
+ * Maps to:
140
+ * GET /invoices/api/v2.0/invoice-status/{refId}
141
+ */
142
+ async getInvoiceStatus(
143
+ authToken: string,
144
+ refId: string,
145
+ ): Promise<ProspayInvoiceStatusResponse> {
146
+ const response$ = this.http.get(
147
+ `/invoices/api/v2.0/invoice-status/${refId}`,
148
+ {
149
+ headers: {
150
+ Authorization: authToken,
151
+ 'Content-Type': 'application/json',
152
+ },
153
+ },
154
+ );
155
+
156
+ const response = await lastValueFrom(response$);
157
+ return response.data;
158
+ }
159
+ }
160
+
161
+
@@ -0,0 +1,21 @@
1
+ export const PROSPAY_SDK_OPTIONS = 'PROSPAY_SDK_OPTIONS';
2
+
3
+ export interface ProspaySdkOptions {
4
+ /**
5
+ * Prospay product identifier (used as resourceId header and in hash).
6
+ */
7
+ productId: string;
8
+
9
+ /**
10
+ * Prospay product API key (used only to generate the bcrypt hash).
11
+ */
12
+ productApiKey: string;
13
+
14
+ /**
15
+ * Optional base URL; defaults to Prospay sandbox.
16
+ * Example: https://sandbox.prospay.tech
17
+ */
18
+ baseUrl?: string;
19
+ }
20
+
21
+