Add missing subscriptions
This commit is contained in:
parent
d0d753fa2c
commit
04a92c77e5
2 changed files with 98 additions and 4 deletions
41
main.ts
41
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);
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
}`;
|
||||
|
|
Loading…
Reference in a new issue