Skip to content

Commit

Permalink
feat: add commerce package
Browse files Browse the repository at this point in the history
  • Loading branch information
roushou committed Jun 23, 2024
1 parent 484f3ff commit 695c983
Show file tree
Hide file tree
Showing 31 changed files with 898 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-berries-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase-platform/commerce": minor
---

feat: add `commerce` package
7 changes: 7 additions & 0 deletions examples/commerce_create-charge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Create charge - Commerce

Run

```sh
$ bun run index.ts
```
21 changes: 21 additions & 0 deletions examples/commerce_create-charge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
type CreateChargeParameters,
createCharge,
} from "@coinbase-platform/commerce";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const parameters: CreateChargeParameters = {
name: "Nvidia RTX 4080",
description: "Graphic Card",
pricing_type: "fixed_price",
local_price: {
amount: "1000.00",
currency: "USD",
},
};

const response = await createCharge(parameters, apiKey);

console.log(JSON.stringify(response, null, 2));
16 changes: 16 additions & 0 deletions examples/commerce_create-charge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/commerce_create-charge",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase-platform/commerce": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/commerce_create-charge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/commerce_create-checkout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Create checkout - Commerce

Run

```sh
$ bun run index.ts
```
23 changes: 23 additions & 0 deletions examples/commerce_create-checkout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
type CreateCheckoutParameters,
createCheckout,
} from "@coinbase-platform/commerce";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const parameters: CreateCheckoutParameters = {
name: "Nvidia RTX 4080",
description: "Graphic Card",
pricing_type: "fixed_price",
local_price: {
amount: "1000.00",
currency: "USD",
},
logo_url: "",
requested_info: [],
};

const response = await createCheckout(parameters, apiKey);

console.log(JSON.stringify(response, null, 2));
16 changes: 16 additions & 0 deletions examples/commerce_create-checkout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/commerce_create-checkout",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase-platform/commerce": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/commerce_create-checkout/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/commerce_get-charges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get charge - Commerce

Run

```sh
$ bun run index.ts
```
13 changes: 13 additions & 0 deletions examples/commerce_get-charges/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getCharge, getCharges } from "@coinbase-platform/commerce";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

// Get a charge by id
const chargeId = "fb86d331-1db8-44f2-a96c-235d2a855ad3";
const charge = await getCharge(chargeId, apiKey);
console.log(JSON.stringify(charge, null, 2));

// Get all charges
const charges = await getCharges(apiKey);
console.log(JSON.stringify(charges, null, 2));
16 changes: 16 additions & 0 deletions examples/commerce_get-charges/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/commerce_get-charges",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase-platform/commerce": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/commerce_get-charges/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/commerce_get-checkouts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get checkout - Commerce

Run

```sh
$ bun run index.ts
```
13 changes: 13 additions & 0 deletions examples/commerce_get-checkouts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getCheckout, getCheckouts } from "@coinbase-platform/commerce";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

// Get a checkout by id
const checkoutId = "a6e9fdd6-877d-4b2d-9d2e-70e810211b52";
const checkout = await getCheckout(checkoutId, apiKey);
console.log(JSON.stringify(checkout, null, 2));

// Get all checkouts
const checkouts = await getCheckouts(apiKey);
console.log(JSON.stringify(checkouts, null, 2));
16 changes: 16 additions & 0 deletions examples/commerce_get-checkouts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/commerce_get-checkouts",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase-platform/commerce": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/commerce_get-checkouts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/commerce_get-events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get events - Commerce

Run

```sh
$ bun run index.ts
```
13 changes: 13 additions & 0 deletions examples/commerce_get-events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getEvent, getEvents } from "@coinbase-platform/commerce";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

// Get an event by id
const eventId = "400ecd4e-9952-412b-9726-bdb173762b05";
const event = await getEvent(eventId, apiKey);
console.log(JSON.stringify(event, null, 2));

// Get all events
const events = await getEvents(apiKey);
console.log(JSON.stringify(events.data, null, 2));
16 changes: 16 additions & 0 deletions examples/commerce_get-events/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/commerce_get-events",
"private": true,
"module": "index.ts",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase-platform/commerce": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/commerce_get-events/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
Loading

0 comments on commit 695c983

Please sign in to comment.