Skip to content

Commit d1eff07

Browse files
committed
feat: add get_subscription tool
1 parent c9464d0 commit d1eff07

6 files changed

Lines changed: 124 additions & 3 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> MCP server for Iyzico (Turkish payment processor) — read-mostly access for Claude / Cursor / cline.
44
5-
**v0.0.2**4 read tools: `get_payment`, `list_payments`, `get_bin_info`, `get_installment_info`. Not yet published to npm; install from source.
5+
**v0.0.3**5 read tools: `get_payment`, `list_payments`, `get_bin_info`, `get_installment_info`, `get_subscription`. Not yet published to npm; install from source.
66

77
## Tools
88

@@ -53,6 +53,17 @@ List installment options Iyzico will allow for a given card BIN at a given price
5353
| `price` | string | yes | Total price as a decimal string (e.g. `"1000"`, `"1000.50"`). |
5454
| `locale` | `"tr"` \| `"en"` | no | Response language. Default `"en"`. |
5555

56+
### `get_subscription`
57+
58+
Retrieve an Iyzico subscription by its reference code. Returns subscription state (active/canceled/expired), pricing plan, customer reference, and billing schedule.
59+
60+
**Input:**
61+
62+
| field | type | required | notes |
63+
|---|---|---|---|
64+
| `subscriptionReferenceCode` | string | yes | Iyzico subscription reference code (returned at subscription creation, permanent ID). |
65+
| `locale` | `"tr"` \| `"en"` | no | Response language. Default `"en"`. |
66+
5667
## Setup
5768

5869
### Install from source

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@verepdev/iyzico-mcp",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "MCP server scaffold for Iyzico (Turkish payment processor) — read-mostly access for Claude / Cursor / cline.",
55
"type": "module",
66
"main": "dist/index.js",

src/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
55
import { getBinInfo, getBinInfoInputShape } from "./tools/get_bin_info.js";
66
import { getInstallmentInfo, getInstallmentInfoInputShape } from "./tools/get_installment_info.js";
77
import { getPayment, getPaymentInputShape } from "./tools/get_payment.js";
8+
import { getSubscription, getSubscriptionInputShape } from "./tools/get_subscription.js";
89
import { listPayments, listPaymentsInputShape } from "./tools/list_payments.js";
910

1011
const server = new McpServer({
1112
name: "iyzico-mcp",
12-
version: "0.0.2",
13+
version: "0.0.3",
1314
});
1415

1516
server.tool(
@@ -80,5 +81,22 @@ server.tool(
8081
},
8182
);
8283

84+
server.tool(
85+
"get_subscription",
86+
"Retrieve an Iyzico subscription by its reference code. Returns subscription state (active/canceled/expired), pricing plan, customer reference, and billing schedule.",
87+
getSubscriptionInputShape,
88+
async (input) => {
89+
const result = await getSubscription(input);
90+
return {
91+
content: [
92+
{
93+
type: "text",
94+
text: JSON.stringify(result, null, 2),
95+
},
96+
],
97+
};
98+
},
99+
);
100+
83101
const transport = new StdioServerTransport();
84102
await server.connect(transport);

src/iyzico/types.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,22 @@ declare module "iyzipay" {
6060
retrieve(request: InstallmentInfoRetrieveRequest, cb: Callback): void;
6161
}
6262

63+
export interface SubscriptionRetrieveRequest {
64+
locale?: "tr" | "en";
65+
conversationId?: string;
66+
subscriptionReferenceCode: string;
67+
}
68+
69+
export interface SubscriptionResource {
70+
retrieve(request: SubscriptionRetrieveRequest, cb: Callback): void;
71+
}
72+
6373
export default class Iyzipay {
6474
constructor(config: IyzipayConfig);
6575
payment: PaymentResource;
6676
reportingTransactions: ReportingTransactionsResource;
6777
binNumber: BinNumberResource;
6878
installmentInfo: InstallmentInfoResource;
79+
subscription: SubscriptionResource;
6980
}
7081
}

src/tools/get_subscription.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { IyzicoResponse } from "iyzipay";
2+
import { z } from "zod";
3+
import { createClient, getConfig } from "../iyzico/client.js";
4+
import { mapIyzicoFailure } from "../iyzico/error.js";
5+
6+
export const getSubscriptionInputShape = {
7+
subscriptionReferenceCode: z
8+
.string()
9+
.min(1)
10+
.describe(
11+
"Iyzico subscription reference code (returned at subscription creation, used as the subscription's permanent ID).",
12+
),
13+
locale: z.enum(["tr", "en"]).default("en").describe("Response language. Default 'en'."),
14+
};
15+
16+
export const getSubscriptionInputSchema = z.object(getSubscriptionInputShape);
17+
export type GetSubscriptionInput = z.infer<typeof getSubscriptionInputSchema>;
18+
19+
export async function getSubscription(input: GetSubscriptionInput): Promise<IyzicoResponse> {
20+
const config = getConfig();
21+
const client = createClient(config);
22+
23+
return new Promise<IyzicoResponse>((resolve, reject) => {
24+
client.subscription.retrieve(
25+
{
26+
locale: input.locale,
27+
conversationId: `mcp-get-subscription-${input.subscriptionReferenceCode}`,
28+
subscriptionReferenceCode: input.subscriptionReferenceCode,
29+
},
30+
(err, result) => {
31+
if (err) {
32+
reject(err instanceof Error ? err : new Error(String(err)));
33+
return;
34+
}
35+
const failure = mapIyzicoFailure(result);
36+
if (failure) {
37+
reject(failure);
38+
return;
39+
}
40+
resolve(result);
41+
},
42+
);
43+
});
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { getSubscriptionInputSchema } from "../../src/tools/get_subscription";
3+
4+
describe("get_subscription input schema", () => {
5+
test("accepts valid reference code and applies locale default", () => {
6+
const result = getSubscriptionInputSchema.parse({
7+
subscriptionReferenceCode: "SUB-REF-12345",
8+
});
9+
expect(result.subscriptionReferenceCode).toBe("SUB-REF-12345");
10+
expect(result.locale).toBe("en");
11+
});
12+
13+
test("accepts explicit locale", () => {
14+
const result = getSubscriptionInputSchema.parse({
15+
subscriptionReferenceCode: "SUB-REF-12345",
16+
locale: "tr",
17+
});
18+
expect(result.locale).toBe("tr");
19+
});
20+
21+
test("rejects missing subscriptionReferenceCode", () => {
22+
expect(() => getSubscriptionInputSchema.parse({})).toThrow();
23+
});
24+
25+
test("rejects empty subscriptionReferenceCode", () => {
26+
expect(() => getSubscriptionInputSchema.parse({ subscriptionReferenceCode: "" })).toThrow();
27+
});
28+
29+
test("rejects invalid locale", () => {
30+
expect(() =>
31+
getSubscriptionInputSchema.parse({
32+
subscriptionReferenceCode: "SUB-REF-12345",
33+
locale: "de",
34+
}),
35+
).toThrow();
36+
});
37+
});

0 commit comments

Comments
 (0)