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 example inv_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.status and document.reported events. Refer to Set up your organization.
  • Your app stored the document_id of each accepted document. Refer to Submit a document.

Track a document: the four steps

StepAction
1Receive each webhook event, and check it.
2Find the document that the event is about.
3Update the status of the document in your app.
4Ask the API for documents that stay in progress.

Step 1: Receive each webhook event and check it

  1. Check the signature of the event with the signing secret of your webhook endpoint. Refer to Webhooks.
  2. Read the webhook-id header. Wafeq e-invoicing ASP can send the same event more than one time. If your app already processed this webhook-id, ignore the event.
  3. Store the event. Then answer with a 2xx status.

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_statustax_authority_statusMeaning
reporting—Wafeq e-invoicing ASP reported the document. The FTA did not answer yet.
reportedREPORTEDThe FTA accepted the report.
rejectedNOT_COMPLIANTThe FTA rejected the report.
withdrawnWITHDRAWNWafeq 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_statusIn progress or finalMeaning
queued, sending, retryingIn progressWafeq 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.
sentIn progressWafeq 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_apIn progressThe 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.
forwardedFinal: a successful deliveryThe 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_confirmedFinal: a successful deliveryThe 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).
rejectedFinalThe 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.
failedFinalThe delivery stopped, or the buyer's provider rejected the document with FD. Refer to Delivery errors.
attention_requiredFinalWafeq e-invoicing ASP stopped the delivery and does not try again. The error_code of the delivery tells why. Refer to Delivery errors.
not_applicableFinalWafeq 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} gives tdd_status, delivery_status and the history of the delivery.
  • GET /deliveries/{delivery_job_id} gives the progress of a queued delivery. The Location header of the 202 response 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:

FieldMeaning
discovery_attempt_countThe number of attempts to look up the buyer on Peppol.
attempt_countThe number of attempts to send the document to the access point of the buyer's provider.
max_attemptsThe maximum number of attempts, for each of the two counts.
retry_untilAfter this time, Wafeq e-invoicing ASP starts no new attempt.
attemptsEach 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 BV or SV. 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, BW only, an unknown reason, or FD together with BV or SV. Wafeq e-invoicing ASP withdraws a report that the FTA accepted, as for any other rejection, and reviews the case. reporting_recovery.trigger is c3_rejection_unclassified, and reporting_recovery.resolution is operator_review.
  • The buyer's provider never answered a queued delivery. The access point of the buyer's provider gave a receipt, so delivery_status stays received_by_ap. After the deadline for an answer, in c3_deadlines.mls_due_at, a document.status event can come with c3_deadlines.state: attention_required and reason_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 changes delivery_status. In the 7 days after the deadline, a late forward (AB) or confirmed delivery (AP) also changes c3_deadlines.state to response_received. A late rejection (RE) starts the recovery of the report, as any rejection does: c3_deadlines.state becomes recovery_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_status is failed or attention_required. Refer to The attempts of a queued delivery.
  • Wafeq e-invoicing ASP withdrew the report, for any cause. When reporting_recovery.state is withdrawn or original_rejected, your app can submit a correction with the same number, also after FD, an unclear reason or a missed deadline. After c3_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 new Idempotency-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 get reporting_recovery, contact support. Then submit a correction with corrects_document_id, when reporting_recovery.state is withdrawn or original_rejected.

Tracking in Sandbox

  • Wafeq e-invoicing ASP simulates the delivery. The document.status events of a simulated delivery contain simulated: 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_status changes from reporting to reported, and a real document.reported event comes, with test: false and data.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, BV or FD, no answer, a late confirmed delivery, a failed handover, or a rejection with no reason or with FD and BV together. Its L digit can also end a queued delivery attention_required, with retry_exhausted or invalid_receipt. After a rejection, a report that the FTA accepted ends withdrawn, 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 L 3 or 4; with R 8, the first correction fails again; with R 9, every correction is confirmed as received by the buyer (MLS AP). 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: true and changes no document.

Next

Stage 5: Correct or cancel a document.


Track a document