Skip to content

Commit

Permalink
Added square example (triggerdotdev#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
biplobsd committed Oct 28, 2023
1 parent abaa8f5 commit eeb4d85
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ NOVU_API_KEY=
## Loops
LOOPS_BASE_URL=https://app.loops.so/api/v1
LOOPS_API_KEY=

## SQUARE
SQUARE_ACCESS_TOKEN=
216 changes: 215 additions & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"zbd": "node -r dotenv/config -r ts-node/register src/zbd.ts",
"novu": "node -r dotenv/config -r ts-node/register src/novu.ts",
"brex": "node -r dotenv/config -r ts-node/register src/brex.ts",
"square": "node -r dotenv/config -r ts-node/register src/square.ts",
"dev:trigger": "trigger-cli dev --port 8080"

},
"dependencies": {
"@doist/todoist-api-typescript": "^3.0.0",
Expand All @@ -47,6 +47,7 @@
"octokit": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"square": "^32.0.0",
"svix": "^1.13.0",
"twilio": "^4.19.0",
"zod": "^3.21.4"
Expand All @@ -66,4 +67,4 @@
"tslib": "^2.6.2",
"typescript": "^5.2.2"
}
}
}
51 changes: 51 additions & 0 deletions src/square.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
import { Client, Environment } from "square";
import z from "zod";

const client = new TriggerClient({ id: "api-reference" });

// SDK: https://developer.squareup.com/docs/sdks/nodejs
// Initialize the Square client with your credentials
const squareClient = new Client({
environment: Environment.Production, // Use Square.Environment.Sandbox for testing
accessToken: process.env.SQUARE_ACCESS_TOKEN!, // Get your access token at https://developer.squareup.com/docs/build-basics/access-tokens
});

client.defineJob({
id: "square-create-customer",
name: "Square create customer",
version: "1.0.0",
trigger: eventTrigger({
name: "square-create-customer",
schema: z.object({
givenName: z.string(),
familyName: z.string().optional(),
companyName: z.string().optional(),
emailAddress: z.string().optional(),
phoneNumber: z.string().optional(),
}),
}),
run: async (payload, io, ctx) => {

// Wrap an SDK call in io.runTask so it's resumable and displays in logs
await io.runTask(
"Square create customer",
async () => {
// Use the Square SDK to send a message to the seller
const customersApi = squareClient.customersApi;

// After create a customer you can see it in the Square dashboard
// at https://squareup.com/dashboard/customers/directory/all
// See more https://developer.squareup.com/reference/square/customers-api/create-customer
await customersApi.createCustomer(payload);
},

// Add metadata to the task to improve the display in the logs
{ name: "Square create customer", icon: "square" }
);
},
});

// These lines can be removed if you don't want to use express
import { createExpressServer } from "@trigger.dev/express";
createExpressServer(client);

0 comments on commit eeb4d85

Please sign in to comment.