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.
- package/README.md +155 -0
- package/dist/auth/auth.service.d.ts +10 -0
- package/dist/auth/auth.service.js +88 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/customer/customer.service.d.ts +191 -0
- package/dist/customer/customer.service.js +76 -0
- package/dist/customer/customer.service.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/invoice/invoice.service.d.ts +76 -0
- package/dist/invoice/invoice.service.js +58 -0
- package/dist/invoice/invoice.service.js.map +1 -0
- package/dist/sdk.config.d.ts +6 -0
- package/dist/sdk.config.js +5 -0
- package/dist/sdk.config.js.map +1 -0
- package/dist/transaction/transaction.service.d.ts +145 -0
- package/dist/transaction/transaction.service.js +66 -0
- package/dist/transaction/transaction.service.js.map +1 -0
- package/manual.txt +47 -0
- package/package.json +37 -0
- package/src/auth/auth.service.ts +63 -0
- package/src/customer/customer.service.ts +325 -0
- package/src/index.ts +44 -0
- package/src/invoice/invoice.service.ts +161 -0
- package/src/sdk.config.ts +21 -0
- package/src/transaction/transaction.service.ts +261 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { HttpService } from '@nestjs/axios';
|
|
3
|
+
import { lastValueFrom } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
export interface TransactionChargeBreakup {
|
|
6
|
+
head: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
appliedOn: string[];
|
|
9
|
+
tags: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TransactionChargeMetadata {
|
|
13
|
+
key: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TransactionCharge {
|
|
18
|
+
head: string;
|
|
19
|
+
amount: number;
|
|
20
|
+
hsnOrSac: string;
|
|
21
|
+
isBillable: boolean;
|
|
22
|
+
absorbedBy: string;
|
|
23
|
+
transactionType: string;
|
|
24
|
+
/**
|
|
25
|
+
* ISO datetime string when the charge was applied.
|
|
26
|
+
* Optional for create transaction, required for add-charges use case.
|
|
27
|
+
*/
|
|
28
|
+
chargedAt?: string;
|
|
29
|
+
breakup?: TransactionChargeBreakup[];
|
|
30
|
+
metadata?: TransactionChargeMetadata[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CreateTransactionDto {
|
|
34
|
+
customerId: string;
|
|
35
|
+
entityType: string; // e.g. "order"
|
|
36
|
+
referenceId: string;
|
|
37
|
+
currency: string; // e.g. "INR"
|
|
38
|
+
vertical: string; // e.g. "customer"
|
|
39
|
+
charges: TransactionCharge[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AddChargesToTransactionDto {
|
|
43
|
+
charges: TransactionCharge[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TransactionDateRangeFilter {
|
|
47
|
+
start: string; // ISO datetime
|
|
48
|
+
end: string; // ISO datetime
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface TransactionSearchFilters {
|
|
52
|
+
customerIds?: string[];
|
|
53
|
+
transactionDateRange?: TransactionDateRangeFilter;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SearchTransactionsDto {
|
|
57
|
+
page: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
transactionFilters: TransactionSearchFilters;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ChargeSummaryParams {
|
|
63
|
+
startDate: string; // YYYY-MM-DD
|
|
64
|
+
endDate: string; // YYYY-MM-DD
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ProspayCreateTransactionSuccessResponse {
|
|
68
|
+
success: true;
|
|
69
|
+
requestId: string;
|
|
70
|
+
path: string;
|
|
71
|
+
timestamp: string;
|
|
72
|
+
data: {
|
|
73
|
+
transactionId: string;
|
|
74
|
+
summary: {
|
|
75
|
+
transactionAmount: number;
|
|
76
|
+
billableAmount: number;
|
|
77
|
+
totalCreditAmount: number;
|
|
78
|
+
totalDebitAmount: number;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ProspayCreateTransactionErrorResponse {
|
|
84
|
+
success: false;
|
|
85
|
+
requestId: string;
|
|
86
|
+
path: string;
|
|
87
|
+
timestamp: string;
|
|
88
|
+
error: {
|
|
89
|
+
code: string; // e.g. "CONFLICT"
|
|
90
|
+
errors: {
|
|
91
|
+
message: string;
|
|
92
|
+
field: string;
|
|
93
|
+
value: string;
|
|
94
|
+
}[];
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ProspayAddChargesSuccessResponse {
|
|
99
|
+
success: true;
|
|
100
|
+
requestId: string;
|
|
101
|
+
path: string;
|
|
102
|
+
timestamp: string;
|
|
103
|
+
data: {
|
|
104
|
+
transactionId: string;
|
|
105
|
+
addedChargesSummary: {
|
|
106
|
+
transactionAmount: number;
|
|
107
|
+
billableAmount: number;
|
|
108
|
+
totalCreditAmount: number;
|
|
109
|
+
totalDebitAmount: number;
|
|
110
|
+
};
|
|
111
|
+
transactionSummary: {
|
|
112
|
+
transactionAmount: number;
|
|
113
|
+
billableAmount: number;
|
|
114
|
+
totalCreditAmount: number;
|
|
115
|
+
totalDebitAmount: number;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface ProspaySearchTransactionsResponse {
|
|
121
|
+
success: true;
|
|
122
|
+
requestId: string;
|
|
123
|
+
path: string;
|
|
124
|
+
timestamp: string;
|
|
125
|
+
data: {
|
|
126
|
+
items: any[]; // structure not provided yet
|
|
127
|
+
pagination: {
|
|
128
|
+
total: number;
|
|
129
|
+
page: number;
|
|
130
|
+
limit: number;
|
|
131
|
+
totalPages: number;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface ProspayChargeSummaryItem {
|
|
137
|
+
chargeHead: string;
|
|
138
|
+
hsnOrSac: string;
|
|
139
|
+
vertical: string;
|
|
140
|
+
taxableAmount: number;
|
|
141
|
+
cgstRate: number;
|
|
142
|
+
cgst: number;
|
|
143
|
+
sgstRate: number;
|
|
144
|
+
sgst: number;
|
|
145
|
+
igstRate: number;
|
|
146
|
+
igst: number;
|
|
147
|
+
totalTaxRate: number;
|
|
148
|
+
totalTax: number;
|
|
149
|
+
netAmount: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ProspayChargeSummaryResponse {
|
|
153
|
+
success: true;
|
|
154
|
+
requestId: string;
|
|
155
|
+
path: string;
|
|
156
|
+
timestamp: string;
|
|
157
|
+
data: ProspayChargeSummaryItem[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@Injectable()
|
|
161
|
+
export class ProspayTransactionService {
|
|
162
|
+
constructor(private readonly http: HttpService) {}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Create a transaction for an order.
|
|
166
|
+
* Maps to:
|
|
167
|
+
* POST /uts/api/transactions
|
|
168
|
+
*/
|
|
169
|
+
async createTransaction(
|
|
170
|
+
authToken: string,
|
|
171
|
+
payload: CreateTransactionDto,
|
|
172
|
+
): Promise<ProspayCreateTransactionSuccessResponse> {
|
|
173
|
+
const response$ = this.http.post(
|
|
174
|
+
'/uts/api/transactions',
|
|
175
|
+
payload,
|
|
176
|
+
{
|
|
177
|
+
headers: {
|
|
178
|
+
Authorization: authToken,
|
|
179
|
+
'Content-Type': 'application/json',
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const response = await lastValueFrom(response$);
|
|
185
|
+
return response.data;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Add charges to an existing transaction by transactionId.
|
|
190
|
+
* Maps to:
|
|
191
|
+
* POST /uts/api/transactions/{transactionId}/charges
|
|
192
|
+
*/
|
|
193
|
+
async addChargesToTransaction(
|
|
194
|
+
authToken: string,
|
|
195
|
+
transactionId: string,
|
|
196
|
+
payload: AddChargesToTransactionDto,
|
|
197
|
+
): Promise<ProspayAddChargesSuccessResponse> {
|
|
198
|
+
const response$ = this.http.post(
|
|
199
|
+
`/uts/api/transactions/${transactionId}/charges`,
|
|
200
|
+
payload,
|
|
201
|
+
{
|
|
202
|
+
headers: {
|
|
203
|
+
Authorization: authToken,
|
|
204
|
+
'Content-Type': 'application/json',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const response = await lastValueFrom(response$);
|
|
210
|
+
return response.data;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Search transactions with filters (customerIds, date range, etc.).
|
|
215
|
+
* Maps to:
|
|
216
|
+
* POST /uts/api/transactions/search
|
|
217
|
+
*/
|
|
218
|
+
async searchTransactions(
|
|
219
|
+
authToken: string,
|
|
220
|
+
payload: SearchTransactionsDto,
|
|
221
|
+
): Promise<ProspaySearchTransactionsResponse> {
|
|
222
|
+
const response$ = this.http.post(
|
|
223
|
+
'/uts/api/transactions/search',
|
|
224
|
+
payload,
|
|
225
|
+
{
|
|
226
|
+
headers: {
|
|
227
|
+
Authorization: authToken,
|
|
228
|
+
'Content-Type': 'application/json',
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const response = await lastValueFrom(response$);
|
|
234
|
+
return response.data;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get charge summary for a date range.
|
|
239
|
+
* Maps to:
|
|
240
|
+
* GET /uts/api/transactions/charge-summary/?startDate=YYYY-MM-DD&endDate=YYYY-MM-DD
|
|
241
|
+
*/
|
|
242
|
+
async getChargeSummary(
|
|
243
|
+
authToken: string,
|
|
244
|
+
params: ChargeSummaryParams,
|
|
245
|
+
): Promise<ProspayChargeSummaryResponse> {
|
|
246
|
+
const response$ = this.http.get(
|
|
247
|
+
'/uts/api/transactions/charge-summary/',
|
|
248
|
+
{
|
|
249
|
+
params,
|
|
250
|
+
headers: {
|
|
251
|
+
Authorization: authToken,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const response = await lastValueFrom(response$);
|
|
257
|
+
return response.data;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "ES2019",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"types": ["node"],
|
|
19
|
+
"lib": ["es2019", "dom"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*"],
|
|
22
|
+
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|