@cashfreepayments/agent-skills 0.0.1

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.
Files changed (44) hide show
  1. package/README.md +214 -0
  2. package/bin/cashfree.js +2 -0
  3. package/dist/config.d.ts +50 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +24 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/generators/index.d.ts +2 -0
  8. package/dist/generators/index.d.ts.map +1 -0
  9. package/dist/generators/index.js +2 -0
  10. package/dist/generators/index.js.map +1 -0
  11. package/dist/generators/utils.d.ts +14 -0
  12. package/dist/generators/utils.d.ts.map +1 -0
  13. package/dist/generators/utils.js +34 -0
  14. package/dist/generators/utils.js.map +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +156 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/templates/crossBorder.d.ts +5 -0
  20. package/dist/templates/crossBorder.d.ts.map +1 -0
  21. package/dist/templates/crossBorder.js +10 -0
  22. package/dist/templates/crossBorder.js.map +1 -0
  23. package/dist/templates/crossBorder.md +264 -0
  24. package/dist/templates/payouts.d.ts +5 -0
  25. package/dist/templates/payouts.d.ts.map +1 -0
  26. package/dist/templates/payouts.js +10 -0
  27. package/dist/templates/payouts.js.map +1 -0
  28. package/dist/templates/payouts.md +332 -0
  29. package/dist/templates/pg.d.ts +5 -0
  30. package/dist/templates/pg.d.ts.map +1 -0
  31. package/dist/templates/pg.js +10 -0
  32. package/dist/templates/pg.js.map +1 -0
  33. package/dist/templates/pg.md +501 -0
  34. package/dist/templates/secure-id.d.ts +5 -0
  35. package/dist/templates/secure-id.d.ts.map +1 -0
  36. package/dist/templates/secure-id.js +10 -0
  37. package/dist/templates/secure-id.js.map +1 -0
  38. package/dist/templates/secure-id.md +215 -0
  39. package/dist/templates/subscriptions.d.ts +5 -0
  40. package/dist/templates/subscriptions.d.ts.map +1 -0
  41. package/dist/templates/subscriptions.js +10 -0
  42. package/dist/templates/subscriptions.js.map +1 -0
  43. package/dist/templates/subscriptions.md +193 -0
  44. package/package.json +49 -0
@@ -0,0 +1,501 @@
1
+ ---
2
+ name: Cashfree Payment Gateway
3
+ description: Use this to see payment gateway documentation and API references
4
+ ---
5
+
6
+ # Cashfree Payment Gateway Integration Skills
7
+
8
+ ## Project Overview
9
+
10
+ This project integrates Cashfree Payment Gateway for accepting payments. The integration follows a 3-step flow:
11
+
12
+ 1. Create Order (backend) → 2. Open Checkout (frontend) → 3. Confirm Payment via Webhooks
13
+
14
+ ---
15
+
16
+ ## API Configuration
17
+
18
+ ### Environments
19
+
20
+ | Environment | Base URL |
21
+ | ----------- | --------------------------------- |
22
+ | Sandbox | `https://sandbox.cashfree.com/pg` |
23
+ | Production | `https://api.cashfree.com/pg` |
24
+
25
+ ### Required Headers
26
+
27
+ ```
28
+ x-client-id: <Your App ID>
29
+ x-client-secret: <Your Secret Key>
30
+ x-api-version: 2025-01-01
31
+ Content-Type: application/json
32
+ ```
33
+
34
+ ### Authentication
35
+
36
+ - Credentials are obtained from Merchant Dashboard
37
+ - Never expose `x-client-secret` in frontend code
38
+ - Whitelist your domain in Merchant Dashboard before going live
39
+
40
+ ---
41
+
42
+ ## Backend Integration
43
+
44
+ ### Create Order API
45
+
46
+ **Endpoint:** `POST /orders`
47
+
48
+ Creates a payment order and returns `payment_session_id` for frontend checkout.
49
+
50
+ #### Request Body
51
+
52
+ ```json
53
+ {
54
+ "order_id": "unique_order_id",
55
+ "order_amount": 100.0,
56
+ "order_currency": "INR",
57
+ "customer_details": {
58
+ "customer_id": "customer_123",
59
+ "customer_phone": "9999999999",
60
+ "customer_email": "customer@example.com",
61
+ "customer_name": "John Doe"
62
+ },
63
+ "order_meta": {
64
+ "return_url": "https://yoursite.com/return/{order_id}",
65
+ "notify_url": "https://yoursite.com/webhook"
66
+ },
67
+ "order_note": "Optional order note",
68
+ "order_tags": {
69
+ "key": "value"
70
+ }
71
+ }
72
+ ```
73
+
74
+ #### Response
75
+
76
+ ```json
77
+ {
78
+ "cf_order_id": 2149460581,
79
+ "order_id": "order_123",
80
+ "order_status": "ACTIVE",
81
+ "payment_session_id": "session_xxx...",
82
+ "order_expiry_time": "2023-09-09T18:02:46+05:30",
83
+ "payments": {
84
+ "url": "https://sandbox.cashfree.com/pg/orders/order_123/payments"
85
+ }
86
+ }
87
+ ```
88
+
89
+ #### Backend SDK Examples
90
+
91
+ **Node.js:**
92
+
93
+ ```javascript
94
+ const { Cashfree } = require("cashfree-pg");
95
+
96
+ Cashfree.XClientId = process.env.CASHFREE_APP_ID;
97
+ Cashfree.XClientSecret = process.env.CASHFREE_SECRET_KEY;
98
+ Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;
99
+
100
+ const request = {
101
+ order_amount: 100.0,
102
+ order_currency: "INR",
103
+ customer_details: {
104
+ customer_id: "customer_123",
105
+ customer_phone: "9999999999",
106
+ },
107
+ };
108
+
109
+ const response = await Cashfree.PGCreateOrder("2025-01-01", request);
110
+ ```
111
+
112
+ **Python:**
113
+
114
+ ```python
115
+ from cashfree_pg.api_client import Cashfree
116
+
117
+ Cashfree.XClientId = "<app_id>"
118
+ Cashfree.XClientSecret = "<secret_key>"
119
+ Cashfree.XEnvironment = Cashfree.SANDBOX
120
+
121
+ request = CreateOrderRequest(
122
+ order_amount=100.00,
123
+ order_currency="INR",
124
+ customer_details=CustomerDetails(
125
+ customer_id="customer_123",
126
+ customer_phone="9999999999"
127
+ )
128
+ )
129
+ response = Cashfree.PGCreateOrder("2025-01-01", request)
130
+ ```
131
+
132
+ **Java:**
133
+
134
+ ```java
135
+ Cashfree.XClientId = "<app_id>";
136
+ Cashfree.XClientSecret = "<secret_key>";
137
+ Cashfree.XEnvironment = Cashfree.SANDBOX;
138
+
139
+ CustomerDetails customerDetails = new CustomerDetails();
140
+ customerDetails.setCustomerId("customer_123");
141
+ customerDetails.setCustomerPhone("9999999999");
142
+
143
+ CreateOrderRequest request = new CreateOrderRequest();
144
+ request.setOrderAmount(100.00);
145
+ request.setOrderCurrency("INR");
146
+ request.setCustomerDetails(customerDetails);
147
+
148
+ Cashfree cashfree = new Cashfree();
149
+ OrderEntity response = cashfree.PGCreateOrder("2025-01-01", request, null, null, null);
150
+ ```
151
+
152
+ **Go:**
153
+
154
+ ```go
155
+ import cashfree "github.com/cashfree/cashfree-pg/v4"
156
+
157
+ clientId := "<app_id>"
158
+ clientSecret := "<secret_key>"
159
+ cashfree.XClientId = &clientId
160
+ cashfree.XClientSecret = &clientSecret
161
+ cashfree.XEnvironment = cashfree.SANDBOX
162
+
163
+ request := cashfree.CreateOrderRequest{
164
+ OrderAmount: 100.00,
165
+ OrderCurrency: "INR",
166
+ CustomerDetails: cashfree.CustomerDetails{
167
+ CustomerId: "customer_123",
168
+ CustomerPhone: "9999999999",
169
+ },
170
+ }
171
+ response, _, err := cashfree.PGCreateOrder(&xApiVersion, &request, nil, nil, nil)
172
+ ```
173
+
174
+ ### Get Order Status API
175
+
176
+ **Endpoint:** `GET /orders/{order_id}`
177
+
178
+ Always verify payment status from backend before fulfilling orders.
179
+
180
+ ```javascript
181
+ const response = await Cashfree.PGFetchOrder("2025-01-01", orderId);
182
+ // Check response.order_status: "PAID", "ACTIVE", "EXPIRED"
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Frontend Integration
188
+
189
+ ### 1. Include JavaScript SDK
190
+
191
+ ```html
192
+ <script src="https://sdk.cashfree.com/js/v3/cashfree.js"></script>
193
+ ```
194
+
195
+ ### 2. Initialize and Open Checkout
196
+
197
+ ```javascript
198
+ // Initialize Cashfree
199
+ const cashfree = Cashfree({
200
+ mode: "sandbox", // or "production"
201
+ });
202
+
203
+ // Open checkout (modal or redirect)
204
+ cashfree.checkout({
205
+ paymentSessionId: "session_id_from_backend",
206
+ redirectTarget: "_modal", // "_modal" for popup, "_self" for redirect
207
+ });
208
+ ```
209
+
210
+ ### 3. Handle Payment Response
211
+
212
+ ```javascript
213
+ cashfree.checkout({
214
+ paymentSessionId: sessionId,
215
+ redirectTarget: "_modal",
216
+ onSuccess: function (data) {
217
+ console.log("Payment successful", data);
218
+ // Verify payment on backend
219
+ },
220
+ onFailure: function (data) {
221
+ console.log("Payment failed", data);
222
+ },
223
+ onClose: function () {
224
+ console.log("Checkout closed");
225
+ },
226
+ });
227
+ ```
228
+
229
+ ### Mobile SDK Integration
230
+
231
+ **Android (Gradle):**
232
+
233
+ ```groovy
234
+ implementation 'com.cashfree.pg:api:2.2.8'
235
+ ```
236
+
237
+ **iOS (CocoaPods):**
238
+
239
+ ```ruby
240
+ pod 'CashfreePG', '2.2.4'
241
+ ```
242
+
243
+ **Flutter:**
244
+
245
+ ```yaml
246
+ dependencies:
247
+ flutter_cashfree_pg_sdk: ^2.2.9
248
+ ```
249
+
250
+ **React Native:**
251
+
252
+ ```bash
253
+ npm install react-native-cashfree-pg-sdk
254
+ ```
255
+
256
+ ---
257
+
258
+ ## Webhook Integration
259
+
260
+ ### Configure Webhooks
261
+
262
+ 1. Go to **Payment Gateway Dashboard** > **Developers** > **Webhooks**
263
+ 2. Click **Add Webhook URL**
264
+ 3. Enter your webhook endpoint URL
265
+ 4. Select events to subscribe
266
+
267
+ ### Webhook Events
268
+
269
+ | Event | Description |
270
+ | ------------------------------ | ------------------------------- |
271
+ | `PAYMENT_SUCCESS_WEBHOOK` | Payment completed successfully |
272
+ | `PAYMENT_FAILED_WEBHOOK` | Payment failed |
273
+ | `PAYMENT_USER_DROPPED_WEBHOOK` | User dropped off during payment |
274
+ | `REFUND_STATUS_WEBHOOK` | Refund status update |
275
+ | `SETTLEMENT_WEBHOOK` | Settlement processed |
276
+
277
+ ### Webhook Payload Structure
278
+
279
+ ```json
280
+ {
281
+ "data": {
282
+ "order": {
283
+ "order_id": "order_123",
284
+ "order_amount": 100.0,
285
+ "order_currency": "INR",
286
+ "order_tags": null
287
+ },
288
+ "payment": {
289
+ "cf_payment_id": 1234567890,
290
+ "payment_status": "SUCCESS",
291
+ "payment_amount": 100.0,
292
+ "payment_currency": "INR",
293
+ "payment_message": "Transaction successful",
294
+ "payment_time": "2023-08-11T18:02:46+05:30",
295
+ "bank_reference": "123456789",
296
+ "payment_method": {
297
+ "upi": {
298
+ "upi_id": "user@upi"
299
+ }
300
+ }
301
+ },
302
+ "customer_details": {
303
+ "customer_id": "customer_123",
304
+ "customer_name": "John Doe",
305
+ "customer_email": "john@example.com",
306
+ "customer_phone": "9999999999"
307
+ }
308
+ },
309
+ "event_time": "2023-08-11T18:02:46+05:30",
310
+ "type": "PAYMENT_SUCCESS_WEBHOOK"
311
+ }
312
+ ```
313
+
314
+ ### Webhook Headers
315
+
316
+ | Header | Description |
317
+ | --------------------- | -------------------------------------- |
318
+ | `x-webhook-signature` | HMAC-SHA256 signature for verification |
319
+ | `x-webhook-timestamp` | Timestamp when webhook was sent |
320
+ | `x-webhook-version` | API version used |
321
+
322
+ ### Signature Verification (REQUIRED)
323
+
324
+ **IMPORTANT:** Always verify webhook signatures before processing. Never process webhooks without verification.
325
+
326
+ **Verification Process:**
327
+
328
+ 1. Extract `x-webhook-timestamp` from headers
329
+ 2. Concatenate: `timestamp + rawBody`
330
+ 3. Generate HMAC-SHA256 hash using your secret key
331
+ 4. Base64-encode the hash
332
+ 5. Compare with `x-webhook-signature` header
333
+
334
+ **Node.js (Express):**
335
+
336
+ ```javascript
337
+ const crypto = require("crypto");
338
+
339
+ function verifyWebhookSignature(req) {
340
+ const timestamp = req.headers["x-webhook-timestamp"];
341
+ const signature = req.headers["x-webhook-signature"];
342
+ const rawBody = req.rawBody; // Must use raw body, not parsed JSON
343
+
344
+ const signatureString = timestamp + rawBody;
345
+ const computedSignature = crypto
346
+ .createHmac("sha256", process.env.CASHFREE_SECRET_KEY)
347
+ .update(signatureString)
348
+ .digest("base64");
349
+
350
+ return computedSignature === signature;
351
+ }
352
+
353
+ // Using SDK
354
+ const { Cashfree } = require("cashfree-pg");
355
+ try {
356
+ Cashfree.PGVerifyWebhookSignature(
357
+ req.headers["x-webhook-signature"],
358
+ req.rawBody,
359
+ req.headers["x-webhook-timestamp"],
360
+ );
361
+ } catch (err) {
362
+ console.log("Invalid signature:", err.message);
363
+ }
364
+ ```
365
+
366
+ **Python (Flask):**
367
+
368
+ ```python
369
+ import base64
370
+ import hashlib
371
+ import hmac
372
+
373
+ def verify_webhook_signature(request):
374
+ raw_body = request.data.decode('utf-8')
375
+ timestamp = request.headers['x-webhook-timestamp']
376
+ signature = request.headers['x-webhook-signature']
377
+
378
+ signature_data = timestamp + raw_body
379
+ message = bytes(signature_data, 'utf-8')
380
+ secret_key = bytes(os.environ['CASHFREE_SECRET_KEY'], 'utf-8')
381
+
382
+ computed_signature = base64.b64encode(
383
+ hmac.new(secret_key, message, digestmod=hashlib.sha256).digest()
384
+ ).decode('utf-8')
385
+
386
+ return computed_signature == signature
387
+ ```
388
+
389
+ **Go:**
390
+
391
+ ```go
392
+ import (
393
+ "crypto/hmac"
394
+ "crypto/sha256"
395
+ "encoding/base64"
396
+ )
397
+
398
+ func VerifySignature(signature, timestamp, rawBody, secretKey string) bool {
399
+ signatureString := timestamp + rawBody
400
+ h := hmac.New(sha256.New, []byte(secretKey))
401
+ h.Write([]byte(signatureString))
402
+ computedSignature := base64.StdEncoding.EncodeToString(h.Sum(nil))
403
+ return computedSignature == signature
404
+ }
405
+ ```
406
+
407
+ **PHP:**
408
+
409
+ ```php
410
+ function verifyWebhookSignature() {
411
+ $rawBody = file_get_contents('php://input');
412
+ $timestamp = getallheaders()['x-webhook-timestamp'];
413
+ $signature = getallheaders()['x-webhook-signature'];
414
+
415
+ $signatureString = $timestamp . $rawBody;
416
+ $computedSignature = base64_encode(
417
+ hash_hmac('sha256', $signatureString, $_ENV['CASHFREE_SECRET_KEY'], true)
418
+ );
419
+
420
+ return $computedSignature === $signature;
421
+ }
422
+ ```
423
+
424
+ **Java:**
425
+
426
+ ```java
427
+ import javax.crypto.Mac;
428
+ import javax.crypto.spec.SecretKeySpec;
429
+ import java.util.Base64;
430
+
431
+ public String generateSignature(String timestamp, String rawBody, String secretKey) throws Exception {
432
+ String data = timestamp + rawBody;
433
+ Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
434
+ SecretKeySpec secret_key_spec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
435
+ sha256_HMAC.init(secret_key_spec);
436
+ return Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(data.getBytes()));
437
+ }
438
+ ```
439
+
440
+ ### Webhook Response Requirements
441
+
442
+ - Return HTTP 200 to acknowledge receipt
443
+ - Cashfree retries on non-200 responses
444
+ - Implement idempotency to handle duplicate deliveries
445
+
446
+ ### IPs to Whitelist
447
+
448
+ **Sandbox:**
449
+
450
+ - 52.66.25.127
451
+ - 15.206.45.168
452
+
453
+ **Production:**
454
+
455
+ - 52.66.101.190
456
+ - 3.109.102.144
457
+ - 18.60.134.245
458
+ - 18.60.183.142
459
+
460
+ **Port:** 443 (HTTPS only)
461
+
462
+ ---
463
+
464
+ ## Payment Status Values
465
+
466
+ | Status | Description |
467
+ | --------------- | ------------------------------ |
468
+ | `SUCCESS` | Payment completed successfully |
469
+ | `FAILED` | Payment failed |
470
+ | `PENDING` | Payment awaiting confirmation |
471
+ | `NOT_ATTEMPTED` | No payment attempt made |
472
+ | `USER_DROPPED` | User abandoned payment |
473
+
474
+ ---
475
+
476
+ ## Security Checklist
477
+
478
+ - [ ] Never expose secret key in frontend code
479
+ - [ ] Always verify webhook signatures before processing
480
+ - [ ] Whitelist your domain in Merchant Dashboard
481
+ - [ ] Use HTTPS endpoints for webhooks
482
+ - [ ] Whitelist Cashfree IPs for webhook endpoints
483
+ - [ ] Always verify payment status from backend before fulfilling orders
484
+ - [ ] Use raw request body for signature verification (not parsed JSON)
485
+ - [ ] Implement idempotency for webhook handlers
486
+
487
+ ---
488
+
489
+ ## Testing
490
+
491
+ - Use sandbox environment for development
492
+ - Test cards and UPI IDs available in Cashfree documentation
493
+ - Verify webhook delivery in Dashboard > Developers > Webhooks
494
+
495
+ ---
496
+
497
+ ## Useful Links
498
+
499
+ - [Cashfree Dev Studio](https://www.cashfree.com/devstudio)
500
+ - [GitHub SDKs](https://github.com/cashfree/)
501
+ - [Postman Collections](/api-reference/postman-collections)
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Secure ID System skill template
3
+ */
4
+ export declare function getSecureIdSkillTemplate(): string;
5
+ //# sourceMappingURL=secure-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-id.d.ts","sourceRoot":"","sources":["../../src/templates/secure-id.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAGjD"}
@@ -0,0 +1,10 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ /**
4
+ * Secure ID System skill template
5
+ */
6
+ export function getSecureIdSkillTemplate() {
7
+ const templatePath = path.join(__dirname, "secure-id.md");
8
+ return fs.readFileSync(templatePath, "utf8");
9
+ }
10
+ //# sourceMappingURL=secure-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-id.js","sourceRoot":"","sources":["../../src/templates/secure-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B;;GAEG;AACH,MAAM,UAAU,wBAAwB;IACpC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAC1D,OAAO,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC"}