cashfree-pg 5.0.3 → 5.0.8-node

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,567 +0,0 @@
1
- import * as assert from "assert";
2
- import { expect, jest, test } from '@jest/globals';
3
- import { Cashfree, UpiChannelEnum, AppProviderEnum, CardChannelEnum, OfferTncOfferTncTypeEnum, OfferType, DiscountDetailsDiscountTypeEnum } from "../api";
4
- const { execSync } = require('child_process');
5
-
6
- Cashfree.XClientId = process.env.CLIENT_ID;
7
- Cashfree.XClientSecret = process.env.SECRET_KEY;
8
- Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;
9
-
10
-
11
- var orderId = ''
12
- var paymentSessionId = ''
13
- var orderAmount = 3000;
14
- var xApiVersion = '2023-08-01';
15
-
16
- function getCurrentTimeStamp() {
17
- var today = new Date();
18
- var date = today.getFullYear() + (today.getMonth() + 1) + today.getDate();
19
- var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds();
20
- var dateTime = date + '' + time;
21
- return dateTime
22
- }
23
-
24
- function setOrderDetails(order_id: string, payment_session_id: string) {
25
- orderId = order_id
26
- paymentSessionId = payment_session_id
27
- }
28
-
29
- it('Create Order Test', function (done) {
30
- var blah = 'foo';
31
- var request = {
32
- "order_amount": orderAmount,
33
- "order_currency": "INR",
34
- "customer_details": {
35
- "customer_id": "iij",
36
- "customer_name": "abcd",
37
- "customer_email": "success@eligibility.com",
38
- "customer_phone": "9999999999"
39
- },
40
-
41
- "order_note": "Test order",
42
- "order_tags": {
43
- "abc": "def"
44
- }
45
- }
46
-
47
- Cashfree.PGCreateOrder(xApiVersion, request).then((response) => {
48
- assert.equal(response.data.order_amount, request.order_amount, "Amount is not matching")
49
- assert.equal(response.data.order_currency, "INR", "Currency is not matching")
50
- assert.equal(response.data.customer_details?.customer_id, response.data.customer_details?.customer_id, "Customer id is not matching")
51
- assert.equal(response.data.customer_details?.customer_name, response.data.customer_details?.customer_name, "Customer name is not matching")
52
- assert.equal(response.data.customer_details?.customer_email, response.data.customer_details?.customer_email, "Customer email is not matching")
53
- assert.equal(response.data.customer_details?.customer_phone, response.data.customer_details?.customer_phone, "Customer phone is not matching")
54
- setOrderDetails(response.data.order_id, response.data.payment_session_id)
55
- done()
56
- }).catch((error) => {
57
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
58
- assert.fail("Fail error message")
59
- done()
60
- });
61
-
62
- });
63
-
64
-
65
- it('Create Order with Invalid Currency Test', function (done) {
66
- var currency = 'INaR';
67
- var request = {
68
- "order_amount": orderAmount,
69
- "order_currency": currency,
70
- "customer_details": {
71
- "customer_id": "iij",
72
- "customer_name": "abcd",
73
- "customer_email": "success@eligibility.com",
74
- "customer_phone": "9999999999"
75
- },
76
-
77
- "order_note": "Test order",
78
- "order_tags": {
79
- "abc": "def"
80
- }
81
- }
82
-
83
- Cashfree.PGCreateOrder(xApiVersion, request).then((response) => {
84
- assert.fail("Fail error message")
85
- done()
86
- }).catch((error) => {
87
- assert.equal(error.response.data.message, "order_currency : is not valid or not enabled. Value received: " + currency, "Link id is not matching")
88
- assert.equal(error.response.data.code, "order_currency_invalid", "Code is not matching")
89
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
90
- done()
91
- });
92
-
93
- });
94
-
95
- it('Create Order with Invalid Amount Test', function (done) {
96
- var request = {
97
- "order_amount": -3005,
98
- "order_currency": "INR",
99
- "customer_details": {
100
- "customer_id": "iij",
101
- "customer_name": "abcd",
102
- "customer_email": "success@eligibility.com",
103
- "customer_phone": "9999999999"
104
- },
105
-
106
- "order_note": "Test order",
107
- "order_tags": {
108
- "abc": "def"
109
- }
110
- }
111
-
112
- Cashfree.PGCreateOrder(xApiVersion, request).then((response) => {
113
- assert.fail("Fail error message")
114
- done()
115
- }).catch((error) => {
116
- assert.equal(error.response.data.message, "order_amount : Invalid amount entered ", "Link id is not matching")
117
- assert.equal(error.response.data.code, "order_amount_invalid", "Code is not matching")
118
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
119
- done()
120
- });
121
-
122
- });
123
-
124
- it('Create Order with Empty Customer Phone Test', function (done) {
125
- var request = {
126
- "order_amount": orderAmount,
127
- "order_currency": "INR",
128
- "customer_details": {
129
- "customer_id": "iij",
130
- "customer_name": "abcd",
131
- "customer_email": "success@eligibility.com",
132
- "customer_phone": ""
133
- },
134
-
135
- "order_note": "Test order",
136
- "order_tags": {
137
- "abc": "def"
138
- }
139
- }
140
-
141
- Cashfree.PGCreateOrder(xApiVersion, request).then((response) => {
142
- assert.fail("Fail error message")
143
- done()
144
- }).catch((error) => {
145
- assert.equal(error.response.data.message, "customer_details.customer_phone : is missing in the request. Value received: ", "Customer phone is not matching")
146
- assert.equal(error.response.data.code, "customer_details.customer_phone_missing", "Code is not matching")
147
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
148
- done()
149
- });
150
-
151
- });
152
-
153
- it('Order Pay Net Banking Test', function (done) {
154
- var request = {
155
- "payment_session_id": paymentSessionId,
156
- "payment_method": {
157
- "netbanking": {
158
- "netbanking_bank_code": 3087,
159
- "channel": "link"
160
- }
161
- }
162
- }
163
- Cashfree.PGPayOrder(xApiVersion, request).then((response) => {
164
- assert.equal(response.data.channel, "link", "channel is not matching")
165
- assert.equal(response.data.payment_method, "netbanking", "payment_method is not matching")
166
- assert.strictEqual(Number(response.data.payment_amount) >= orderAmount, true, "Payment amount is less than order amount")
167
- done()
168
- }).catch((error) => {
169
- assert.fail("Fail error message")
170
- done()
171
- });
172
- });
173
-
174
- it('Order Pay Card payment Test', function (done) {
175
- var request = {
176
- "payment_session_id": paymentSessionId,
177
- "payment_method": {
178
- "card": {
179
- "channel": CardChannelEnum.LINK,
180
- "card_number": "4838305610460100",
181
- "card_holder_name": "Tushar Gupta",
182
- "card_expiry_mm": "06",
183
- "card_expiry_yy": "25",
184
- "card_cvv": "123"
185
- }
186
- }
187
- }
188
- Cashfree.PGPayOrder(xApiVersion, request).then((response) => {
189
- assert.equal(response.data.channel, "link", "channel is not matching")
190
- assert.equal(response.data.payment_method, "card", "payment_method is not matching")
191
- assert.strictEqual(Number(response.data.payment_amount) >= orderAmount, true, "Payment amount is less than order amount")
192
- done()
193
- }).catch((error) => {
194
- assert.fail("Fail error message")
195
- done()
196
- });
197
- });
198
-
199
- it('Order Pay Card payment with empty cvv Test', function (done) {
200
- var request = {
201
- "payment_session_id": paymentSessionId,
202
- "payment_method": {
203
- "card": {
204
- "channel": CardChannelEnum.LINK,
205
- "card_number": "4838305610460100",
206
- "card_holder_name": "Tushar Gupta",
207
- "card_expiry_mm": "06",
208
- "card_expiry_yy": "25",
209
- "card_cvv": ""
210
- }
211
- }
212
- }
213
- Cashfree.PGPayOrder(xApiVersion, request).then((response) => {
214
- assert.fail("Fail error message")
215
- done()
216
- }).catch((error) => {
217
- assert.equal(error.response.data.message, "card_cvv : is missing in the request. Value received: ", "Message is not matching")
218
- assert.equal(error.response.data.code, "card_cvv_missing", "Code is not matching")
219
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
220
- done()
221
- });
222
- });
223
-
224
- it('Order Pay Wallet Test', function (done) {
225
- Cashfree.XClientId = process.env.CLIENT_ID;
226
- Cashfree.XClientSecret = process.env.SECRET_KEY;
227
- Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;
228
- var request = {
229
- "payment_session_id": paymentSessionId,
230
- "payment_method": {
231
- "app": {
232
- "provider": AppProviderEnum.PHONEPE,
233
- "phone": "8474090512",
234
- "channel": "link"
235
- }
236
- }
237
- }
238
- Cashfree.PGPayOrder(xApiVersion, request).then((response) => {
239
- done()
240
- }).catch((error) => {
241
- assert.fail("Fail error message")
242
- done()
243
- });
244
- });
245
-
246
- it('Get Order Test', function (done) {
247
- Cashfree.PGFetchOrder(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => {
248
- assert.equal(response.data.order_currency, "INR")
249
- done()
250
- }).catch((error) => {
251
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
252
- assert.fail("Fail error message")
253
- done()
254
- });
255
- });
256
-
257
- it('Get Payments For an Order Test', function (done) {
258
- Cashfree.PGOrderFetchPayments(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => {
259
- done()
260
- }).catch((error) => {
261
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
262
- assert.fail("Fail error message")
263
- done()
264
- });
265
-
266
- });
267
-
268
- it('Create Refund Test', function (done) {
269
- var request = {
270
- "refund_amount": 1,
271
- "refund_id": "Refund_id_" + getCurrentTimeStamp(),
272
- "refund_note": "initiated refund by automation"
273
- }
274
- Cashfree.PGOrderCreateRefund(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", request).then((response) => {
275
- done()
276
- }).catch((error) => {
277
- console.log(error.response.data)
278
- assert.fail("Fail error message")
279
- done()
280
- });
281
- });
282
-
283
- it('Create Refund with negative refund amount Test', function (done) {
284
- var request = {
285
- "refund_amount": -1,
286
- "refund_id": "Refund_id_" + getCurrentTimeStamp(),
287
- "refund_note": "initiated refund by automation"
288
- }
289
-
290
- Cashfree.PGOrderCreateRefund(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", request).then((response) => {
291
- assert.fail("Fail error message")
292
- done()
293
- }).catch((error) => {
294
- assert.equal(error.response.data.message, "refund_amount : Invalid amount entered ", "Link id is not matching")
295
- assert.equal(error.response.data.code, "refund_amount_invalid", "Code is not matching")
296
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
297
- done()
298
- });
299
- });
300
-
301
- it('Create Refund with invalid order id Test', function (done) {
302
- var request = {
303
- "refund_amount": 1,
304
- "refund_id": "Refund_id_" + getCurrentTimeStamp(),
305
- "refund_note": "initiated refund by automation"
306
- }
307
- var order_id = "Order_" + getCurrentTimeStamp()
308
- Cashfree.PGOrderCreateRefund(xApiVersion, order_id, request).then((response) => {
309
- assert.fail("Fail error message")
310
- done()
311
- }).catch((error) => {
312
- assert.equal(error.response.data.message, "Order Reference Id does not exist", "Link id is not matching")
313
- assert.equal(error.response.data.code, "order_not_found", "Code is not matching")
314
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
315
- done()
316
- });
317
- });
318
-
319
- it('Fetch All Refunds Test', function (done) {
320
- var order_id = "Order_" + getCurrentTimeStamp()
321
- Cashfree.PGOrderFetchRefunds(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => {
322
- done()
323
- }).catch((error) => {
324
- console.log(error.response.data)
325
- assert.fail("Fail error message")
326
- done()
327
- });
328
- });
329
-
330
- it('Fetch Refund Test', function (done) {
331
- var order_id = "Order_" + getCurrentTimeStamp()
332
- Cashfree.PGOrderFetchRefund(xApiVersion, "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", "Refund_id_2060112241827").then((response) => {
333
- done()
334
- }).catch((error) => {
335
- console.log(error.response.data)
336
- assert.fail("Fail error message")
337
- done()
338
- });
339
- });
340
-
341
- it('Create Payment Link Test', function (done) {
342
- var link_id = "Automated_Test_" + getCurrentTimeStamp()
343
- var request = {
344
- "link_amount": 1,
345
- "link_id": link_id,
346
- "link_currency": "INR",
347
- "customer_details": {
348
- "customer_name": "John Doe",
349
- "customer_phone": "9292229292",
350
- "customer_email": "john@cashfree.com"
351
-
352
- },
353
- "link_purpose": "qui",
354
- "link_partial_payments": false,
355
- "link_minimum_partial_amount": 77634560.22892892,
356
- "link_notify": {
357
- "send_sms": false,
358
- "send_email": true
359
- },
360
- "link_auto_reminders": false,
361
- "link_notes": {
362
- "key_1": "value_1",
363
- "key_2": "value_2"
364
- },
365
- "link_meta": {
366
- "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net",
367
- "upi_intent": false
368
- }
369
- }
370
- Cashfree.PGCreateLink(xApiVersion, request).then((response) => {
371
- done()
372
- }).catch((error) => {
373
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
374
- assert.fail("Fail error message")
375
- done()
376
- });
377
- });
378
-
379
-
380
- it('Fetch Payment Link Test', function (done) {
381
- var link_id = "Automated_Test_188181"
382
- Cashfree.PGFetchLink(xApiVersion, link_id).then((response) => {
383
- done()
384
- }).catch((error) => {
385
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
386
- assert.fail("Fail error message")
387
- done()
388
- });
389
- });
390
-
391
- it('Cancel Payment Link Test', function (done) {
392
- var link_id = "Automated_Test_188181"
393
- Cashfree.PGCancelLink(xApiVersion, link_id).then((response) => {
394
- assert.fail("Fail error message")
395
- done()
396
- }).catch((error) => {
397
- assert.equal(error.response.data.message, "Only link in ACTIVE state can be cancelled", "Link id is not matching")
398
- assert.equal(error.response.data.code, "link_not_active", "Code is not matching")
399
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
400
- done()
401
- });
402
- });
403
-
404
- it('Fetch Payment Link with Invalid link id Test', function (done) {
405
- var link_id = "jahha" + getCurrentTimeStamp()
406
- Cashfree.PGFetchLink(xApiVersion, link_id).then((response) => {
407
- assert.fail("Fail error message")
408
- done()
409
- }).catch((error) => {
410
- assert.equal(error.response.data.message, "No request found with link Id " + link_id, "Link id is not matching")
411
- assert.equal(error.response.data.code, "link_not_found", "Code is not matching")
412
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
413
- done()
414
- });
415
- });
416
-
417
- it('Fetch Link Orders Test', function (done) {
418
- var link_id = "Automated_Test_188181"
419
- Cashfree.PGLinkFetchOrders(xApiVersion, link_id).then((response) => {
420
- done()
421
- }).catch((error) => {
422
- console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator)
423
- assert.fail("Fail error message")
424
- done()
425
- });
426
- });
427
-
428
- it('Fetch Link Orders with invalid link id Test', function (done) {
429
- var link_id = "jajqq"
430
- Cashfree.PGLinkFetchOrders(xApiVersion, link_id).then((response) => {
431
- assert.fail("Fail error message")
432
- done()
433
- }).catch((error) => {
434
- assert.equal(error.response.data.message, "No request found with link ID " + link_id, "Link id is not matching")
435
- assert.equal(error.response.data.code, "link_not_found", "Code is not matching")
436
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
437
- done()
438
- });
439
- });
440
-
441
-
442
- // it('Create Offer Test', function (done) {
443
- // var request = {
444
- // "offer_meta": {
445
- // "offer_title": "bat mann",
446
- // "offer_description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
447
- // "offer_code": "VISA1122",
448
- // "offer_start_time": "2024-01-01T08:09:51Z",
449
- // "offer_end_time": "2024-09-14T06:18:50Z"
450
- // },
451
- // "offer_tnc": {
452
- // "offer_tnc_type": OfferTncOfferTncTypeEnum.TEXT,
453
- // "offer_tnc_value": "Lorem ipsum dolor sit amet"
454
- // },
455
- // "offer_details": {
456
- // "offer_type": OfferType.DISCOUNT,
457
- // "discount_details": {
458
- // "discount_type": DiscountDetailsDiscountTypeEnum.PERCENTAGE,
459
- // "discount_value": "20.00",
460
- // "max_discount_amount": "150.00"
461
- // }
462
- // },
463
- // "offer_validations": {
464
- // "min_amount": 223.0,
465
- // "max_allowed": 122,
466
- // "payment_method": {
467
- // "all": {
468
-
469
- // }
470
- // }
471
- // }
472
- // }
473
- // Cashfree.PGCreateOffer(xApiVersion, request).then((response) => {
474
- // assert.fail("Fail error message")
475
- // done()
476
- // }).catch((error) => {
477
- // console.log(error.response)
478
- // done()
479
- // });
480
- // });
481
-
482
- // it('Get Offer Test', function (done) {
483
- // Cashfree.PGFetchOffer(xApiVersion, "a189050b-8f7e-4f1c-be5f-ba4bf58bdd6b").then((response) => {
484
- // done()
485
- // }).catch((error) => {
486
- // assert.fail("Fail error message")
487
- // done()
488
- // });
489
- // });
490
-
491
- it('Fetch Eligibility Payment Methods Test', function (done) {
492
- var request = {
493
- "queries": {
494
- "amount": 100
495
- }
496
- }
497
- Cashfree.PGEligibilityFetchPaymentMethods(xApiVersion, request).then((response) => {
498
- done()
499
- }).catch((error) => {
500
- assert.fail("Fail error message")
501
- done()
502
- });
503
- });
504
-
505
- it('Fetch Eligibility Payment Methods using Order Id Test', function (done) {
506
- var request = {
507
- "queries": {
508
- "order_id": "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI"
509
- }
510
- }
511
- Cashfree.PGEligibilityFetchPaymentMethods(xApiVersion, request).then((response) => {
512
- done()
513
- }).catch((error) => {
514
- assert.fail("Fail error message")
515
- done()
516
- });
517
- });
518
-
519
- it('Fetch Eligibility Payment Methods With invalid amount Test', function (done) {
520
- var request = {
521
- "queries": {
522
- "amount": -100
523
- }
524
- }
525
- Cashfree.PGEligibilityFetchPaymentMethods(xApiVersion, request).then((response) => {
526
- assert.fail("Fail error message")
527
- done()
528
- }).catch((error) => {
529
- assert.equal(error.response.data.message, "queries.amount : should be greater than 0", "Link id is not matching")
530
- assert.equal(error.response.data.code, "queries.amount_invalid", "Code is not matching")
531
- assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching")
532
- done()
533
- });
534
- });
535
-
536
- it('Settlement Reconcilation Test', function (done) {
537
- var request = {
538
- "pagination": {
539
- "limit": 10
540
- },
541
- "filters": {
542
- "start_date": "2023-03-01T00:00:00Z",
543
- "end_date": "2023-03-21T23:59:59Z"
544
- }
545
- }
546
- Cashfree.PGSettlementFetchRecon(xApiVersion, request).then((response) => {
547
- done()
548
- }).catch((error) => {
549
- assert.fail("Fail error message")
550
- done()
551
- });
552
- });
553
-
554
- it('Get Instrument By Id Test', function (done) {
555
- var instrumemtId = "9f9477b7-61ea-4baa-b878-a7e63d978034"
556
- var customerId = "iij"
557
- Cashfree.PGCustomerFetchInstrument(xApiVersion, customerId, instrumemtId).then((response) => {
558
- assert.equal(response.data.instrument_id, instrumemtId, "instrument_id is not matching")
559
- assert.equal(response.data.customer_id, customerId, "instrument_id is not matching")
560
- done()
561
- }).catch((error) => {
562
- console.log(error.response)
563
- assert.fail("Fail error message")
564
- done()
565
- });
566
- });
567
-