Product Management

The productManager provides methods to create and manage products in the Galliun Payment Protocol.

Creating Products

const { resp, productObjChange } = await client.productManager.createProduct(
	coinType, // e.g., "0x2::sui::SUI"
	name, // Product name
	description, // Product description
	price, // Price in smallest unit
	quantity, // Initial quantity
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);

Response

interface ProductResponse {
	resp: SuiTransactionBlockResponse;
	productObjChange: {
		id: string;
		type: string;
		// ... other product properties
	};
}

Managing Products

Buy Product

const resp = await client.productManager.buyProduct(
	coinType, // Token type to pay with
	productId, // ID of the product to buy
	price, // Price to pay
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);

Update Product Info

const resp = await client.productManager.updateProductInfo(
	coinType, // Token type
	productId, // ID of the product to update
	name, // New name
	description, // New description
	price, // New price
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);

Manage Quantity

Increase Quantity

const resp = await client.productManager.increaseQuantity(
	productId, // ID of the product
	amount, // Amount to increase
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);

Decrease Quantity

const resp = await client.productManager.decreaseQuantity(
	productId, // ID of the product
	amount, // Amount to decrease
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);

Fetching Products

Fetch Single Product

const product = await client.productManager.fetchProduct(productId);

Fetch Multiple Products

const products = await client.productManager.fetchProducts([productId1, productId2]);

Product Object

The SDK returns products in this format:

interface ProductObj {
	id: string;
	name: string;
	description: string;
	price: bigint;
	coin_type: string;
	creator: string;
	creation_time: number;
	quantity: bigint;
	sold: bigint;
	is_available: boolean;
}

Error Handling

Handle specific product management errors:

try {
	await client.productManager.buyProduct(/* ... */);
} catch (error) {
	switch (error.code) {
		case 'UNSUPPORTED_COIN':
			// Handle unsupported coin type
			break;
		case 'INSUFFICIENT_BALANCE':
			// Handle insufficient balance
			break;
		case 'OUT_OF_STOCK':
			// Handle out of stock
			break;
		case 'PERMISSION_DENIED':
			// Handle permission issues
			break;
		default:
		// Handle other errors
	}
}

Common Use Cases

  1. Create and Track Product:

// Create product
const { productObjChange } = await client.productManager.createProduct(/* ... */);
const productId = productObjChange.id;

// Monitor inventory
const product = await client.productManager.fetchProduct(productId);
console.log('Available:', product.quantity - product.sold);
  1. Update Product with Price Change:

await client.productManager.updateProductInfo(
	coinType,
	productId,
	product.name, // Keep existing name
	product.description, // Keep existing description
	newPrice, // Update price only
);

Last updated