Every order: charged, invoiced, shipped, notified.
The agent takes each order from your stream and makes four calls: a Pix charge with codespar_charge, the NF-e with codespar_invoice, the shipping label with codespar_ship and a WhatsApp text with codespar_notify. Each goes to the provider your project connected. NFe.io and Z-API have no test environment: a test key is refused there, and in a live project the NF-e is issued for real and the message is really sent.
One order, four calls.
An example with demo data: the agent charges order #4821 by Pix, issues the NF-e, buys the label and sends the buyer a WhatsApp text. The NF-e and the WhatsApp text only run in a live project.
- The Pix charge goes to the provider the project connected
- NF-e through NFe.io: live projects only, no test environment
- WhatsApp through Z-API: a text, queued; live projects only
The conversation is the easy part.
Fulfillment lives in tools that do not talk to each other: charge here, invoice there, ship somewhere else, notify by hand.
Charge in one tool, invoice in another
The agent charges and invoices with two meta tools
Buy the label in a third tab
codespar_ship quotes and buys the label at Melhor Envio
Notify the buyer by hand
codespar_notify sends a WhatsApp text through Z-API
Track the parcel on the carrier's site
codespar_ship with action=track reads the tracking
Fulfillment as four calls.
The agent reads each order from your stream and calls codespar_charge (Pix), codespar_invoice (NF-e), codespar_ship (label) and codespar_notify (WhatsApp). Each call goes to the provider the project connected. The NF-e and the WhatsApp text run only in a live project, where they are real; the fiscal setup lives on the NFe.io company the connection points to. Writing the order back to your ERP is your integration.
Read from your stream
codespar_chargePix charge
Connected providercodespar_invoiceNF-e · live projects only
NFe.iocodespar_shipLabel
Melhor Enviocodespar_notifyWhatsApp text · live projects only
Z-APIYour order stream hands the agent each paid-for order. codespar_charge mints the Pix charge on the connected provider (Asaas, Mercado Pago, EBANX, Celcoin, Iugu or Stone). codespar_invoice issues the NF-e through NFe.io for the company the connection points to. codespar_ship quotes, buys and tracks the label at Melhor Envio. codespar_notify sends a WhatsApp text through Z-API, which answers that the message is queued. Writing the result back to your ERP is your integration.
The code, and what it assumes.
// Prerequisites: CODESPAR_API_KEY set to a test key (csk_test_…), a Pix // provider (Asaas, for instance) and Melhor Envio connected to the project. // NFe.io and Z-API have no test environment: codespar_invoice (NF-e) and // codespar_notify (WhatsApp) need a live key, and then issue and send for real. import { CodeSpar } from "@codespar/sdk"; const session = await new CodeSpar().create("user_0000", { preset: "brazilian" }); const buyer = { name: "Ana Souza", email: "ana@example.com", document: "12345678909", phone: "+5511999990000" }; // 1 · charge the order by Pix (amount in reais) const charge = await session.charge({ amount: 219.8, currency: "BRL", method: "pix", description: "Order #4821", buyer }); console.log(charge.status, charge.pix_copy_paste); // 2 · buy the shipping label at Melhor Envio const label = await session.ship({ action: "label", origin: { postal_code: "01310-100" }, destination: { postal_code: "20040-002" }, items: [{ description: "Order #4821", weight_g: 800, width_cm: 15, height_cm: 10, length_cm: 20 }], }); console.log(label.status, label.tracking_code);
Example with the published SDK (@codespar/sdk 0.16.11). Its prerequisites are in the comments. Compiling does not prove the integration: run it in test mode first.
codespar_chargeMints a Pix charge on the provider the project connected.
codespar_invoiceIssues the NF-e through NFe.io; live projects only.
codespar_shipQuotes, buys and tracks the shipping label at Melhor Envio.
codespar_notifySends a WhatsApp text through Z-API; live projects only.
Start with a test key.
Test keys are free. Open the sandbox, connect the providers your project uses and see which tools it can call before you build.