Add transaction process
This commit is contained in:
parent
eaa40cf94a
commit
28068f7334
2 changed files with 75 additions and 7 deletions
26
main.ts
26
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,
|
||||
});
|
||||
}),
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue