Custom payment buttons offer the ability to send notifications when a successful payment is made, this is achieved by configuring a hook.
Activate a Hook for a Payment Button
Activating a Hook takes only 2 steps:
- Define the default API key that will be used for signing each Hook request and will secure the information been shared
- Setup a URL to the one we will send out the notifications.
To use the Hook you must first create a Dynamic Payment Button: View tutorial
1. Define the API Key credentials for Hooks
To define the credentials head over to Settings > API Credentials
In the example above we can see a dropdown list of the options from where we will choose the credential that we will use as default for hooks.
2. Setup your systems URL
The second step is to setup the path to which requests will be made each time successful payments are received on a custom payment button. Some considerations to keep in mind:
1. It must be a public path (accessible from the Internet).
2. You must have a valid security certificate (path must use HTTPS).
To configure the URL, simply go into the settings of the payment button(s) in which you want to activate the Hook, click on edit and then on "Advanced Options".
Once in the Advanced Options you will find a field called "Hook URL" where you can place the route.
When a Hook is activated, Fygaro will send a “POST” type request to the configured URL each time a successful payment is processed on the respective payment button. The request will have a JSON content type with the following structure::
The customReference contains the dynamic reference assigned when creating or sharing the payment button by a URL parameter.
The transactionReference contains the unique reference identifier that is assigned to every transaction in Fygaro.
The createdAt contains the timestamp that reflects the moment when the customer initiated the payment.
The jwt contains a token in “Json Web Token” (JWT) format with the detailed information of the transaction.
The JWT format will allow you to guarantee the integrity and source of the information provided thanks to the signature that is created using the credential defined in the previous chapter. For more information on the format, you can visit: https://jwt.io/.
Before obtaining the information contained within the JWT, it is recommended to validate it using the previously defined credentials. Once it is determined valid, you can access the body of the token, where you will find the following information:
"CustomReference" is a validated copy of the field described above.
"TransactionReference" is a validated copy of the field described above.
"CreatedAt" is a validated copy of the field described above.
“Currency” contains the 3-character ISO alphabetic code that represents the currency used in the payment (ex: “USD”).
“Amount” contains the amount of the transaction in “Decimal” format of up to 2 characters.
"ClientData" is a dictionary that contains the information of the customer who made the purchase. Its structure is as follows:
"name": name and surname entered by the customer when making the payment.
"email": Email entered by the customer when making the payment.
"phone": Telephone entered by the customer when making the payment.
Requests made to the requested URL await a successful response using status 200. Any other response or time-out status will be considered a failure and the request will be retried later.
A single request will be attempted up to 4 times, each attempt taking longer to break than the last to allow your system to recover from errors or crashes.
Please note that multiple consecutive failed requests may cause a temporary suspension of sending new requests for the same payment button. Repetitive suspensions can cause a permanent hook lock.