Skip to content

Commit ff55978

Browse files
authored
feat: fetch all orders (#10)
* feat: fetch all orders chore: Makefile added * chore: made document more clear * chore: review fixes
1 parent 8bbac28 commit ff55978

File tree

10 files changed

+676
-73
lines changed

10 files changed

+676
-73
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/bin
33
/.go
44
/logs
5-
/vendor
5+
/vendor
6+
razorpay-mcp-server

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ Thank you for your interest in contributing to the Razorpay MCP Server! This doc
66

77
Please be respectful and considerate of others when contributing to this project. We strive to maintain a welcoming and inclusive environment for all contributors.
88

9+
## TLDR;
10+
11+
```
12+
make test
13+
make fmt
14+
make lint
15+
make build
16+
make run
17+
```
18+
19+
We use Cursor to contribute - our AI developer. Look at `~/.cusor/rules`. It understands the standards we have defined and codes with that.
20+
921
## Development Process
1022

1123
We use a fork-based workflow for all contributions:
@@ -95,6 +107,8 @@ We use a fork-based workflow for all contributions:
95107

96108
### Running the Server Locally
97109

110+
There are `make` commands also available now for the below, refer TLDR; above.
111+
98112
To run the server in development mode:
99113

100114
```bash

Makefile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Build variables
2+
VERSION ?= $(shell git describe --tags --always --dirty --match="v*" 2> /dev/null || echo "dev")
3+
BUILD_DATE = $(shell date -u '+%Y-%m-%d')
4+
COMMIT = $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
5+
LDFLAGS = -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
6+
7+
# Go variables
8+
GO = go
9+
GOBIN = $(shell $(GO) env GOPATH)/bin
10+
11+
# Docker variables
12+
IMAGE = razorpay-mcp-server
13+
TAG ?= latest
14+
15+
# Default target
16+
all: verify fmt test lint build
17+
18+
# Build docker image
19+
build:
20+
docker build -t $(IMAGE):$(TAG) .
21+
22+
# Run docker container
23+
run:
24+
docker run -it --rm \
25+
-e RAZORPAY_KEY_ID=your_key_id \
26+
-e RAZORPAY_KEY_SECRET=your_key_secret \
27+
$(IMAGE):$(TAG)
28+
29+
# Run the application
30+
local-run:
31+
$(GO) run ./cmd/razorpay-mcp-server
32+
33+
local-build:
34+
$(GO) build -v ./cmd/razorpay-mcp-server
35+
36+
# Verify dependencies
37+
verify:
38+
$(GO) mod verify
39+
$(GO) mod download
40+
41+
# Format code
42+
fmt:
43+
$(GO) fmt ./...
44+
$(GO) mod tidy
45+
46+
# Run tests
47+
test:
48+
$(GO) test -race ./...
49+
50+
# Run tests with coverage
51+
test-coverage:
52+
$(GO) test -race -coverprofile=coverage.out -covermode=atomic ./pkg/...
53+
$(GO) tool cover -html=coverage.out -o coverage.html
54+
55+
# Install golangci-lint
56+
install-lint:
57+
@LINT_VERSION=1.64.8; \
58+
if ! command -v golangci-lint > /dev/null 2>&1; then \
59+
echo "Installing golangci-lint v$$LINT_VERSION..."; \
60+
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v$$LINT_VERSION/golangci-lint-$$LINT_VERSION-$$($(GO) env GOOS)-$$($(GO) env GOARCH).tar.gz | \
61+
tar xz --strip-components 1 --wildcards \*/golangci-lint; \
62+
mkdir -p bin && mv golangci-lint bin/; \
63+
echo "golangci-lint installed to bin/golangci-lint"; \
64+
fi
65+
66+
# Run linter
67+
lint: install-lint
68+
@if [ -f ./bin/golangci-lint ]; then \
69+
./bin/golangci-lint run --out-format=colored-line-number --timeout=3m; \
70+
else \
71+
golangci-lint run --out-format=colored-line-number --timeout=3m; \
72+
fi
73+
74+
# Clean build artifacts
75+
clean:
76+
rm -rf bin/
77+
rm -f coverage.out coverage.html
78+
79+
# Help
80+
help:
81+
@echo "Available targets:"
82+
@echo " all - Run verify, fmt, test, lint, and build (default)"
83+
@echo " build - Build Docker image"
84+
@echo " run - Run Docker container"
85+
@echo " local-build - Build the application"
86+
@echo " local-run - Run the application"
87+
@echo " verify - Verify dependencies"
88+
@echo " fmt - Format code"
89+
@echo " test - Run tests"
90+
@echo " test-coverage - Run tests with coverage"
91+
@echo " lint - Run linter"
92+
@echo " clean - Clean build artifacts"
93+
@echo " help - Show this help message"

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ The Razorpay MCP Server is a [Model Context Protocol (MCP)](https://modelcontext
66

77
Currently, the Razorpay MCP Server provides the following tools:
88

9-
| Tool | Description |
10-
|-----------------------|---------------------------------------|
11-
| `fetch_payment` | Fetch payment details |
12-
| `create_payment_link` | Creates a new payment link |
13-
| `fetch_payment_link` | Fetch details of a payment link |
14-
| `create_order` | Creates an order |
15-
| `fetch_order` | Fetch order details |
16-
9+
| Tool | Description | API
10+
|:----------------------|:------------------------------------------------|:-----------------------------------
11+
| `fetch_payment` | Fetch payment details with ID | [Payment](https://razorpay.com/docs/api/payments/fetch-with-id)
12+
| `create_payment_link` | Creates a new payment link (standard) | [Payment Link](https://razorpay.com/docs/api/payments/payment-links/create-standard)
13+
| `fetch_payment_link` | Fetch details of a payment link (standard) | [Payment Link](https://razorpay.com/docs/api/payments/payment-links/fetch-id-standard/)
14+
| `create_order` | Creates an order | [Order](https://razorpay.com/docs/api/orders/create/)
15+
| `fetch_order` | Fetch order with ID | [Order](https://razorpay.com/docs/api/orders/fetch-with-id)
16+
| `fetch_all_orders` | Fetch all orders | [Order](https://razorpay.com/docs/api/orders/fetch-all)
1717

1818
## Use Cases
1919
- Workflow Automation: Automate your day to day workflow using Razorpay MCP Server.

pkg/razorpay/orders.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,125 @@ func FetchOrder(
192192
handler,
193193
)
194194
}
195+
196+
// FetchAllOrders returns a tool to fetch all orders with optional filtering
197+
func FetchAllOrders(
198+
_ *slog.Logger,
199+
client *rzpsdk.Client,
200+
) mcpgo.Tool {
201+
parameters := []mcpgo.ToolParameter{
202+
mcpgo.WithNumber(
203+
"count",
204+
mcpgo.Description("Number of orders to be fetched "+
205+
"(default: 10, max: 100)"),
206+
mcpgo.Min(1),
207+
mcpgo.Max(100),
208+
),
209+
mcpgo.WithNumber(
210+
"skip",
211+
mcpgo.Description("Number of orders to be skipped (default: 0)"),
212+
mcpgo.Min(0),
213+
),
214+
mcpgo.WithNumber(
215+
"from",
216+
mcpgo.Description("Timestamp (in Unix format) from when "+
217+
"the orders should be fetched"),
218+
mcpgo.Min(0),
219+
),
220+
mcpgo.WithNumber(
221+
"to",
222+
mcpgo.Description("Timestamp (in Unix format) up till "+
223+
"when orders are to be fetched"),
224+
mcpgo.Min(0),
225+
),
226+
mcpgo.WithNumber(
227+
"authorized",
228+
mcpgo.Description("Filter orders based on payment authorization status. "+
229+
"Values: 0 (orders with unauthorized payments), "+
230+
"1 (orders with authorized payments)"),
231+
mcpgo.Min(0),
232+
mcpgo.Max(1),
233+
),
234+
mcpgo.WithString(
235+
"receipt",
236+
mcpgo.Description("Filter orders that contain the "+
237+
"provided value for receipt"),
238+
),
239+
mcpgo.WithArray(
240+
"expand",
241+
mcpgo.Description("Used to retrieve additional information. "+
242+
"Supported values: payments, payments.card, transfers, virtual_account"),
243+
),
244+
}
245+
246+
handler := func(
247+
ctx context.Context,
248+
r mcpgo.CallToolRequest,
249+
) (*mcpgo.ToolResult, error) {
250+
// Prepare query parameters map
251+
options := make(map[string]interface{})
252+
253+
// Process pagination options
254+
if result := AddPaginationToQueryParams(r, options); result != nil {
255+
return result, nil
256+
}
257+
258+
// Process date range parameters directly
259+
from, err := OptionalInt(r, "from")
260+
if result, _ := HandleValidationError(err); result != nil {
261+
return result, nil
262+
}
263+
if from > 0 {
264+
options["from"] = from
265+
}
266+
267+
to, err := OptionalInt(r, "to")
268+
if result, _ := HandleValidationError(err); result != nil {
269+
return result, nil
270+
}
271+
if to > 0 {
272+
options["to"] = to
273+
}
274+
275+
// Process authorized status parameter directly
276+
authorized, err := OptionalInt(r, "authorized")
277+
if result, _ := HandleValidationError(err); result != nil {
278+
return result, nil
279+
}
280+
281+
// Always add the authorized parameter if it was provided in the request
282+
options["authorized"] = authorized
283+
284+
// Process receipt parameter directly
285+
receipt, err := OptionalParam[string](r, "receipt")
286+
if result, _ := HandleValidationError(err); result != nil {
287+
return result, nil
288+
}
289+
if receipt != "" {
290+
options["receipt"] = receipt
291+
}
292+
293+
// Process expand parameters
294+
if result := AddExpandToQueryParams(r, options); result != nil {
295+
return result, nil
296+
}
297+
298+
// Fetch all orders using Razorpay SDK
299+
orders, err := client.Order.All(options, nil)
300+
if err != nil {
301+
return mcpgo.NewToolResultError(
302+
fmt.Sprintf("fetching orders failed: %s", err.Error()),
303+
), nil
304+
}
305+
306+
// Convert to JSON
307+
return mcpgo.NewToolResultJSON(orders)
308+
}
309+
310+
return mcpgo.NewTool(
311+
"fetch_all_orders",
312+
"Fetch all orders with optional filtering and pagination",
313+
parameters,
314+
handler,
315+
)
316+
}

0 commit comments

Comments
 (0)