Commandes
Gestion des commandes via @ziwako/client — CRUD, cycle de vie, articles, accès, paiements, commissions.
La ressource Commandes gère le cycle de vie complet d'un achat : création, cycle de vie
(processing → delivering → delivered → complete), articles (OrderItem), accès partagés,
paiements (lien de paiement, échéances), payouts et commissions.
- Factory :
getOrders()(@ziwako/client/axios) - Types :
Order,OrderResponse,OrderListResponse,OrderItemListResponse,OrderAccessListResponse,OrderPayoutBreakdownResponse,CreateOrderBody,UpdateOrderBody,SellerCreateOrderBody,AddItemBody,UpdateItemBody,SetOrderInstallmentsBody,SetOrderPayoutsBody,GenerateOrderPaymentLinkBody,GrantOrderAccessBody,UpdateOrderAccessBody,UpdateOrderCommissionModeBody,ReplaceOrderItemBody - Endpoints : 26 endpoints (voir la liste des fonctions ci-dessous)
import { configure, getOrders } from '@ziwako/client/axios';
configure({ accessToken: '...' });
const orders = getOrders();CRUD
createOrder
Crée une commande (côté client).
Signature : createOrder(createOrderBody?: CreateOrderBody) → Promise<OrderResponse>
const response = await orders.createOrder({
items: [{ productId: '64b8f2...', quantity: 2 }],
owner: profilId,
proProfilId: '64b8f2...',
});
console.log(response.data?.id);import { useCreateOrder } from '@ziwako/client/react-query';
const mutation = useCreateOrder();
mutation.mutate({ data: { owner: profilId, proProfilId: '64b8f2...' } });listOrders
Liste paginée des commandes (filtre par owner, proProfilId, statut...).
Signature : listOrders(params?: ListOrdersParams) → Promise<OrderListResponse>
const list = await orders.listOrders({ page: 1, limit: 20, filter: { owner: profilId } });
console.log(list.data?.docs);import { useListOrders } from '@ziwako/client/react-query';
const { data } = useListOrders({ filter: { owner: profilId } });getOrder
Récupère une commande par son id.
Signature : getOrder(id: string) → Promise<OrderResponse>
const response = await orders.getOrder('64b8f2...');
console.log(response.data?.status, response.data?.total);import { useGetOrder } from '@ziwako/client/react-query';
const { data } = useGetOrder(orderId, { query: { enabled: !!orderId } });updateOrder
Met à jour les informations d'une commande (adresse, note, ...).
Signature : updateOrder(id: string, updateOrderBody?: UpdateOrderBody) → Promise<OrderResponse>
await orders.updateOrder(orderId, { note: 'Livrer à partir de 18h' });import { useUpdateOrder } from '@ziwako/client/react-query';
const mutation = useUpdateOrder();
mutation.mutate({ id: orderId, data: { note: 'Livrer à partir de 18h' } });deleteOrder
Supprime une commande.
Signature : deleteOrder(id: string) → Promise<DeleteOrder200>
await orders.deleteOrder(orderId);import { useDeleteOrder } from '@ziwako/client/react-query';
const mutation = useDeleteOrder();
mutation.mutate({ id: orderId });Analytique & cycle de vie
getOrderAnalytic
Statistiques agrégées sur les commandes.
Signature : getOrderAnalytic() → Promise<GetOrderAnalytic200>
const analytics = await orders.getOrderAnalytic();
console.log(analytics.data);import { useGetOrderAnalytic } from '@ziwako/client/react-query';
const { data } = useGetOrderAnalytic();processOrder
Passe une commande à l'état « en cours de traitement ».
Signature : processOrder(id: string) → Promise<OrderResponse>
await orders.processOrder(orderId);import { useProcessOrder } from '@ziwako/client/react-query';
const mutation = useProcessOrder({
mutation: {
onSuccess: async () => {
toast.success('Commande validée');
await orderQuery.refetch();
},
},
});
mutation.mutate({ id: orderId });setDeliveringOrder
Passe la commande à l'état « en cours de livraison ».
Signature : setDeliveringOrder(id: string) → Promise<OrderResponse>
await orders.setDeliveringOrder(orderId);import { useSetDeliveringOrder } from '@ziwako/client/react-query';
const mutation = useSetDeliveringOrder();
mutation.mutate({ id: orderId });setDeliveredOrder
Marque la commande comme livrée.
Signature : setDeliveredOrder(id: string) → Promise<OrderResponse>
await orders.setDeliveredOrder(orderId);import { useSetDeliveredOrder } from '@ziwako/client/react-query';
const mutation = useSetDeliveredOrder();
mutation.mutate({ id: orderId });completeOrder
Clôture la commande (terminée).
Signature : completeOrder(id: string) → Promise<OrderResponse>
await orders.completeOrder(orderId);import { useCompleteOrder } from '@ziwako/client/react-query';
const mutation = useCompleteOrder();
mutation.mutate({ id: orderId });markAsPaid
Marque la commande comme payée.
Signature : markAsPaid(id: string) → Promise<OrderResponse>
await orders.markAsPaid(orderId);import { useMarkAsPaid } from '@ziwako/client/react-query';
const mutation = useMarkAsPaid();
mutation.mutate({ id: orderId });sellerCreateOrder
Le vendeur crée une commande pour un client (achat assisté).
Signature : sellerCreateOrder(sellerCreateOrderBody?: SellerCreateOrderBody) → Promise<OrderResponse>
await orders.sellerCreateOrder({
clientProfilId: '64b8f2...',
items: [{ productId: '64b8f2...', quantity: 1 }],
});import { useSellerCreateOrder } from '@ziwako/client/react-query';
const mutation = useSellerCreateOrder();
mutation.mutate({ data: { clientProfilId: '64b8f2...' } });Articles (OrderItem)
listOrderItems
Liste les articles d'une commande.
Signature : listOrderItems(id: string) → Promise<OrderItemListResponse>
const list = await orders.listOrderItems(orderId);
console.log(list.data?.docs);import { useListOrderItems } from '@ziwako/client/react-query';
const { data } = useListOrderItems(orderId);addItem
Ajoute un article à une commande.
Signature : addItem(id: string, addItemBody?: AddItemBody) → Promise<AddItem200>
await orders.addItem(orderId, { productId: '64b8f2...', quantity: 1 });import { useAddItem } from '@ziwako/client/react-query';
const mutation = useAddItem();
mutation.mutate({ id: orderId, data: { productId: '64b8f2...', quantity: 1 } });getItem
Récupère un article d'une commande.
Signature : getItem(id: string, itemId: string) → Promise<GetItem200>
const item = await orders.getItem(orderId, itemId);import { useGetItem } from '@ziwako/client/react-query';
const { data } = useGetItem(orderId, itemId);updateItem
Met à jour un article (quantité, prix, options...).
Signature : updateItem(id: string, itemId: string, updateItemBody?: UpdateItemBody) → Promise<UpdateItem200>
await orders.updateItem(orderId, itemId, { quantity: 3 });import { useUpdateItem } from '@ziwako/client/react-query';
const mutation = useUpdateItem();
mutation.mutate({ id: orderId, itemId, data: { quantity: 3 } });removeItem
Retire un article d'une commande.
Signature : removeItem(id: string, itemId: string) → Promise<RemoveItem200>
await orders.removeItem(orderId, itemId);import { useRemoveItem } from '@ziwako/client/react-query';
const mutation = useRemoveItem();
mutation.mutate({ id: orderId, itemId });replaceOrderItem
Remplace le produit d'un article de commande.
Signature : replaceOrderItem(id: string, itemId: string, replaceOrderItemBody?: ReplaceOrderItemBody) → Promise<OrderResponse>
await orders.replaceOrderItem(orderId, itemId, { productId: '64b8f2...' });import { useReplaceOrderItem } from '@ziwako/client/react-query';
const mutation = useReplaceOrderItem();
mutation.mutate({ id: orderId, itemId, data: { productId: '64b8f2...' } });Paiements & échéances
setOrderInstallments
Définit le plan d'échéances (paiement fractionné) d'une commande.
Signature : setOrderInstallments(id: string, setOrderInstallmentsBody?: SetOrderInstallmentsBody) → Promise<OrderResponse>
await orders.setOrderInstallments(orderId, { installments: 3 });import { useSetOrderInstallments } from '@ziwako/client/react-query';
const mutation = useSetOrderInstallments();
mutation.mutate({ id: orderId, data: { installments: 3 } });generateOrderPaymentLink
Génère un lien de paiement pour une commande (à envoyer au client).
Signature : generateOrderPaymentLink(id: string, generateOrderPaymentLinkBody?: GenerateOrderPaymentLinkBody) → Promise<GenerateOrderPaymentLink200>
const link = await orders.generateOrderPaymentLink(orderId, { returnUrl: 'https://ziwako.com/orders/confirm' });
console.log(link.data?.paymentUrl);import { useGenerateOrderPaymentLink } from '@ziwako/client/react-query';
const mutation = useGenerateOrderPaymentLink();
mutation.mutate({ id: orderId, data: { returnUrl: 'https://ziwako.com/orders/confirm' } });Accès partagés
getOrderAccesses
Liste les accès accordés sur une commande.
Signature : getOrderAccesses(id: string) → Promise<OrderAccessListResponse>
const list = await orders.getOrderAccesses(orderId);import { useGetOrderAccesses } from '@ziwako/client/react-query';
const { data } = useGetOrderAccesses(orderId);grantOrderAccess
Accorde un accès (ex. : un collaborateur) sur une commande.
Signature : grantOrderAccess(id: string, grantOrderAccessBody?: GrantOrderAccessBody) → Promise<OrderAccessListResponse>
await orders.grantOrderAccess(orderId, { profilId: '64b8f2...', role: 'manager' });import { useGrantOrderAccess } from '@ziwako/client/react-query';
const mutation = useGrantOrderAccess();
mutation.mutate({ id: orderId, data: { profilId: '64b8f2...', role: 'manager' } });updateOrderAccess
Met à jour un accès (rôle, permissions).
Signature : updateOrderAccess(id: string, accessId: string, updateOrderAccessBody?: UpdateOrderAccessBody) → Promise<OrderAccessListResponse>
await orders.updateOrderAccess(orderId, accessId, { role: 'viewer' });import { useUpdateOrderAccess } from '@ziwako/client/react-query';
const mutation = useUpdateOrderAccess();
mutation.mutate({ id: orderId, accessId, data: { role: 'viewer' } });revokeOrderAccess
Révoque un accès sur une commande.
Signature : revokeOrderAccess(id: string, accessId: string) → Promise<OrderAccessListResponse>
await orders.revokeOrderAccess(orderId, accessId);import { useRevokeOrderAccess } from '@ziwako/client/react-query';
const mutation = useRevokeOrderAccess();
mutation.mutate({ id: orderId, accessId });Payouts & commissions
setOrderPayouts
Configure les payouts (répartition du versement) d'une commande.
Signature : setOrderPayouts(id: string, setOrderPayoutsBody?: SetOrderPayoutsBody) → Promise<OrderResponse>
await orders.setOrderPayouts(orderId, { proProfilId: '64b8f2...', amount: 75000 });import { useSetOrderPayouts } from '@ziwako/client/react-query';
const mutation = useSetOrderPayouts();
mutation.mutate({ id: orderId, data: { proProfilId: '64b8f2...', amount: 75000 } });getOrderPayoutBreakdown
Récupère le détail des payouts d'une commande (montants, commissions).
Signature : getOrderPayoutBreakdown(id: string) → Promise<OrderPayoutBreakdownResponse>
const breakdown = await orders.getOrderPayoutBreakdown(orderId);
console.log(breakdown.data?.total, breakdown.data?.commission);import { useGetOrderPayoutBreakdown } from '@ziwako/client/react-query';
const { data } = useGetOrderPayoutBreakdown(orderId);updateOrderCommissionMode
Change le mode de commission d'une commande.
Signature : updateOrderCommissionMode(id: string, updateOrderCommissionModeBody?: UpdateOrderCommissionModeBody) → Promise<OrderResponse>
await orders.updateOrderCommissionMode(orderId, { mode: 'fixed' });import { useUpdateOrderCommissionMode } from '@ziwako/client/react-query';
const mutation = useUpdateOrderCommissionMode();
mutation.mutate({ id: orderId, data: { mode: 'fixed' } });