From ac37a5833005f8b8084fecd039e2b7e26c1d9a9d Mon Sep 17 00:00:00 2001 From: KutluhanETH Date: Mon, 7 Sep 2026 22:27:16 +0000 Subject: [PATCH] fix(ack-pay): accept DID URIs for serviceCallback Align paymentRequest.serviceCallback with paymentService/receiptService and the documented URL-or-DID contract by reusing urlOrDidUri in both Valibot and Zod schemas. Fixes #205 --- .../ack-pay-service-callback-did-uri.md | 5 +++++ packages/ack-pay/src/schemas/schemas.test.ts | 19 +++++++++++++++++++ packages/ack-pay/src/schemas/valibot.ts | 2 +- packages/ack-pay/src/schemas/zod.ts | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .changeset/ack-pay-service-callback-did-uri.md diff --git a/.changeset/ack-pay-service-callback-did-uri.md b/.changeset/ack-pay-service-callback-did-uri.md new file mode 100644 index 00000000..6246bdc4 --- /dev/null +++ b/.changeset/ack-pay-service-callback-did-uri.md @@ -0,0 +1,5 @@ +--- +"@agentcommercekit/ack-pay": patch +--- + +Allow `paymentRequest.serviceCallback` to accept DID URIs in addition to URLs, matching the documented field contract and the existing `paymentService` / `receiptService` schemas. diff --git a/packages/ack-pay/src/schemas/schemas.test.ts b/packages/ack-pay/src/schemas/schemas.test.ts index 735b3ead..7d0fca6d 100644 --- a/packages/ack-pay/src/schemas/schemas.test.ts +++ b/packages/ack-pay/src/schemas/schemas.test.ts @@ -43,4 +43,23 @@ describe("paymentRequestSchema", () => { expect(zod.success && zod.data.expiresAt).toBe(expected) } }) + + it("accepts URL and DID URI serviceCallback values", () => { + for (const serviceCallback of [ + "https://service.example.com/webhook/payment-complete", + "did:web:merchant.example", + ]) { + const input = { ...paymentRequest, serviceCallback } + + expect(v.safeParse(valibotPaymentRequestSchema, input).success).toBe(true) + expect(zodPaymentRequestSchema.safeParse(input).success).toBe(true) + } + }) + + it("rejects invalid serviceCallback values", () => { + const input = { ...paymentRequest, serviceCallback: "not-a-url-or-did" } + + expect(v.safeParse(valibotPaymentRequestSchema, input).success).toBe(false) + expect(zodPaymentRequestSchema.safeParse(input).success).toBe(false) + }) }) diff --git a/packages/ack-pay/src/schemas/valibot.ts b/packages/ack-pay/src/schemas/valibot.ts index 75fc9807..09f221da 100644 --- a/packages/ack-pay/src/schemas/valibot.ts +++ b/packages/ack-pay/src/schemas/valibot.ts @@ -28,7 +28,7 @@ export const paymentOptionSchema = v.object({ export const paymentRequestSchema = v.object({ id: v.string(), description: v.optional(v.string()), - serviceCallback: v.optional(v.pipe(v.string(), v.url())), + serviceCallback: v.optional(urlOrDidUri), expiresAt: v.optional(timestampSchema), paymentOptions: v.pipe( v.tupleWithRest([paymentOptionSchema], paymentOptionSchema), diff --git a/packages/ack-pay/src/schemas/zod.ts b/packages/ack-pay/src/schemas/zod.ts index 05cfdca8..623e0c1f 100644 --- a/packages/ack-pay/src/schemas/zod.ts +++ b/packages/ack-pay/src/schemas/zod.ts @@ -35,7 +35,7 @@ export const paymentOptionSchema = z.object({ export const paymentRequestSchema = z.object({ id: z.string(), description: z.string().optional(), - serviceCallback: z.url().optional(), + serviceCallback: urlOrDidUri.optional(), expiresAt: timestampSchema.optional(), paymentOptions: z.array(paymentOptionSchema).nonempty(), })