vondera_sdk 1.0.1
vondera_sdk: ^1.0.1 copied to clipboard
A Flutter SDK for interacting with the Vondera REST APIs. Provides a clean, type-safe interface for all Vondera public API endpoints.
example/example.dart
import 'package:vondera_sdk/vondera_sdk.dart';
void main() async {
// Initialize the SDK
final vondera = VonderaSDK(
baseUrl:
'https://us-central1-brands-61c3d.cloudfunctions.net/app-api/api/public',
apiKey: 'YOUR_API_KEY',
userId: 'unique-user-id', // Optional: for cart tracking
);
try {
// Example: Get store information
final store = await vondera.stores.getStore();
print('Store: ${store.name}');
// Example: Get products
final products = await vondera.products.getProducts(
pageNo: 1,
limit: 10,
);
print('Products: ${products.items.length}');
// Example: Get categories
final categories = await vondera.categories.getCategories();
print('Categories: ${categories.length}');
// Example: Customer login
// final authResponse = await vondera.customers.login(
// email: 'user@example.com',
// password: 'password123',
// );
// print('Token: ${authResponse.token}');
// Example: Add to cart
// await vondera.cart.addToCart(
// ProductItem(
// productId: 'product-id',
// quantity: 1,
// variantId: 'variant-id', // Optional
// options: {'Color': 'Red'}, // Optional
// ),
// );
// Example: Get cart
// final cart = await vondera.cart.getCart();
// print('Cart items: ${cart.items.length}');
// print('Total price: ${cart.totalPrice} ${cart.currency}');
// print('Total quantity: ${cart.totalQuantity}');
// print('Products count: ${cart.productsCount}');
// Example: Calculate order price
// final priceRequest = OrderPriceRequest(
// phone: '01114077125',
// city: 'القاهرة',
// discountCode: '', // or provide a discount code
// products: [
// OrderPriceRequestItem(
// id: '2032',
// quantity: 5,
// variantId: 'ae15e7199365ea445650af812485c712899cf223fa302d8acd4f732d3686c79e',
// ),
// ],
// );
// final price = await vondera.orders.calculateOrderPrice(priceRequest);
// print('Items Price: ${price.itemsPrice}');
// print('Shipping Fees: ${price.shippingFees}');
// print('Discount: ${price.discount}');
// print('Total Price: ${price.totalPrice}');
// print('Auto Apply Promo: ${price.autoApplyPromo}');
// Example: Create order
// final orderRequest = OrderRequest(
// name: 'Shreif El Sayed',
// phone: '01114077125',
// countryCode: '+20',
// email: 'armjldtrainer@gmail.com',
// address: '69 El Dokki St.',
// city: 'القاهرة',
// country: 'EG',
// notes: 'Notes on order', // Optional, defaults to empty string
// paymentMethod: PaymentMethod.gateway, // PaymentMethod.cash, PaymentMethod.gateway, or PaymentMethod.deposit
// discountCode: '', // or provide a discount code
// products: [
// OrderRequestItem(
// id: '0300',
// quantity: 1,
// variantId: '699c8f3ad1cb9370a24a91af4bf641daa622011e52bdb458ebbbd525204f0ff6',
// ),
// ],
// );
// final order = await vondera.orders.createOrder(orderRequest);
// print('Order created: ${order.id}');
} on UnauthorizedException catch (e) {
print('Unauthorized: ${e.message}');
} on ValidationException catch (e) {
print('Validation error: ${e.message}');
} on NetworkException catch (e) {
print('Network error: ${e.message}');
} on ApiException catch (e) {
print('API error: ${e.message}');
}
}