diff --git a/main.ts b/main.ts index 1b7df5d..6675523 100644 --- a/main.ts +++ b/main.ts @@ -2,7 +2,13 @@ import { serve } from "wren/mod.ts"; import { GET, POST } from "wren/route.ts"; import * as Response from "wren/response.ts"; import { AppManifest } from "./types.ts"; -import { cancelSub, chargeSub, refundSub } from "./subscriptions.ts"; +import { + cancelSub, + chargeSub, + gatewayInitialize, + refundSub, + transactionInitialize, +} from "./subscriptions.ts"; interface ActionRequestResponse { pspReference: string; @@ -50,6 +56,18 @@ const routes = [ permissions: ["HANDLE_PAYMENTS", "HANDLE_CHECKOUTS", "MANAGE_ORDERS"], tokenTargetUrl: `${URL}/install`, webhooks: [ + { + name: "Gateway Initialize", + targetUrl: `${URL}/gateway-initialize`, + query: gatewayInitialize, + syncEvents: ["PAYMENT_GATEWAY_INITIALIZE_SESSION"], + }, + { + name: "Transaction Initialize", + targetUrl: `${URL}/transaction-initialize`, + query: transactionInitialize, + syncEvents: ["TRANSACTION_INITIALIZE_SESSION"], + }, { name: "Charge Request", targetUrl: `${URL}/transaction-charge-requested`, @@ -85,6 +103,27 @@ const routes = [ success: true, }); }), + POST("/gateway-initialize", async (req: Request) => { + const json = await req.json(); + console.log("gateway initialize", json); + console.log("headers", req.headers); + return Response.OK({ + data: { + some: "data", + }, + }); + }), + POST("/transaction-initialize", async (req: Request) => { + const json = await req.json(); + console.log("transaction initialize", json); + console.log("headers", req.headers); + const amount = json.action.amount; + return Response.OK({ + pspReference: "initialize-test", + result: "CHARGE_SUCCESS", + amount, + }); + }), POST("/transaction-charge-requested", async (req: Request) => { const json = await req.json(); console.log("charge request", json); diff --git a/subscriptions.ts b/subscriptions.ts index 0ea0597..f5032c6 100644 --- a/subscriptions.ts +++ b/subscriptions.ts @@ -1,3 +1,58 @@ +export const gatewayInitialize = `subscription { + event { + ... on PaymentGatewayInitializeSession { + issuedAt + version + issuingPrincipal { + ... on Node { + id + } + __typename + } + recipient { + id + name + } + sourceObject { + __typename + } + data + amount + } + } +}`; + +export const transactionInitialize = `subscription { + event { + ... on TransactionInitializeSession { + issuedAt + version + issuingPrincipal { + ... on Node { + id + } + __typename + } + recipient { + id + name + } + transaction { + id + name + pspReference + } + data + merchantReference + action { + amount + currency + actionType + } + } + } +}` + export const chargeSub = `subscription { event { ... on TransactionChargeRequested { @@ -20,7 +75,7 @@ export const chargeSub = `subscription { } } } -` +`; export const refundSub = `subscription { event { @@ -43,7 +98,7 @@ export const refundSub = `subscription { } } } -}` +}`; export const cancelSub = `subscription { event { @@ -66,4 +121,4 @@ export const cancelSub = `subscription { } } } -}` +}`;