Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"cross-fetch": "^3.1.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"gretchen": "^1.5.0",
"ngrok": "^4.2.2"
},
"jest": {
Expand Down
27 changes: 15 additions & 12 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require("cross-fetch/polyfill");

const path = require("path");
const express = require("express");
const { gretch } = require("gretchen");

const app = express();
const API_BASE_URL = "https://api.truework-sandbox.com";
Expand Down Expand Up @@ -39,22 +38,23 @@ app.get("/token", async (req, res) => {
],
};

const { data, error, status, response } = await gretch(
const response = await fetch(
`${API_BASE_URL}/orders/truework-direct`,
{
method: "POST",
headers: {
Accept: "application/json; version=2023-10-30",
Authorization: `Bearer ${TW_SANDBOX_API_TOKEN}`,
},
json: USER_PAYLOAD,
body: JSON.stringify(USER_PAYLOAD),
}
).json();
)

const data = await response.json().catch(e => undefined)
if (!response.ok) {
console.error(
`${status} error when creating session:\n${JSON.stringify(
error,
`${response.status} error when creating session:\n${JSON.stringify(
data,
null,
2
)}`
Expand Down Expand Up @@ -101,25 +101,28 @@ app.post("/webhook", async (req, res) => {
*/
if (req.body.hook.event === "order.completed") {
const id = req.body.data.order_id;
const { status, data, error, response } = await gretch(
const response = await fetch(
`${API_BASE_URL}/orders/${id}`,
{
headers: {
Authorization: `Bearer ${TW_SANDBOX_API_TOKEN}`,
Accept: "application/json; version=2023-10-30",
},
}
).json();
)

if (!response.ok || !data) {
const data = await response.json().catch(e => undefined)
if (!response.ok) {
console.error(
`${status} error when fetching verification:\n${JSON.stringify(
error,
`${response.status} error when fetching verification:\n${JSON.stringify(
data,
null,
2
)}`
);
} else if (data) {
}

if (data) {
console.info(
`Received verification data:\n${JSON.stringify(data, null, 2)}`
);
Expand Down