How to create a Limited Invoice via API
Last updated
Last updated
Before starting an integration please check our page for more info.
An invoice is a document given to the buyer by the seller to collect payment. It includes the cost of the products purchased or services rendered to the buyer as well as lists products/services.
To accept a single payment for a product with a fixed price when price specified in crypto currency you can use single invoice. Single Invoice is an instrument that allows you to receive a fixed amount of funds for your product.
You can find more information about other features of Public API integration in our documentation:
To create a new Invoice use the following endpoint: New Single Invoice (POST https://api.calypso.finance/api/v1/invoice/single/create
)
You can find the detailed description of all the parameters in the documentation:
Here we consider the most important ones.
amount
(required) - the amount of money merchant want to receive for a product/service.
currency
(required) - the crypto currency of payment.
description
(required) - the description of product/service.
idempotencyKey
- a specific UUID for the payment link which guarantees uniqueness of the request. It’s possible to check the status of the invoice by this parameter after creation.
So to create invoice without additional options you just have to send request:
cURL
Some additional options:
By default the invoice is available 3hours for TRON base currencies 1day for others . You can set custom expiration time of an invoice by transmitting expiration field in request body but the expiration date may only be less than 1 day from the current moment. After this time the invoice will be unavailable for payment.
You can customise interface of your invoice by transmitting returnUrl
, supportUrl
and logoUrl
fields.
If the creation was successful you receive the response:
Response exampleJSON
To complete the payment the client must pay the amount of money from amount
field to address specified in invoiceAddress
field.
Now after you’ve successfully created Invoice you can send link for payment to your client. Link format: https://pay.calypso.finance/invoice/{idempotencyKey}
Invoice Payment link view
Or you can build your own invoice interface using data from the response.
For example, you can use the following HTML template:
After creating Invoice you can receive information about it from the system. There are two options to track changes in invoice state:
Get invoice data via request by ID.
Set webhooks for invoices
To receive information about earlier created Invoice you can use Get a Specific Invoice endpoint (POST https://api.calypso.finance/api/v1/invoice
).
You can request invoice by id
, externalId
or idempotencyKey
.
Example of the request by id
:
Bash
In response you will receive invoice data:
Response exampleJSON
The most important fields you need to pay attention to:
totalDebitAmount
- received amount of money to this invoice.
To track state of your created Invoice you can use Calypso Payment functionality which is called Webhooks.
Webhook is a way for an app to provide other applications with real-time information. The Webhooks API allows you to subscribe to events happening with your created objects (Invoices or Payouts) in Calypso. Rather than making an API call to check status of invoice or payout during processing, Calypso can send an HTTP request to an endpoint you configure.
First of all, to receive information about Invoice state change you need to create a subscription for system events which you want to track.
There are several types of events which you need to track in order to understand what is happening to your Invoices.
The main events are:
INVOICE_FUNDS_RECEIVED_FOR_INVOICE
The event shows if funds have been received to invoice wallet
INVOICE_PAID
Invoice successfully paid. All required amount has been received to invoice wallet.
INVOICE_PENDING_INTERVENTION
Invoice has changed state to INVOICE_PENDING_INTERVENTION. Either more or less funds was received to the invoice wallet than required
INVOICE_TRANSLATION_TO_ACCOUNT_COMPLETED
Funds have been received from invoice wallet to the merchant balance.
To create a subscription for those events you can use the Create Webhook Public API endpoint: POST https://api.calypso.finance/api/v1/subscription/webhook/create
Bash
You can subscribe to all types of events if you specify value “INVOICE” in the notificationServiceTypes
field instead of enumeration all types of events in notificationEventTypes
.
In the response you will get:
JSON
After successful creation of subscription for Payment events and providing your client with Payment Link you can wait for your client to make payment.
When money are received to invoice address you will receive webhook with type INVOICE_FUNDS_RECEIVED_FOR_INVOICE. It means that money delivered to invoice but it doesn't inform whether the right amount was received. You can compare amount from the webhook payload on your side or wait for the next webhook.
The example of webhook payload:
JSON
If client successfully paid the invoice (he sent the right amount of money) you will receive webhook with type INVOICE_PAID. Receiving this type of webhook guarantees that the invoice was fully paid.
The example of webhook payload:
To avoid errors related to receiving webhooks, it is necessary to request information about the invoice in Calypso Pay after receiving the webhook. To get detailed information about invoice you can use Get a Specific Invoice endpoint (POST https://api.calypso.finance/api/v1/invoice
using idempotencyKey
, externalId
or parentExternalId
(id
in request).
You will see changes in the fields:
The value of state
is PAID.
The value of totalDebitAmount
is changed to received payment amount.
The value of fee
shows the amount of service fee charged from the deposit amount of the invoice.
That means that the money were sent by client and they were received to invoice wallet address (invoiceAddress
field).
After receiving the correct amount of money to the invoice address in Calypso system the money will be automatically credited to the merchant balance.
When money successfully credited to the balance you will receive webhook with type INVOICE_TRANSLATION_TO_ACCOUNT_COMPLETED.
The example of webhook payload:
JSON
The most important fields in the event payload:
parentExternalId
- system ID of invoice.
externalId
- custom merchant ID, that could be set when the invoice was created.
amount
- amount of money paid for this invoice.
serviceFee
- service fee for the invoice deposit. This amount will be charged from the deposit amount.
In order to calculate exact amount of money credited to the merchant balance you should deduct serviceFee
from amount
.
You will see changes in the fields:
The value of state
is COMPLETED.
For advanced invoice usage scenarios and error handling please check our How to manage interventions via API? page.
You can set a specific custom ID to your Invoice by transmitting externalId
field in request body. It’s possible to check the status of the invoice by this parameter after creation. Here, for example, you can pass a unique client ID and then use this method get them all. As well, externalId
is returned in all types of events in webhooks, if it is set.
You can check the real example or watch entire payment flow .
The real example of embedded form .
See in details:
More info on Get a Specific Invoice endpoint:
state
- represents status of the invoice. More info about possible states in documentation:
More detailed information about Calypso Webhooks functionality:
More info on Calypso Webhooks event types:
We’ll look at more scenarios of using Webhooks in and sections.
More info on Webhooks management in Calypso Pay system: