From 28068f7334c717bf1dd2f671856af9dde9d8b0e2 Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Mon, 7 Aug 2023 17:24:47 +0200 Subject: [PATCH] Add transaction process --- main.ts | 26 ++++++++++++++++------ subscriptions.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/main.ts b/main.ts index 6f36c46..9245e55 100644 --- a/main.ts +++ b/main.ts @@ -8,6 +8,7 @@ import { gatewayInitialize, refundSub, transactionInitialize, + transactionProcess, } from "./subscriptions.ts"; interface ActionRequestResponse { @@ -73,6 +74,12 @@ const routes = [ query: transactionInitialize, syncEvents: ["TRANSACTION_INITIALIZE_SESSION"], }, + { + name: "Transaction Process", + targetUrl: `${URL}/transaction-process`, + query: transactionProcess, + syncEvents: ["TRANSACTION_PROCESS_SESSION"], + }, { name: "Charge Request", targetUrl: `${URL}/transaction-charge-requested`, @@ -91,12 +98,6 @@ const routes = [ query: cancelSub, syncEvents: ["TRANSACTION_CANCELATION_REQUESTED"], }, - // { - // name: "Action request async", - // targetUrl: `${URL}/transaction-action-request`, - // isActive: true, - // asyncEvents: ["TRANSACTION_ACTION_REQUEST"] - // } ], } satisfies AppManifest); }), @@ -125,7 +126,18 @@ const routes = [ const amount = json.action.amount; return Response.OK({ pspReference: "initialize-test", - result: "CHARGE_SUCCESS", + result: json?.data?.final ? "CHARGE_SUCCESS" : "CHARGE_REQUEST", + amount, + }); + }), + POST("/transaction-process", async (req: Request) => { + const json = await req.json(); + console.log("transaction process", json); + console.log("headers", req.headers); + const amount = json.action.amount; + return Response.OK({ + pspReference: "initialize-test", + result: json?.data?.final ? "CHARGE_SUCCESS" : "CHARGE_REQUEST", amount, }); }), diff --git a/subscriptions.ts b/subscriptions.ts index 798e0c0..cdffeec 100644 --- a/subscriptions.ts +++ b/subscriptions.ts @@ -83,6 +83,62 @@ export const transactionInitialize = `subscription { } }`; +export const transactionProcess = `fragment Money { + ... on Money { + currency + amount + } +} + +subscription { + event { + ... on TransactionProcessSession { + issuedAt + version + issuingPrincipal { + ... on User { + id + lastName + firstName + } + ... on App { + id + name + } + __typename + } + recipient { + id + name + } + sourceObject { + ... on Checkout { + id + totalPrice { + currency + gross { + ...Money + } + } + } + ... on Order { + id + total { + currency + gross { + ...Money + } + } + } + __typename + } + data + merchantReference + action + } + } +}`; + export const chargeSub = `subscription { event { ... on TransactionChargeRequested {