Owostack
SDK Reference

addon()

Purchase add-on credit packs

addon()

Purchase a credit pack to top up a customer's prepaid balance. If the customer has a card on file, the charge happens immediately. Otherwise, a checkout URL is returned.

Signature

await owo.addon({
  customer: string,
  pack: string,
  quantity?: number,
}): Promise<AddonResult>

Parameters

ParameterTypeRequiredDescription
customerstringYesYour internal user ID
packstringYesCredit pack slug or ID
quantitynumberNoNumber of packs to buy (default: 1)

Response

interface AddonResult {
  success: boolean;
  requiresCheckout: boolean;
  checkoutUrl?: string;
  balance?: number;
  creditsAdded?: number;
  error?: string;
}

Examples

Basic purchase

const result = await owo.addon({
  customer: "user_123",
  pack: "500-credits",
});

if (result.requiresCheckout) {
  console.log("Redirect to:", result.checkoutUrl);
} else {
  console.log("Credits added:", result.creditsAdded);
  console.log("New balance:", result.balance);
}

Buy multiple packs

const result = await owo.addon({
  customer: "user_123",
  pack: "500-credits",
  quantity: 3, // 1500 credits
});

Notes

  • Credit packs must be tied to a credit system. Packs without a credit system are rejected.
  • If the customer has a valid payment method on file, requiresCheckout is false and credits are added immediately.
  • The provider used for checkout is determined by the credit pack's providerId.

On this page