Ziwako Docs
ZiwakoGuide développeurSDK @ziwako/client

Contrats de paiement

Contrats récurrents via @ziwako/client — CRUD, cycle de vie, workers et paiements de cycle.

La ressource PaymentContracts gère les contrats de paiement récurrents (abonnement de service, versements échelonnés programmés) : création, cycle de vie (acceptation, suspension, reprise, terminaison), remplacement de worker et paiements de cycle.

  • Factory : getPaymentContracts() (@ziwako/client/axios)
  • Types : PaymentContract, PaymentContractResponse, PaymentContractListResponse, ContractPaymentListResponse, CreatePaymentContractBody, UpdatePaymentContractBody, ReplaceContractWorkerBody, GenerateContractPaymentLinkBody, ListPaymentContractsParams, ListContractPaymentsParams
  • Endpoints : POST /payment-contracts, GET /payment-contracts, GET /payment-contracts/{id}, PUT /payment-contracts/{id}, POST /payment-contracts/{id}/accept, /suspend, /resume, /terminate, POST /payment-contracts/{id}/worker, GET /payment-contracts/{id}/cycles, POST /payment-contracts/{id}/cycles/{cycleId}/payment-link
import { configure, getPaymentContracts } from '@ziwako/client/axios';
configure({ accessToken: '...' });
const contracts = getPaymentContracts();

CRUD

createPaymentContract

Crée un contrat de paiement récurrent.

Signature : createPaymentContract(createPaymentContractBody?: CreatePaymentContractBody) → Promise<PaymentContractResponse>

const response = await contracts.createPaymentContract({
    title: 'Maintenance mensuelle',
    amount: 50000,
    frequency: 'monthly',
    owner: profilId,
    workerProfilId: '64b8f2...',
});
console.log(response.data?.id);
import { useCreatePaymentContract } from '@ziwako/client/react-query';

const mutation = useCreatePaymentContract();
mutation.mutate({ data: { title: 'Maintenance mensuelle', amount: 50000, frequency: 'monthly', owner: profilId } });

listPaymentContracts

Liste paginée des contrats récurrents.

Signature : listPaymentContracts(params?: ListPaymentContractsParams) → Promise<PaymentContractListResponse>

const list = await contracts.listPaymentContracts({ page: 1, limit: 20, filter: { owner: profilId } });
import { useListPaymentContracts } from '@ziwako/client/react-query';

const { data } = useListPaymentContracts({ page: 1, limit: 20 });

getPaymentContract

Récupère un contrat par son id.

Signature : getPaymentContract(id: string) → Promise<PaymentContractResponse>

const response = await contracts.getPaymentContract('64b8f2...');
console.log(response.data?.status);
import { useGetPaymentContract } from '@ziwako/client/react-query';

const { data } = useGetPaymentContract(contractId);

updatePaymentContract

Met à jour un contrat (montant, fréquence, description...).

Signature : updatePaymentContract(id: string, updatePaymentContractBody?: UpdatePaymentContractBody) → Promise<PaymentContractResponse>

await contracts.updatePaymentContract(contractId, { amount: 60000 });
import { useUpdatePaymentContract } from '@ziwako/client/react-query';

const mutation = useUpdatePaymentContract();
mutation.mutate({ id: contractId, data: { amount: 60000 } });

Cycle de vie

acceptPaymentContract

Accepte le contrat (le prestataire accepte les termes).

Signature : acceptPaymentContract(id: string) → Promise<PaymentContractResponse>

await contracts.acceptPaymentContract(contractId);
import { useAcceptPaymentContract } from '@ziwako/client/react-query';

const mutation = useAcceptPaymentContract();
mutation.mutate({ id: contractId });

suspendPaymentContract

Suspend temporairement le contrat.

Signature : suspendPaymentContract(id: string) → Promise<PaymentContractResponse>

await contracts.suspendPaymentContract(contractId);
import { useSuspendPaymentContract } from '@ziwako/client/react-query';

const mutation = useSuspendPaymentContract();
mutation.mutate({ id: contractId });

resumePaymentContract

Reprend un contrat suspendu.

Signature : resumePaymentContract(id: string) → Promise<PaymentContractResponse>

await contracts.resumePaymentContract(contractId);
import { useResumePaymentContract } from '@ziwako/client/react-query';

const mutation = useResumePaymentContract();
mutation.mutate({ id: contractId });

terminatePaymentContract

Met fin au contrat définitivement.

Signature : terminatePaymentContract(id: string) → Promise<PaymentContractResponse>

await contracts.terminatePaymentContract(contractId);
import { useTerminatePaymentContract } from '@ziwako/client/react-query';

const mutation = useTerminatePaymentContract();
mutation.mutate({ id: contractId });

Worker & cycles

replaceContractWorker

Remplace le prestataire (worker) associé au contrat.

Signature : replaceContractWorker(id: string, replaceContractWorkerBody?: ReplaceContractWorkerBody) → Promise<PaymentContractResponse>

await contracts.replaceContractWorker(contractId, { workerProfilId: '64b8f3...' });
import { useReplaceContractWorker } from '@ziwako/client/react-query';

const mutation = useReplaceContractWorker();
mutation.mutate({ id: contractId, data: { workerProfilId: '64b8f3...' } });

listContractPayments

Liste les paiements de cycle d'un contrat.

Signature : listContractPayments(id: string, params?: ListContractPaymentsParams) → Promise<ContractPaymentListResponse>

const list = await contracts.listContractPayments(contractId, { page: 1, limit: 20 });
console.log(list.data?.docs);
import { useListContractPayments } from '@ziwako/client/react-query';

const { data } = useListContractPayments(contractId);

Génère un lien de paiement pour un cycle précis du contrat.

Signature : generateContractPaymentLink(id: string, cycleId: string, generateContractPaymentLinkBody?: GenerateContractPaymentLinkBody) → Promise<GenerateContractPaymentLink200>

const link = await contracts.generateContractPaymentLink(contractId, cycleId, {
    returnUrl: 'https://ziwako.com/contrats/paiement',
});
console.log(link.data?.paymentUrl);
import { useGenerateContractPaymentLink } from '@ziwako/client/react-query';

const mutation = useGenerateContractPaymentLink();
mutation.mutate({ id: contractId, cycleId, data: { returnUrl: 'https://ziwako.com/contrats/paiement' } });