Skip to content

Commit

Permalink
Added square example (#41) (#73)
Browse files Browse the repository at this point in the history
* Added square example (#41)

* Fixes spaces and reduce line
  • Loading branch information
biplobsd authored Oct 30, 2023
1 parent 0ec1a3f commit c1d37b4
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ NOVU_API_KEY=
LOOPS_BASE_URL=https://app.loops.so/api/v1
LOOPS_API_KEY=

## SQUARE
SQUARE_ACCESS_TOKEN=

## Lemon Squeezy
LEMONSQUEEZY_API_KEY=
LEMONSQUEEZY_API_KEY=
214 changes: 214 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"notion": "node -r dotenv/config -r ts-node/register src/notion.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",
"lemon-squeezy": "node -r dotenv/config -r ts-node/register src/lemon-squeezy.ts",
"dev:trigger": "trigger-cli dev --port 8080"
},
Expand All @@ -50,6 +51,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 Down
47 changes: 47 additions & 0 deletions src/square.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 () => {
// 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 squareClient.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 c1d37b4

Please sign in to comment.