Receiving notifications
Notifications allow you to be informed when a transaction (also called a "charge") has changed status. This way, you will be able to identify when a charge is paid, for example.
When a transaction has a notification URL registered (attribute notification_url
), Gerencianet triggers a POST
to this URL every time the charge status changes. This notification has a specific token, which will be the same throughout the entire "change cycle" of the transaction. For example:
A charge has been generated. Your system receives a
POST
from Gerencianet containing the notification token09027955-5e06-4ff0-a9c7-46b47b8f1b27
and informing the transaction status - in this case,new
;That same charge had the payment method set, so its status changed to
waiting
and then we will send a new notification to your system containing the same token09027955-5e06-4ff0-a9c7-46b47b8f1b27
;Subsequently, this same charge had the payment confirmed, so the status changes to
paid
and again your system gets a notification, still with the same token09027955-5e06-4ff0-a9c7-46b47b8f1b27
.
A POST
will contain only one piece of information: a notification token. That is, if the registered URL is prepared to read the token in the variable $_POST['notification'] and consult this information, the answer will be all informational data about the change suffered by the charge, such as, for example, the previous and current status of the charge. To do so, you need to register a notification URL in the charge and prepare it to show/store the notification token.
For security, transaction information will only be sent when your system queries it using the received notification token.
Any time the integrator consults this notification token, it will obtain the most current charge information, all sorted according to events. Every change in status generates a notification.
On the tab Notification History
it is possible to track every notification POST
triggered by our system. If the integrator queries the sent token, we consider that the notification was successful. If not, try again.
To view the table containing all the status of a transaction, booklet or subscription, access this link in our documentation.
The rest of this page has the detailed procedures, but you need to install one of our libraries on your server to run the sample code. Make sure the Gerencianet SDK has been installed.
1. Setting the URL for receiving notifications
PTo proceed with the execution of the following codes, make sure that the Gerencianet SDK has been installed.
You will be able to define a URL that will receive notifications during the creation of the charge (createCharge
) or later (updateChargeMetadata
).
A transaction generated through the API may undergo several status changes depending on the interactions of the payer, the integrator or the operators and banking institutions involved. To keep up with these changes, it is necessary to prepare your system to receive notifications sent by Gerencianet.
When defining the parameters for creating the transaction, you can set a notification url. This URL will receive a token when a transaction has a status change. With this token, your application will be able to query our webservice to obtain the transaction status.
- Código: definir URL de notificação
Dica para testar as notificações (callbacks) facilmente com o WebhookInbox
To test notifications, we suggest using the WebhookInbox, which is a free service to inspect HTTP requests. You will be able to create a temporary URL to use it in the attribute notification_url
, in order to visualize, in an easy and friendly way, the POSTs made for your application. To generate the URL that will receive the request, access WebhookInbox and click Create An Inbox
.
WebhookInbox will record HTTP requests and allow you to inspect them to check Headers and Body of the requests. In this way, you will be able to start developing your integration with Gerencianet and test the Notification URL (callbacks) even if you don't already have a public URL available.
If you do not register a URL at the time of creating the transaction, you can do so through the metadata change method, through a PUT
request for the route /v1/charge/:id /metadata
.
You should note that the notification process is carried out in two steps to ensure the security of the reported data:
In the first one, your system is notified that there was a change related to a transaction (the webservice sends a
POST
with a token to you);In the second, your system queries - passing the token you received as a parameter to Gestoranet to know details about this change.
2. Consult notification details
Gerencianet considers that a notification was successful only after this consult. As long as your system does not consult the notification details, it will continue to be notified:
- PHP
- Python
- NodeJS
- .NET
- Java
- GO
- Ruby
- Delphi
2.1. Exemplos de respostas:
A seguir alguns exemplos de respostas de notificações para transações, assinaturas, carnês e link de pagamento:
- Transação
- Assinatura
- Carnê
- Link de Pagamento
List of all possible transaction, carnets and subscriptions statuses
All transactions, booklets and signatures have status, which represents their "situations". Therefore, it is important to know the possible statuses in the API to provide the proper handling in your system.
Check this link for all the details of the possible statuses.
Order of notifications (callbacks)
In short, the order of notifications is always the order of events.
For example: in the case of carnets, considering that installment 1 had its payment confirmed, then installment 2 and, finally, installment 3. In this situation, we will have an array of 3 positions where the first shows the installment confirmation 1, the second the confirmation of installment 2 and, the last one, the confirmation of installment 3.
To find out about the most recent situation of the parcel, you can scan the array and know (store) until which "event" was synchronized, as it may be that a notification brings 2 or 3 updates, for example, so you can't consider that the last position of the array is always the one that needs to be synchronized.
2.2. Explanation of response parameters:
The response to a notification will always be an array containing the changes that have occurred in a common transaction, subscription, carnets, subscription transaction or carnets transaction in the last 6 months.
Note that notifications related to subscription and booklet may also be accompanied by changes in your transactions (or installments).
2.3. Response tags:
Tag | Description |
---|---|
id | Order indicator, started on 1 . It is incremented for each change of a notification token. This is useful if you need to keep track of which change you have already processed. |
type | Determines the type of charge that was changed. Possible types are: charge // The change occurred in a transaction.subscription // The change occurred in a subscription. carnet // The change took place in a carnet.subscription_charge // The change occurred in a subscription installment.carnet_charge // The change occurred in a parcel of the carnet |
custom_id | Informs the charge identifier defined by the integrator, if any. |
status | Defines the current and previous status of the transaction, subscription or carnet. Status attributes: current previous Note: if there is no previous state (that is, for new charges), the previous value will be null |
identifiers | Identifiers representing the charge. The attributes of this tag may vary depending on the type of change (parameter type ). Identifiers that can be returned: charge_id // Returned when type = "charge" subscription_id // Returned when type = "subscription" . carnet_id // returned when type = "subscription" .charge_id and subscription_id // returned when type = "subscription_charge" .charge_id e carnet_id // returned when type = "carnet_charge" . |
value | Value accompanying the change. This tag will exist when the change is a payment confirmation, informing the amount paid that was confirmed. |
3. Notification queue status (callback)
Gerencianet notifies the integrated systems of each change in the status of a given charge through its associated notification URL.
Notifications are processed and always sent through a submission queue. It is also worth remembering that, if the callback is rejected by the destination system, it automatically returns to the queue and is rescheduled for a new delivery attempt. Callbacks are dynamic and can occur throughout the day.
Thinking about offering new ways of consulting the processing of this queue, Gestoret provides a screen that allows consulting the consumption status of the notifications queue (callbacks) processed until then. In this way, if the customer is in doubt as to whether a callback has already been sent or not, he can follow the daily processing of this queue.
To see the status and processing of the queue, see the link status of payment confirmations - Gerencianet.
4. Videos: Notifications
Thinking about offering new means of transmitting information, Gerencianet makes the following videos available in order to explain, in a clear and objective way, how to implement and configure your notification URL to receive callbacks.
4.1. Implementing Notifications - Callback or Auto Return (via Playground)
4.2. Configuring your notifications URL (Integration Gerencianet API)
5. IP addresses of Gerencianet for delivery of callbacks
Some applications and services may filter our communications through our IP addresses. Therefore, we recommend checking through the list of addresses used by the Gerencianet. Check it out in full in our FAQ.
6. Complementary Information: status of transactions, carnets and subscriptions
check out this link the table containing the possible status of a transaction, carnets and subscriptions in Gerencianet API.
7. Next steps
Now that you've implemented the Notification URL feature, you can check out more details this link on how to interpret scenarios pertaining to notifications (callbacks), such as in situations where a charge on your system has not been downloaded, the callback has been triggered to a URL you previously defined but which is no longer valid, etc.