corgi-sdk
v0.0.6
Published
Corgi Labs SDK
Readme
corgi-sdk
Official Corgi Labs SDK for merchants to finalize Stripe Payment Element payments through Corgi’s API.
Install
npm install corgi-sdkQuick start
import { CorgiSDK } from 'corgi-sdk';
// Create one on Corgi web app settings page
const sdk = new CorgiSDK({
token: process.env.CORGI_API_TOKEN!,
});Confirm a Payment
const result = await sdk.confirmPayment('ctoken_123', {
amount: 5000,
currency: 'usd',
metadata: {
order_id: 'order_123',
},
});
console.log(result.status);Error handling
API errors throw CorgiSDKError.
import { CorgiSDKError } from 'corgi-sdk';
try {
await sdk.confirmPayment('ctoken_123', {
amount: 5000,
currency: 'usd',
});
} catch (error) {
if (error instanceof CorgiSDKError) {
console.error(error.status, error.code, error.message);
if (error.code === 'CONFIRMATION_TOKEN_ALREADY_USED') {
// The token was spent by an earlier call; this is the PaymentIntent it paid.
console.error(error.paymentIntentId);
}
}
throw error;
}Manage lists
Create lists and manage their items. Lists are referenced by rules through their alias; existing lists cannot be renamed or deleted via the API.
const list = await sdk.lists.create({
alias: 'vip_customers',
name: 'VIP customers',
itemType: 'email',
});
// `listId` accepts either the list id or its alias.
await sdk.lists.addItems('vip_customers', ['[email protected]', '[email protected]']);
await sdk.lists.removeItems('vip_customers', ['[email protected]']);Listing is cursor-paginated (limit ≤ 100 for lists, ≤ 500 for items):
let cursor: string | undefined;
do {
const page = await sdk.lists.listItems('vip_customers', {
limit: 500,
startingAfter: cursor,
});
console.log(page.data.map((item) => item.value));
cursor = page.nextCursor ?? undefined;
} while (cursor);