Skip to content

Commit b113e72

Browse files
authored
feat: add payout tool (#22)
* feat: add payout tool * fix: bug fixes for payouts service * chore : added description and convention * fix: dependencies restore except razorpay-go * Merge branch 'main' into razorng/Payout_API_integration
1 parent e0b9584 commit b113e72

File tree

6 files changed

+389
-3
lines changed

6 files changed

+389
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Currently, the Razorpay MCP Server provides the following tools:
4343
| `create_instant_settlement` | Create an instant settlement | [Settlement](https://razorpay.com/docs/api/settlements/instant/create)
4444
| `fetch_all_instant_settlements` | Fetch all instant settlements | [Settlement](https://razorpay.com/docs/api/settlements/instant/fetch-all)
4545
| `fetch_instant_settlement_with_id` | Fetch instant settlement with ID | [Settlement](https://razorpay.com/docs/api/settlements/instant/fetch-with-id)
46+
| `fetch_all_payouts` | Fetch all payout details with A/c number | [Payout](https://razorpay.com/docs/api/x/payouts/fetch-all/)
47+
| `fetch_payout_by_id` | Fetch the payout details with payout ID | [Payout](https://razorpay.com/docs/api/x/payouts/fetch-with-id)
4648

4749

4850
## Use Cases

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-test/deep v1.1.1
77
github.com/gorilla/mux v1.8.1
88
github.com/mark3labs/mcp-go v0.23.1
9-
github.com/razorpay/razorpay-go v1.3.2
9+
github.com/razorpay/razorpay-go v1.3.3
1010
github.com/spf13/cobra v1.9.1
1111
github.com/spf13/viper v1.20.1
1212
github.com/stretchr/testify v1.10.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0
2828
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
2929
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3030
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
31-
github.com/razorpay/razorpay-go v1.3.2 h1:6368QznCNkoQNi7bBbxdHUu7lJJW4UxN7W3WftrbFZg=
32-
github.com/razorpay/razorpay-go v1.3.2/go.mod h1:VcljkUylUJAUEvFfGVv/d5ht1to1dUgF4H1+3nv7i+Q=
31+
github.com/razorpay/razorpay-go v1.3.3 h1:htVhJPI8SXx7X9POcoGg2uMVzbn8hzv7UP9VvbMYYdw=
32+
github.com/razorpay/razorpay-go v1.3.3/go.mod h1:VcljkUylUJAUEvFfGVv/d5ht1to1dUgF4H1+3nv7i+Q=
3333
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
3434
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
3535
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

pkg/razorpay/payouts.go

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package razorpay
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log/slog"
7+
8+
rzpsdk "github.com/razorpay/razorpay-go"
9+
10+
"github.com/razorpay/razorpay-mcp-server/pkg/mcpgo"
11+
)
12+
13+
// FetchPayoutByID returns a tool that fetches a payout by its ID
14+
func FetchPayout(
15+
log *slog.Logger,
16+
client *rzpsdk.Client,
17+
) mcpgo.Tool {
18+
parameters := []mcpgo.ToolParameter{
19+
mcpgo.WithString(
20+
"payout_id",
21+
mcpgo.Description(
22+
"The unique identifier of the payout. For example, 'pout_00000000000001'",
23+
),
24+
mcpgo.Required(),
25+
),
26+
}
27+
28+
handler := func(
29+
ctx context.Context,
30+
r mcpgo.CallToolRequest,
31+
) (*mcpgo.ToolResult, error) {
32+
FetchPayoutOptions := make(map[string]interface{})
33+
34+
validator := NewValidator(&r).
35+
ValidateAndAddRequiredString(FetchPayoutOptions, "payout_id")
36+
37+
if result, err := validator.HandleErrorsIfAny(); result != nil {
38+
return result, err
39+
}
40+
41+
payout, err := client.Payout.Fetch(
42+
FetchPayoutOptions["payout_id"].(string),
43+
nil,
44+
nil,
45+
)
46+
if err != nil {
47+
return mcpgo.NewToolResultError(
48+
fmt.Sprintf("fetching payout failed: %s", err.Error())), nil
49+
}
50+
51+
return mcpgo.NewToolResultJSON(payout)
52+
}
53+
54+
return mcpgo.NewTool(
55+
"fetch_payout_with_id",
56+
"Fetch a payout's details using its ID",
57+
parameters,
58+
handler,
59+
)
60+
}
61+
62+
// FetchAllPayouts returns a tool that fetches all payouts
63+
func FetchAllPayouts(
64+
log *slog.Logger,
65+
client *rzpsdk.Client,
66+
) mcpgo.Tool {
67+
parameters := []mcpgo.ToolParameter{
68+
mcpgo.WithString(
69+
"account_number",
70+
mcpgo.Description("The account from which the payouts were done."+
71+
"For example, 7878780080316316"),
72+
mcpgo.Required(),
73+
),
74+
mcpgo.WithNumber(
75+
"count",
76+
mcpgo.Description("Number of payouts to be fetched. Default value is 10."+
77+
"Maximum value is 100. This can be used for pagination,"+
78+
"in combination with the skip parameter"),
79+
mcpgo.Min(1),
80+
),
81+
mcpgo.WithNumber(
82+
"skip",
83+
mcpgo.Description("Numbers of payouts to be skipped. Default value is 0."+
84+
"This can be used for pagination, in combination with count"),
85+
mcpgo.Min(0),
86+
),
87+
}
88+
89+
handler := func(
90+
ctx context.Context,
91+
r mcpgo.CallToolRequest,
92+
) (*mcpgo.ToolResult, error) {
93+
FetchAllPayoutsOptions := make(map[string]interface{})
94+
95+
validator := NewValidator(&r).
96+
ValidateAndAddRequiredString(FetchAllPayoutsOptions, "account_number").
97+
ValidateAndAddPagination(FetchAllPayoutsOptions)
98+
99+
if result, err := validator.HandleErrorsIfAny(); result != nil {
100+
return result, err
101+
}
102+
103+
payout, err := client.Payout.All(FetchAllPayoutsOptions, nil)
104+
if err != nil {
105+
return mcpgo.NewToolResultError(
106+
fmt.Sprintf("fetching payouts failed: %s", err.Error())), nil
107+
}
108+
109+
return mcpgo.NewToolResultJSON(payout)
110+
}
111+
112+
return mcpgo.NewTool(
113+
"fetch_all_payouts",
114+
"Fetch all payouts for a bank account number",
115+
parameters,
116+
handler,
117+
)
118+
}

0 commit comments

Comments
 (0)