Creating payment link
Learn how to create a link to a Gerencianet payment screen for your customers to make payments. To create it is very simple and requires only two steps:
First, create the transaction, informing the item/product/service, value, quantity, etc;
Now to create payment link, inform the
charge_id
of the transaction created earlier.
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.
Bolix
If you have activated Bolix in your Gerencianet account, the charges generated by our module/plugin will already come with the pix on the ticket. More details about Bolix and how to activate it, click here.
1. Create the transaction
First, we need to generate the transaction (also called "charge"). It is at this moment that the name of the item/product/service, transaction value, quantity, among other possible information will be informed.
After creating it, the charge_id
will be returned, which is the unique identifier of the transaction and will be used to associate the payment method.
As soon as this transaction is created, it receives the status new
, which means that the charge has been generated and is awaiting definition of the payment method. This charge will only change its status when the integrator defines your payment method.
To generate a transaction, you must send a POST
request to the /v1/charge
route.
If you want, you can explore and learn more about this feature using our Playground.
The example below shows how this can be done, using the SDK's available:
- PHP
- Python
- NodeJS
- .NET
- Java
- GO
- Ruby
- Delphi
a) Hierarchical structure of Schema attributes that can be used:
To check more details, go here and explore in our Playground.
b) Attributes that can be used to create a transaction:
Objeto items
Attribute | Description | Mandatory | Type |
---|---|---|---|
items | item being sold. The same transaction can have unlimited items. Item attributes: name* // Name of the item, product or service. Minimum of 1 character and maximum of 255 characters (String).value* // Value, in cents. Ex: R$ 10,00 = 1000. Integeramount Integer | Yes | Array |
shippings | Determines the shipping amount(s) for a transaction. The same transaction can have unlimited shipping values. Shipping attributes: name* // Rótulo do frete. Maximum of 255 characters. String.value* // Freight value, in cents (1990 is equivalent to R$19.90). Integer | No | Array |
metadata | Define transaction-specific data Metadata attributes: custom_id // It allows associating a Gerencianet transaction with a specific ID of your system or application, allowing you to identify it if you have a specific ID and want to keep it. Maximum of 255 characters. String/null.notification_url // Address of your valid URL that will receive transaction status change notifications. Maximum of 255 characters. String/null. | No | Object |
Fields with * represent mandatory values
Now that the transaction has been created and you already have the charge_id
, you need to associate it to get the payment link.
2. Creating a payment link
To create a payment link you need to have generated the transaction, that is, that you already have the charge identifier charge_id
, as you will need to inform it.
Then simply send a POST
request to the /v1/charge/:id/link
route to generate a payment link, where the :id
corresponds to the charge_id
of the transaction created.
If you want, you can explore and learn more about this resource using our Playground.
The example below shows how this can be done, using the SDK's available:
- PHP
- Python
- NodeJS
- .NET
- Java
- GO
- Ruby
- Delphi
important
To create a "payment link" (chargeLink
), a previously created "transaction" (createCharge
) must be informed. Therefore, if there is an attempt to pay and, for some reason, the payment confirmation is not successful (ex: card declined, customer wants to pay in another way, etc.), a new transaction must be generated and associated with a new payment, as the previous transaction will be in a waiting or unpaid status, which means that due to the payment attempt, it has already been linked to a payment method.
a) Attributes that can be used to create a payment link:
Attribute | Description | Mandatory | Type |
---|---|---|---|
billet_discount | Defines a discount, in reais, if the payer chooses a boleto bancário as the payment method (inform the entire amount, in reais). 5000 is equivalent to R$ 50,00 | No | Integer |
card_discount | Defines a discount, in reais, if the payer chooses a credit card as the payment method (enter Integer value). 5000 equals to R$ 50,00 | No | Integer |
conditional_discount | Defines conditional discount that is valid until a specific date. If payment is not made by that date, the discount is invalidated. Conditional discount attributes: type*// Discount type (String). Allowed values: currency : the discount will be reported in cents. percentage :the discount will be informed in percentage.cnpj* Size: 14 characters. String.value*// discount amount (Integer). If the discount type is currency , the value of this tag must be informed by the integrator in cents (ie 500 is equivalent to R$ 5.00). If the discount type is percentage , the value must be multiplied by 100 (ie 1500 equals 15%). Examples: 1) currency // must be informed in cents, that is, if the discount will be R$ 5.99, the integrator must inform 599 ;2) percentage // must be informed in cents, that is, if the discount is 15%, the integrator must inform 1500 .until_date*, // Maximum date the discount will be granted. (String). Format: YYYY-MM-DD | No | Object |
message | Defines a message for the payer. The message appears on the payment screen, in the billing-related emails and on the boleto, if this is the chosen payment method. Minimum of 3 and maximum of 80 characters. | No | String |
expire_at | Defines the due date of the payment screen and of the ticket itself, if this is the chosen payment method. Format: YYYY-MM-DD | Yes | String |
request_delivery_address | Defines whether the payment screen should ask the payer to enter a delivery address. There are two possible values:
| Yes | Boolean |
payment_method | Defines the payment methods that must be available on the screen for your customer to choose, which can be:
| Yes | Object |
Fields with * represent mandatory values
When consuming the /charge/:id/link
endpoint, or through the Playground, the charge gains link
status. In this way, the integrator can distinguish common charges that have not yet had a defined payment method (status new
) from charges that have been associated with a payment link (status link
).
The integrator only needs to redirect the payer to the link returned in the payment_url
tag and everything else will be done on the Gerencianet payment screen.
Then, through the "Input Data" tab, a simple JSON that can be used to create the payment link. Also, you can see the predicted output and validation schema with all tags (mandatory and optional) available for this method. Remembering that you also need to inform the charge_id
input parameter of the transaction created:
- Dados de Entrada
- Dados de Saída
- Schema
This JSON, present in the "Input Data" tab, defines the following information when creating the payment link:
message
: defines a message to the payer. The message appears on the payment screen, in the billing-related emails and on the payment slip, if this is the chosen payment method (maximum 80 characters);payment_method
: defines the payment methods that must be available on the screen (banking_billet
,credit_card
ouall
);expire_at
: defines the payment methods that must be available on the screenrequest_delivery_address
: defines whether the payment screen should ask the payer to enter a delivery address (true
oufalse
);billet_discount
: defines a discount, in cents, if the payer chooses a bank slip as the payment method (enter Integer value);card_discount
: defines a discount, in cents, if the payer chooses a credit card as the payment method (enter Integer value).
List of all possible statuses of a transaction
All transactions have status, which represents the "status" of that transaction. Therefore, it is important to know the possible statuses in the API to provide the proper handling in your system.
Check out this link all the details of the possible status of the transactions.
API transaction callbacks (notifications) to your system
Notifications allow you to be informed when a transaction has changed status. In this way, you will be able to identify when a charge is paid, for example.
Check out this link all the details on how to implement your notification URL.
b) Hierarchical structure of Schema attributes that can be used:
For more details, click here and explore in our Playground.
c) Customizing your payment screen:
You can set a color and logo for your screen. For that, Log into your Gerencianet account and access the menu Minha Conta > Tela de Pagamento
.
Even if you prefer to use your own screen, the information defined here will also be used in emails triggered by the API. So we recommend that you do the customization anyway.
d) Testing in test environment (Playground):
To create a payment link, you must first create a charge in the API, consuming the POST /v1/charge
endpoint. This endpoint returns, among other information, an identifier for the charge. The initial status of a charge is new
:
- Entrada
Just below, the expected output data according to the input made above:
- Saída
Knowing the charge identifier, just consume the POST endpoint /v1/charge/:id/link to generate a payment link.
3. Other endpoints and methods
There are other payment link related endpoints and methods that are available in the API and can be exploited by the integrator. Check out the complete list:
Change certain parameters/attributes of an existing payment link
Change notification URL (notification_url) and/or transaction custom_id
4. Video: Creating transaction via Playground (test environment/sandbox)
Thinking about offering new ways of transmitting information, Gerencianet makes the following video available in order to explain, in a clear and objective way, how to create a transaction via playground (sandbox).
Complete Course on Integration with the Gerencianet API
For access to other classes, on other subjects, access the page Integrations Online Course.