-
Notifications
You must be signed in to change notification settings - Fork 369
Webhook responses for Stripe use-cases #1858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
295ea9d
Webhook responses
krzysztofzuraw d1a02b9
Merge branch 'main' into webhook-response-result
krzysztofzuraw 104a386
fix test
krzysztofzuraw 012bff7
fixes after CR
krzysztofzuraw db45f9e
fixes after CR
krzysztofzuraw b5d9316
fixes after CR
krzysztofzuraw 435192a
renames
krzysztofzuraw 3181d06
fix test
krzysztofzuraw 9e06417
fixes after CR
krzysztofzuraw 8918d0f
add unit test
krzysztofzuraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { StripePublishableKey } from "@/modules/stripe/stripe-publishable-key"; | ||
|
||
export const stripePublishableKey = StripePublishableKey.create({ | ||
publishableKey: "pk_live_1", | ||
})._unsafeUnwrap(); |
26 changes: 0 additions & 26 deletions
26
apps/stripe/src/app/api/saleor/payment-gateway-initialize-session/response-shape.test.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
apps/stripe/src/app/api/saleor/payment-gateway-initialize-session/response-shape.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/stripe/src/app/api/saleor/payment-gateway-initialize-session/use-case-response.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { stripePublishableKey } from "@/__tests__/mocks/stripe-publishable-key"; | ||
|
||
import { PaymentGatewayInitializeSessionUseCaseResponses } from "./use-case-response"; | ||
|
||
describe("PaymentGatewayInitializeSessionUseCaseResponses", () => { | ||
describe("Success", () => { | ||
it("should return fetch API response with status code and message", async () => { | ||
const successResponse = new PaymentGatewayInitializeSessionUseCaseResponses.Success({ | ||
pk: stripePublishableKey, | ||
}); | ||
const fetchReponse = successResponse.getResponse(); | ||
|
||
expect(fetchReponse.status).toBe(200); | ||
expect(await fetchReponse.json()).toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"stripePublishableKey": "pk_live_1", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
apps/stripe/src/app/api/saleor/payment-gateway-initialize-session/use-case-response.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { buildSyncWebhookResponsePayload } from "@saleor/app-sdk/handlers/shared"; | ||
import { z } from "zod"; | ||
|
||
import { SuccessWebhookResponse } from "@/modules/saleor/saleor-webhook-responses"; | ||
import { StripePublishableKey } from "@/modules/stripe/stripe-publishable-key"; | ||
|
||
class Success extends SuccessWebhookResponse { | ||
pk: StripePublishableKey; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you pass it to constructor, better make it readonly or private. Mutation of class member can lead to hard to find bugs and I dont think its our intention |
||
|
||
private static ResponseDataSchema = z.object({ | ||
stripePublishableKey: z.string(), | ||
}); | ||
|
||
constructor(args: { pk: StripePublishableKey }) { | ||
super(); | ||
this.pk = args.pk; | ||
} | ||
|
||
getResponse() { | ||
const typeSafeResponse = buildSyncWebhookResponsePayload<"PAYMENT_GATEWAY_INITIALIZE_SESSION">({ | ||
data: Success.ResponseDataSchema.parse({ | ||
stripePublishableKey: this.pk.keyValue, | ||
}), | ||
}); | ||
|
||
return Response.json(typeSafeResponse, { status: this.statusCode }); | ||
} | ||
} | ||
|
||
export const PaymentGatewayInitializeSessionUseCaseResponses = { | ||
Success, | ||
}; | ||
|
||
export type PaymentGatewayInitializeSessionUseCaseResponsesType = InstanceType< | ||
(typeof PaymentGatewayInitializeSessionUseCaseResponses)[keyof typeof PaymentGatewayInitializeSessionUseCaseResponses] | ||
>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Response is more obvious that "fetch API response" (I am editing this comment because I didnt understand it before)