node-coinbase-commerce
v0.3.3
Published
Node Coinbase Commerce API client
Downloads
42
Maintainers
Readme
Node.js Typescript Coinbase Commerce API
Node.js connector for the Coinbase Commerce API with Typescript.
- Simple and unopiniated connector.
- Actively maintained with a modern, promise-driven interface.
- Strongly typed on all requests and responses.
- Lightweight package and snappy DX.
- Proxy support via axios integration.
- Client samples, webhook samples and code snippet examples
Installation
npm install node-coinbase-commerce
Examples
Refer to the examples folder for implementation demos.
Usage
Create an API client
import { CoinbaseCommerceClient } from "node-coinbase-commerce";
export const client = new CoinbaseCommerceClient(API_KEY);
Charges
const charges = await client.listCharges();
const checkout = await client.createCharge({
name: "Product name",
description: "Product description",
pricing_type: "fixed_price",
local_price: {
amount: 100,
currency: "USDT", // BTC, ETH, USDT
},
metadata: {
customer_id: "Customer id",
customer_name: "Customer name",
},
redirect_url: "http://example.com/redirect_url",
cancel_url: "http://example.com/cancel_url",
});
const charge = await client.showCharge({
charge_code_or_charge_id: "XXX",
});
const charge = await client.cancelCharge({
charge_code_or_charge_id: "XXX",
});
const charge = await client.resolveCharge({
charge_code_or_charge_id: "XXX",
});
Checkouts
const checkouts = await client.listCheckouts();
const checkout = await client.createCheckout({
name: "Product name",
description: "Product description",
requested_info: ["name", "email", "address", "phone"],
pricing_type: "fixed_price",
local_price: {
amount: 100,
currency: "USDT", // BTC, ETH, USDT
},
});
const checkout = await client.showCheckout({
checkout_id: "XXX",
});
const checkout = await client.updateCheckout({
checkout_id: "XXX",
name: "Product name",
description: "Product description",
requested_info: ["name", "email", "address", "phone"],
pricing_type: "fixed_price",
local_price: {
amount: 100,
currency: "USDT", // BTC, ETH, USDT
},
});
await client.deleteCheckout({
checkout_id: "XXX",
});
Invoices
const invoices = await client.listInvoices();
const invoice = await client.createInvoice({
business_name: "XXX",
customer_email: "[email protected]", // has to be email
customer_name: "XXX",
memo: "XXX",
local_price: {
amount: 100,
currency: "USDT", // BTC, ETH, USDT
};
})
const invoice = await client.showInvoice({
invoice_code_or_invoice_id: "XXX",
});
const invoice = await client.voidInvoice({
invoice_code_or_invoice_id: "XXX",
});
const invoice = await client.resolveInvoice({
invoice_code_or_invoice_id: "XXX",
});
Events
const events = await client.listEvents();
const invoice = await client.showEvent({
event_id: "XXX", // uuidv4
});
Webhooks
Verify a webhook
const { isVerified, error, typedBody } = verifyWebhook(
req.body,
req.headers["x-cc-webhook-signature"],
WEBHOOK_SHARED_SECRET,
);