Track a document
Stage 4 of 6. After Wafeq e-invoicing ASP accepts a document, follow what happens to it. Then show the status of each document to your users.
This page uses these terms:
- Document: an invoice or a credit note that your app submitted, and that Wafeq e-invoicing ASP accepted.
- Document ID: the ID that Wafeq e-invoicing ASP gives a document when it accepts it (
document_id, for exampleinv_0123456789ABCDEFGHIJ). - Report: the copy of the document that Wafeq e-invoicing ASP sends to the FTA. The FTA calls it the tax data document (TDD). For this reason, the field for its status is
tdd_status. - Delivery: the transfer of the document to the buyer's e-invoicing provider, on Peppol.
- Webhook event: a message that Wafeq e-invoicing ASP sends to the webhook endpoint of your organization when something changes.
After Wafeq e-invoicing ASP accepts a document, two processes run. Each process has its own status:
- The report to the FTA. Wafeq e-invoicing ASP reports each accepted document to the FTA.
- The delivery to the buyer. Wafeq e-invoicing ASP delivers a document only when the buyer is on Peppol.
One process can succeed when the other fails. Thus your app must track both.
Before you start
- Your organization has a webhook endpoint with the
document.sent,document.statusanddocument.reportedevents. Refer to Set up your organization. - Your app stored the
document_idof each accepted document. Refer to Submit a document.
Track a document: the four steps
| Step | Action |
|---|---|
| 1 | Receive each webhook event, and check it. |
| 2 | Find the document that the event is about. |
| 3 | Update the status of the document in your app. |
| 4 | Ask the API for documents that stay in progress. |
Step 1: Receive each webhook event and check it
- Check the signature of the event with the signing secret of your webhook endpoint. Refer to Webhooks.
- Read the
webhook-idheader. Wafeq e-invoicing ASP can send the same event more than one time. If your app already processed thiswebhook-id, ignore the event. - Store the event. Then answer with a
2xxstatus.
Step 2: Find the document that the event is about
Use data.document_id to find the document. Some old document.status events do not contain data.document_id. For these events, use data.source_id. This is the value that your app sent in source_id.
The documents that your app sends in a batch get the same events. The events do not name the batch. GET /batches/{batch_id}/items gives the document_id of each accepted document of the batch. Refer to Send many documents at once.
Events can arrive in a different order than the changes. Use created_at to put the events of a document in the correct order.
Step 3: Update the status of the document in your app
The report to the FTA. The document.reported event gives the answer of the FTA in data.tax_authority_status. The API gives the same status in tdd_status:
tdd_status | tax_authority_status | Meaning |
|---|---|---|
reporting | — | Wafeq e-invoicing ASP reported the document. The FTA did not answer yet. |
reported | REPORTED | The FTA accepted the report. |
rejected | NOT_COMPLIANT | The FTA rejected the report. |
withdrawn | WITHDRAWN | Wafeq e-invoicing ASP withdrew the report, because the buyer's provider rejected the document, or because a queued delivery missed its deadline. reporting_recovery.trigger tells why. Refer to Correct or cancel a document. |
unresolved | — | The report has a problem that Wafeq e-invoicing ASP did not solve automatically. |
not_reported | — | Wafeq e-invoicing ASP did not report the document. |
The delivery to the buyer. The document.sent and document.status events give the status in data.delivery_status. The API gives the same status in delivery_status. Each status is in progress or final:
delivery_status | In progress or final | Meaning |
|---|---|---|
queued, sending, retrying | In progress | Wafeq e-invoicing ASP sends a queued document. retrying: an attempt did not succeed, and Wafeq e-invoicing ASP tries again. Refer to The attempts of a queued delivery. |
sent | In progress | Wafeq e-invoicing ASP sent the document. It has no receipt from the access point of the buyer's provider yet. In Sandbox, a simulated delivery has this status until the simulated provider answers. A delivery to an active Sandbox taxpayer has it for up to 2 minutes, while Wafeq e-invoicing ASP waits for the app of the buyer's organization to fetch the document. |
received_by_ap | In progress | The access point of the buyer's provider gave a receipt for the document. The buyer's provider did not answer yet. If it never answers, the status stays received_by_ap. Refer to After a problem. |
forwarded | Final: a successful delivery | The buyer's provider forwarded the document to the buyer (MLS AB). The provider has no way to verify that the document arrived. When the buyer is on Wafeq e-invoicing ASP, the app of the buyer did not fetch the document within 2 minutes. Refer to Receive a document. |
delivered_confirmed | Final: a successful delivery | The buyer's provider has a verifiable confirmation that the document arrived on the side of the buyer (MLS AP). When the buyer is on Wafeq e-invoicing ASP, the app of the buyer fetched the document. In Sandbox, a delivery to an active Sandbox taxpayer also ends with this status, or with forwarded, with no MLS answer (response_code: null). |
rejected | Final | The buyer's provider did not deliver the document (MLS RE). The reason is in delivery_reason_code on the document, and in data.reason_code in the event. The event also has every reason in data.reason_codes, and the text of the provider in data.detail. |
failed | Final | The delivery stopped, or the buyer's provider rejected the document with FD. Refer to Delivery errors. |
attention_required | Final | Wafeq e-invoicing ASP stopped the delivery and does not try again. The error_code of the delivery tells why. Refer to Delivery errors. |
not_applicable | Final | Wafeq e-invoicing ASP reported the document to the FTA only. There is no delivery. |
forwarded and delivered_confirmed are both a successful delivery. Neither status tells you that the buyer approved the invoice. The buyer's provider answers each document one time only. Thus forwarded never changes to delivered_confirmed. Show forwarded as delivered to the buyer's provider, and delivered_confirmed as delivered to the buyer. Do not show forwarded as pending, and do not wait for another answer.
A late answer. The buyer's provider can answer a document after its delivery stopped with attention_required. Before the recovery of the report starts, the answer changes delivery_status. After it starts, Wafeq e-invoicing ASP keeps delivery_status, and it records the answer as a conflict on the report. Refer to Correct or cancel a document.
When the buyer's provider rejects a document, the reason has one of these values:
BV: the document breaks a business rule.SV: the format of the document is not correct.FD: the provider could not deliver the document.
A rejection can also come with no reason, or with more than one. data.reason_codes in the event gives all of them.
After a rejection, or after a queued delivery missed its deadline, the document has reporting_recovery, and its events have data.reporting_recovery. Its trigger tells why Wafeq e-invoicing ASP handles the report, and it does not change. For the values, refer to document.status in Webhooks.
Step 4: Ask the API for documents that stay in progress
Webhook events can be late. If a status stays in progress for a long time, ask the API for the current status:
GET /invoices/{document_id}givestdd_status,delivery_statusand the history of the delivery.GET /deliveries/{delivery_job_id}gives the progress of a queued delivery. TheLocationheader of the202response points to this URL.
The attempts of a queued delivery
Wafeq e-invoicing ASP can try a queued delivery more than one time, within a few minutes after it accepts the document. GET /deliveries/{delivery_job_id} shows the attempts:
| Field | Meaning |
|---|---|
discovery_attempt_count | The number of attempts to look up the buyer on Peppol. |
attempt_count | The number of attempts to send the document to the access point of the buyer's provider. |
max_attempts | The maximum number of attempts, for each of the two counts. |
retry_until | After this time, Wafeq e-invoicing ASP starts no new attempt. |
attempts | Each attempt, oldest first, with its phase, outcome, error_code and http_status. |
When the access point gives no receipt. If reporting_recovery.trigger of the document is c3_transport_overdue, the time in c3_deadlines.transport_due_at of the delivery passed, and Wafeq e-invoicing ASP had no verified receipt from the access point of the buyer's provider. Follow reporting_recovery.state. When it is withdrawn or original_rejected, submit a correction. First read A first delivery with an uncertain result.
After a problem
These items are not steps. They tell you what each problem means and who acts.
- The buyer's provider rejected the document with
BVorSV. Wafeq e-invoicing ASP withdraws the report. Your app must submit a corrected document. Refer to Correct or cancel a document. - The buyer's provider rejected the document, and the reason is not clear: no reason,
BWonly, an unknown reason, orFDtogether withBVorSV. Wafeq e-invoicing ASP withdraws a report that the FTA accepted, as for any other rejection, and reviews the case.reporting_recovery.triggerisc3_rejection_unclassified, andreporting_recovery.resolutionisoperator_review. - The buyer's provider never answered a queued delivery. The access point of the buyer's provider gave a receipt, so
delivery_statusstaysreceived_by_ap. After the deadline for an answer, inc3_deadlines.mls_due_at, adocument.statusevent can come withc3_deadlines.state: attention_requiredandreason_code: c3_mls_overdue. Wafeq e-invoicing ASP does not withdraw the report, and it reviews the case. A late answer of the provider still changesdelivery_status. In the 7 days after the deadline, a late forward (AB) or confirmed delivery (AP) also changesc3_deadlines.statetoresponse_received. A late rejection (RE) starts the recovery of the report, as any rejection does:c3_deadlines.statebecomesrecovery_started. Show the document as sent to the buyer's provider, with no answer from the provider. Do not submit the document again. - The attempts of a queued delivery ended, and the access point of the buyer's provider gave no receipt.
delivery_statusisfailedorattention_required. Refer to The attempts of a queued delivery. - Wafeq e-invoicing ASP withdrew the report, for any cause. When
reporting_recovery.stateiswithdrawnororiginal_rejected, your app can submit a correction with the same number, also afterFD, an unclear reason or a missed deadline. Afterc3_transport_overdue, first read A first delivery with an uncertain result. - The delivery failed, with a
document_id. Wafeq e-invoicing ASP accepted the document, and it reports the document to the FTA. Do not submit it again as a new document, with a newIdempotency-Key: its report stays with the FTA. To send a queued document again, wait until Wafeq e-invoicing ASP withdraws its report. If the document does not getreporting_recovery, contact support. Then submit a correction withcorrects_document_id, whenreporting_recovery.stateiswithdrawnororiginal_rejected.
Tracking in Sandbox
- Wafeq e-invoicing ASP simulates the delivery. The
document.statusevents of a simulated delivery containsimulated: true. - Wafeq e-invoicing ASP does not send reports to the FTA. Sandbox accepts each report approximately 5 seconds after Wafeq e-invoicing ASP accepts the document:
tdd_statuschanges fromreportingtoreported, and a realdocument.reportedevent comes, withtest: falseanddata.simulated: true. - To test how your app processes the other answers of the FTA, send the document to a test buyer. A test buyer gives a rejection, a rejection and then a corrected report, no answer, or a late answer. Refer to Test buyers.
- To test the answers of the buyer's provider, send the document to a test buyer on Peppol. Its D digit gives a forward, a confirmed delivery, a rejection with
SV,BVorFD, no answer, a late confirmed delivery, a failed handover, or a rejection with no reason or withFDandBVtogether. Its L digit can also end a queued deliveryattention_required, withretry_exhaustedorinvalid_receipt. After a rejection, a report that the FTA accepted endswithdrawn, as in Live. Refer to Test buyers. - After a withdrawal in Sandbox, your app can send a correction, as in Live. A test buyer forwards it (MLS
AB), whatever its D digit, also with L3or4; with R8, the first correction fails again; with R9, every correction is confirmed as received by the buyer (MLSAP). Refer to Test buyers. - You can also send a test event from Developer → Webhooks in the Wafeq e-invoicing ASP portal. A test event contains
test: trueand changes no document.
Next
Stage 5: Correct or cancel a document.
Updated 5 days ago