generated from saleor/saleor-app-payment-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic setup for ListStoredPaymentMethods
- Loading branch information
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,10 @@ | ||
fragment ListStoredPaymentMethodsEvent on ListStoredPaymentMethods { | ||
__typename | ||
issuingPrincipal { | ||
__typename | ||
... on App { | ||
id | ||
name | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
subscription ListStoredPaymentMethods { | ||
event { | ||
...ListStoredPaymentMethodsEvent | ||
} | ||
} |
This file contains 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,17 @@ | ||
import { type ListStoredPaymentMethodsEventFragment } from "generated/graphql"; | ||
|
||
import { createLogger } from "@/lib/logger"; | ||
import { type ListStoredPaymentMethodsResponse } from "@/schemas/ListStoredPaymentMethods/ListStoredPaymentMethodsResponse.mjs"; | ||
|
||
export class ListStoredPaymentMethodsService { | ||
private logger = createLogger({ | ||
name: "ListStoredPaymentMethodsService", | ||
}); | ||
|
||
async execute( | ||
_payload: ListStoredPaymentMethodsEventFragment, | ||
): Promise<ListStoredPaymentMethodsResponse> { | ||
// TODO | ||
return {}; | ||
} | ||
} |
This file contains 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 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,71 @@ | ||
import { SaleorSyncWebhook } from "@saleor/app-sdk/handlers/next"; | ||
import { createLogger } from "@/lib/logger"; | ||
import { SynchronousWebhookResponseBuilder } from "@/lib/webhook-response-builder"; | ||
|
||
import { getAuthorizeConfig } from "@/modules/authorize-net/authorize-net-config"; | ||
import { AuthorizeWebhookManager } from "@/modules/authorize-net/webhook/authorize-net-webhook-manager"; | ||
import { createAppWebhookManager } from "@/modules/webhooks/webhook-manager-service"; | ||
import { errorUtils } from "@/error-utils"; | ||
import { saleorApp } from "@/saleor-app"; | ||
import { type ListStoredPaymentMethodsResponse } from "@/schemas/ListStoredPaymentMethods/ListStoredPaymentMethodsResponse.mjs"; | ||
import { | ||
UntypedListStoredPaymentMethodsDocument, | ||
type ListStoredPaymentMethodsEventFragment, | ||
} from "generated/graphql"; | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
}; | ||
|
||
export const listStoredPaymentMethodsSyncWebhook = | ||
new SaleorSyncWebhook<ListStoredPaymentMethodsEventFragment>({ | ||
name: "ListStoredPaymentMethods", | ||
apl: saleorApp.apl, | ||
event: "TRANSACTION_REFUND_REQUESTED", | ||
query: UntypedListStoredPaymentMethodsDocument, | ||
webhookPath: "/api/webhooks/list-stored-payment-methods", | ||
}); | ||
|
||
const logger = createLogger({ | ||
name: "listStoredPaymentMethodsSyncWebhook", | ||
}); | ||
|
||
class WebhookResponseBuilder extends SynchronousWebhookResponseBuilder<ListStoredPaymentMethodsResponse> {} | ||
|
||
export default listStoredPaymentMethodsSyncWebhook.createHandler( | ||
async (req, res, { authData, ...ctx }) => { | ||
const responseBuilder = new WebhookResponseBuilder(res); | ||
logger.debug({ payload: ctx.payload }, "handler called"); | ||
|
||
try { | ||
const authorizeConfig = getAuthorizeConfig(); | ||
const authorizeWebhookManager = new AuthorizeWebhookManager({ | ||
appConfig: authorizeConfig, | ||
}); | ||
|
||
await authorizeWebhookManager.register(); | ||
|
||
const appWebhookManager = await createAppWebhookManager({ | ||
authData, | ||
authorizeConfig, | ||
}); | ||
|
||
const response = await appWebhookManager.listStoredPaymentMethods(ctx.payload); | ||
// eslint-disable-next-line @saleor/saleor-app/logger-leak | ||
logger.info({ response }, "Responding with:"); | ||
return responseBuilder.ok(response); | ||
} catch (error) { | ||
const normalizedError = errorUtils.normalize(error); | ||
errorUtils.capture(normalizedError); | ||
logger.error(normalizedError); | ||
|
||
return responseBuilder.ok({ | ||
result: "REFUND_FAILURE", | ||
pspReference: "", // todo: add | ||
message: normalizedError.message, | ||
}); | ||
} | ||
}, | ||
); |
8 changes: 8 additions & 0 deletions
8
src/schemas/ListStoredPaymentMethods/ListStoredPaymentMethodsResponse.schema.json
This file contains 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,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"anyOf": [ | ||
{ | ||
"type": "object" | ||
} | ||
] | ||
} |