@astra-pay/sdk
v1.1.0
Published
Official TypeScript SDK for the AstraPay crypto payment API
Maintainers
Readme
@astra-pay/sdk
Official TypeScript SDK for the AstraPay crypto payment API.
Installation
npm install @astra-pay/sdk
# or
yarn add @astra-pay/sdkQuick Start
import { AstraPayClient } from "@astra-pay/sdk";
const client = new AstraPayClient("ap_live_...");
// Create a payment
const payment = await client.payments.create({
amount: 25,
token: "USDC",
network: "BASE",
});
console.log(payment.checkout_url);
// List payments
const { data, meta } = await client.payments.list({ status: "PENDING" });
// Create a product
const product = await client.products.create({
name: "Pro Plan",
price: 49,
currency_type: "FIAT",
});
// Register a webhook
const webhook = await client.webhooks.create({
url: "https://example.com/webhook",
events: ["payment.completed"],
});
console.log(webhook.secret); // Store this securelyAPI Reference
new AstraPayClient(apiKey, options?)
| Option | Default | Description |
| --------- | --------------------------- | --------------- |
| baseUrl | https://apipay.byastra.ai | API base URL |
| prefix | /v1 | API path prefix |
Payments
| Method | Description |
| -------------------------------- | ------------------------ |
| client.payments.create(params) | Create a payment |
| client.payments.get(id) | Get payment by ID |
| client.payments.list(params?) | List payments |
| client.payments.cancel(id) | Cancel a pending payment |
Products
| Method | Description |
| ------------------------------------ | ----------------- |
| client.products.create(params) | Create a product |
| client.products.get(id) | Get product by ID |
| client.products.list() | List all products |
| client.products.update(id, params) | Update a product |
| client.products.delete(id) | Delete a product |
Webhooks
| Method | Description |
| ------------------------------------ | ----------------- |
| client.webhooks.create(params) | Create a webhook |
| client.webhooks.get(id) | Get webhook by ID |
| client.webhooks.list() | List all webhooks |
| client.webhooks.update(id, params) | Update a webhook |
| client.webhooks.delete(id) | Delete a webhook |
Error Handling
import { AstraPayClient, AstraPayError } from "@astra-pay/sdk";
try {
await client.payments.get("invalid-id");
} catch (err) {
if (err instanceof AstraPayError) {
console.log(err.status); // 404
console.log(err.code); // "NOT_FOUND"
console.log(err.message); // "Payment not found"
}
}Requirements
- Node.js >= 18.0.0 (uses native
fetch) - Zero runtime dependencies
License
MIT
