Provide default transaction actions
This commit is contained in:
parent
06e7363783
commit
ecc52d3f4d
1 changed files with 25 additions and 3 deletions
28
main.ts
28
main.ts
|
@ -24,10 +24,18 @@ import * as log from "log/mod.ts";
|
||||||
|
|
||||||
const apl = new DenoAPL();
|
const apl = new DenoAPL();
|
||||||
|
|
||||||
|
type TransactionActions = "CHARGE" | "REFUND" | "CANCEL";
|
||||||
|
type TransactionProcessAction = "AUTHORIZATION" | "CHARGE";
|
||||||
|
|
||||||
interface TransactionRequestResponse {
|
interface TransactionRequestResponse {
|
||||||
pspReference: string;
|
pspReference: string;
|
||||||
result: string;
|
result: string;
|
||||||
amount: string;
|
amount: string;
|
||||||
|
data?: Record<string, string>;
|
||||||
|
time?: string;
|
||||||
|
externalUrl?: string;
|
||||||
|
nessage?: string;
|
||||||
|
actions?: Array<TransactionActions>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActionRequestResponse {
|
interface ActionRequestResponse {
|
||||||
|
@ -41,13 +49,26 @@ interface ActionRequestResponse {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTransactionActions(
|
||||||
|
action: TransactionProcessAction,
|
||||||
|
): Array<TransactionActions> {
|
||||||
|
if (action === "CHARGE") {
|
||||||
|
return ["REFUND"];
|
||||||
|
}
|
||||||
|
if (action === "AUTHORIZATION") {
|
||||||
|
return ["CHARGE", "CANCEL"];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
async function getTransactionResponse(
|
async function getTransactionResponse(
|
||||||
req: Request,
|
req: Request,
|
||||||
logger: log.Logger
|
logger: log.Logger,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const json = await req.json();
|
const json = await req.json();
|
||||||
const amount = json.action.amount;
|
const amount = json.action.amount;
|
||||||
const action = json.action.actionType ?? "CHARGE";
|
const action =
|
||||||
|
json.action.actionType ?? ("CHARGE" as TransactionProcessAction);
|
||||||
const saleorApiUrl = req.headers.get(SALEOR_API_URL_HEADER);
|
const saleorApiUrl = req.headers.get(SALEOR_API_URL_HEADER);
|
||||||
const data = json?.data;
|
const data = json?.data;
|
||||||
|
|
||||||
|
@ -74,13 +95,14 @@ async function getTransactionResponse(
|
||||||
pspReference: "initialize-test",
|
pspReference: "initialize-test",
|
||||||
result: `${action}_SUCCESS`,
|
result: `${action}_SUCCESS`,
|
||||||
amount,
|
amount,
|
||||||
|
actions: getTransactionActions(action),
|
||||||
...data,
|
...data,
|
||||||
} satisfies TransactionRequestResponse);
|
} satisfies TransactionRequestResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getActionResponse(
|
async function getActionResponse(
|
||||||
req: Request,
|
req: Request,
|
||||||
logger: log.Logger
|
logger: log.Logger,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const json = await req.json();
|
const json = await req.json();
|
||||||
const amount = json.action.amount;
|
const amount = json.action.amount;
|
||||||
|
|
Loading…
Reference in a new issue