Queries¶
Get transactions¶
The query can be done in three ways, using the tx_id of the transaction,
using the pix_client_id that was passed during the creation of the charge and performing the full query where.
Info
The automatic printing feature is available starting from version 1.3.3.0 of the Pix App.
consultByTxId()¶
To perform the query using the transaction's tx_id:
Request¶
// query request
{
"tx_id": "b849b36b-7846-48f8-81ce-a8dbf2530f42",
"preview_customer_receipt": true,
"preview_merchant_receipt": true,
"print_customer_receipt": true,
"print_merchant_receipt": true
}
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
request |
consultByTxId |
Yes | Data transfer object that will contain the pix request information. Note that not all parameters are mandatory. |
callback |
ConsultPixPaymentCallback |
Yes | Interface that will be executed for notifications of success or error in the pix process. |
Parameter Details
request (consultByTxId)
| Name | Type | Required | Description | Default |
|---|---|---|---|---|
tx_id |
String |
Yes | The tx_id represents the id of the pix transaction. | |
preview_customer_receipt |
Boolean |
No | Indicates whether the customer's receipt should be displayed. | true |
preview_merchant_receipt |
Boolean |
No | Indicates whether the merchant's receipt should be displayed. | true |
print_customer_receipt |
Boolean |
No | Indicates whether the customer's receipt should be printed automatically. Note: Automatic printing will only occur if the receipt preview is disabled ( false). |
true |
print_merchant_receipt |
Boolean |
No | Indicates whether the merchant's receipt should be printed automatically. Note: Automatic printing will only occur if the receipt preview is disabled ( false). |
true |
Parameter Details
callback (ConsultPixPaymentCallback)
| Name | Type | Required | Description |
|---|---|---|---|
onSuccess |
Cadena |
Yes | Notification method in case of success. The return response will be a string in json format that will contain the fields that are displayed in the class PixResponse |
onError |
Cadena |
Yes | Notification method in case of error. The return response will be a string in json format that will have the fields shown in the class PixErrorResponse |
fun consultCobRequestService(
pixClient: PixClient,
txId: String,
previewCustomerReceipt: Boolean,
previewMerchantReceipt: Boolean,
printCustomerReceipt: Boolean,
printMerchantReceipt: Boolean,
context: Context
) {
val gson: Gson = Gson()
if (pixClient.isBound() && txId.isNotBlank()) {
val consultCobRequest = ConsultCobRequest(txId, previewCustomerReceipt, previewMerchantReceipt, printCustomerReceipt, printMerchantReceipt)
val callback = object : PixClient.ConsultByTxIdCallback {
override fun onError(response: String?) {
val responseError = gson.fromJson(response, PixErrorResponse::class.java)
println("Erro $response")
Toast.makeText(context, responseError.errorMessage, Toast.LENGTH_SHORT).show()
}
override fun onSuccess(response: String?) {
println("consultado $response")
if (response != null) {
val responseObject =
gson.fromJson(response, PixResponse::class.java)
val responseUtils = ResponseUtils()
Toast.makeText(
context,
responseUtils.messageConsultPix(context, responseObject),
Toast.LENGTH_LONG
).show()
}
}
}
pixClient.consultByTxId(
gson.toJson(consultCobRequest),
callback
)
}
}
Example of the ConsultCobRequest class:¶
data class ConsultCobRequest(
@SerializedName("tx_id")
val txId: String,
@SerializedName("preview_customer_receipt")
val previewCustomerReceipt: Boolean,
@SerializedName("preview_merchant_receipt")
val previewMerchantReceipt: Boolean,
@SerializedName("print_customer_receipt")
val printCustomerReceipt: Boolean,
@SerializedName("print_merchant_receipt")
val printMerchantReceipt: Boolean
)
ResponseUtils class example:¶
class ResponseUtils {
fun messageConsultPix(context: Context, response: PixResponse): String {
return "${context.getString(R.string.consult)}: \n" +
"${context.getString(R.string.value)}: ${response.cobValue} \n" +
"${context.getString(R.string.status)}: ${chargeStatus(context, response.status.getValue())} \n" +
"${context.getString(R.string.tx_id)}: ${response.txID}"
}
fun chargeStatus(context: Context, status: String): String {
return when (status) {
ChargeStatus.ACTIVE.getValue() -> context.getString(R.string.active)
ChargeStatus.CONCLUDED.getValue() -> context.getString(R.string.sale)
ChargeStatus.REFUNDED.getValue() -> context.getString(R.string.refunded)
ChargeStatus.REFUND_PROCESSING.getValue() -> context.getString(R.string.refund_processing)
ChargeStatus.REFUND_NOT_DONE.getValue() -> context.getString(R.string.refund_not_done)
ChargeStatus.REMOVED_BY_USER.getValue() -> context.getString(R.string.cancelled_charge)
ChargeStatus.REMOVED_BY_PSP.getValue() -> context.getString(R.string.cancelled_charge)
ChargeStatus.EXPIRED.getValue() -> context.getString(R.string.expired)
else -> ""
}
}
}
PixResponse¶
data class PixResponse(
@SerializedName("cob_value")
val cobValue: String,
@SerializedName("status")
var status: String,
@SerializedName("tx_id")
val txID: String,
)
PixErrorResponse¶
class PixErrorResponse (
@SerializedName("error_message")
val errorMessage: String
)
consultByPixClientId()¶
To get using pix_client_id:
Request¶
// query request
{
"pix_client_id": "b849b36b-7846-48f8-81ce-a8dbf2530f42"
}
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
request |
consultByPixClientId |
Yes | Data transfer object that will contain the pix request information. Note that not all parameters are mandatory. |
callback |
ConsultByPixClientIdCallback |
Yes | Interface that will be executed for notifications of success or error in the pix process. |
Parameter Details
request (consultByPixClientId)
| Name | Type | Required | Description |
|---|---|---|---|
pix_client_id |
String |
Yes | The pix_client_id is a unique identifier used by the integration app to identify charges created. It supports up to 36 characters. |
Parameter Details
callback (ConsultByPixClientIdCallback)
| Name | Type | Required | Description |
|---|---|---|---|
onSuccess |
Cadena |
Yes | Notification method in case of success. The return response will be a string in json format that will contain the fields that are displayed in the class PixResponse |
onError |
Cadena |
Yes | Notification method in case of error. The return response will be a string in json format that will have the fields shown in the class PixErrorResponse |
fun consultPixClientIdRequestService(
pixClient: PixClient,
pixClientId: String,
context: Context
) {
val gson: Gson = Gson()
if (pixClient.isBound() && pixClientId.isNotBlank()) {
val consultPixByCorrelationIdRequest = ConsultPixByCorrelationIdRequest(pixClientId)
val callback = object : PixClient.ConsultByPixClientIdCallback {
override fun onError(response: String?) {
val responseError = gson.fromJson(response, PixErrorResponse::class.java)
println("Erro $response")
Toast.makeText(context, responseError.errorMessage, Toast.LENGTH_LONG).show()
}
override fun onSuccess(response: String?) {
println("Consultado $response")
if (response != null) {
val responseObject =
gson.fromJson(response, PixResponse::class.java)
val responseUtils = ResponseUtils()
Toast.makeText(
context,
responseUtils.messageConsultPix(context, responseObject),
Toast.LENGTH_LONG
).show()
}
}
}
pixClient.consultByPixClientId(
gson.toJson(consultPixByCorrelationIdRequest),
callback
)
}
}
Example of the ConsultPixByCorrelationIdRequest class:¶
data class ConsultPixByCorrelationIdRequest(
@SerializedName("pix_client_id")
val pixClientId: String
)
PixResponse¶
data class PixResponse(
@SerializedName("cob_value")
val cobValue: String,
@SerializedName("status")
var status: String,
@SerializedName("tx_id")
val txID: String,
)
PixErrorResponse¶
class PixErrorResponse (
@SerializedName("error_message")
val errorMessage: String
)
consult()¶
The PixClient.ConsultCallback method performs a query using the Pix client API and handles the results of this query through a callback.
Request¶
// request de consulta
{
"preview_customer_receipt": true,
"preview_merchant_receipt": true,
"print_customer_receipt": true,
"print_merchant_receipt": true
}
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
request |
pixClientConsult |
Yes | Data transfer object containing the PIX request information. Note that not all parameters are mandatory. |
callback |
PixClientConsultCallback |
Yes | Interface to be executed for success or error notifications of the PIX process. |
Parameter Details
request (pixClientconsult)
| Name | Type | Required | Description | Default |
|---|---|---|---|---|
preview_customer_receipt |
Boolean |
No | Indicates whether the customer's receipt should be displayed. | true |
preview_merchant_receipt |
Boolean |
No | Indicates whether the merchant's receipt should be displayed. | true |
print_customer_receipt |
Boolean |
No | Indicates whether the customer's receipt should be printed automatically. Note: Automatic printing will only occur if the receipt preview is disabled ( false). |
true |
print_merchant_receipt |
Boolean |
No | Indicates whether the merchant's receipt should be printed automatically. Note: Automatic printing will only occur if the receipt preview is disabled ( false). |
true |
Parameter Details
callback (ConsultPixPaymentCallback)
| Name | Type | Required | Description |
|---|---|---|---|
onSuccess |
String |
Yes | Method for notification in case of success. The returned response will be a JSON string containing fields shown in the PixResponse class |
onError |
String |
Yes | Method for notification in case of error. The returned response will be a JSON string containing fields shown in the PixErrorResponse class |
val callback = object : PixClient.ConsultCallback {
override fun onError(response: String?) {
Toast.makeText(context, "Erro na consulta: $response", Toast.LENGTH_LONG).show()
onError(response)
}
override fun onSuccess(response: String?) {
Toast.makeText(context, "Consulta realizada com sucesso.", Toast.LENGTH_LONG).show()
onSuccess(response)
}
}
pixClient.consult(request, callback)