Ir para o conteúdo

Refund


Refund of a PIX

Info

The automatic printing feature is available starting from version 1.3.3.0 of the Pix App.

The return can be made in two ways:

refund()

To list the return options, the refund function will be used and the following request must be passed:

Request

{
  "preview_customer_receipt": true,
  "preview_merchant_receipt": true,
  "print_customer_receipt": true,
  "print_merchant_receipt": true
}

Parameters

Name Type Required Description
request refundPixPayment Yes Data transfer object that will contain the pix request information. Note that not all parameters are mandatory.
callback RefundPixPaymentCallback Yes Interface that will be executed for notifications of success or error in the pix process.

Parameter Details

request (refundPixPayment)

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 (RefundPixPaymentCallback)

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 RefundPixService(
    pixClient: PixClient,
    previewCustomerReceipt: Boolean,
    previewMerchantReceipt: Boolean,
    printCustomerReceipt: Boolean,
    printMerchantReceipt: Boolean,
    context: Context
) {

    val gson: Gson = Gson()
    val refundPixRequest = RefundPixRequest(previewCustomerReceipt, previewMerchantReceipt, printCustomerReceipt, printMerchantReceipt)
    val callback = object : PixClient.RefundCallback {
        override fun onError(response: String?) {
            println("Erro ao devolver $response")

            val alertDialog = AlertDialog.Builder(context)
            alertDialog.setTitle(R.string.refund)
                .setMessage("Não foi possível realizar a devolução.")
                .setNeutralButton("Ok") { _, _ -> }
                .show()

        }

        override fun onSuccess(response: String?) {

            val alertDialog = AlertDialog.Builder(context)
            alertDialog.setTitle(R.string.refund)
                .setMessage("Devolução realizada com sucesso.")
                .setNeutralButton("Ok") { _, _ -> }
                .show()

        }

        }

    pixClient.refund(
        gson.toJson(refundPixRequest),
        callback
    )

}

Example of the RefundPixRequest class:

data class RefundPixRequest(
    @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
)

refundPixPayment()

To make a refund by tx-id, the refundPixPayment function will be used and the following request must be passed:

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 refundByTxIdPixPayment Yes Data transfer object that will contain the pix request information. Note that not all parameters are mandatory.
callback RefundByTxIdPixPaymentCallback Yes Interface that will be executed for notifications of success or error in the pix process.

Parameter Details

request (refundByTxIdPixPayment)

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 (RefundByTxIdPixPaymentCallback)

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 refundPixService(
    pixClient: PixClient,
    txId: String,
    previewCustomerReceipt: Boolean,
    previewMerchantReceipt: Boolean,
    printCustomerReceipt: Boolean,
    printMerchantReceipt: Boolean,
    context: Context
) {
    val gson: Gson = Gson()
    val refundPixRequest = RefundPixRequest(txId, previewCustomerReceipt, previewMerchantReceipt, printCustomerReceipt, printMerchantReceipt)
    val callback = object : PixClient.RefundPixPaymentCallback {
        override fun onError(response: String?) {
            println("Erro ao devolver $response")
            val alertDialog = AlertDialog.Builder(context)
            val responseError = gson.fromJson(response, PixErrorResponse::class.java)
            alertDialog.setTitle(R.string.pix_refund)
                .setMessage(responseError.errorMessage)
                .setNeutralButton("Ok") { _, _ -> }
                .show()
        }

        override fun onSuccess(response: String?) {
            val pixResponse = gson.fromJson(response, PixResponse::class.java)
            println("Devolvido $pixResponse")
            Toast.makeText(context, "Pix devolvido!", Toast.LENGTH_SHORT).show()
        }
    }

    pixClient.refundPixPayment(
        gson.toJson(refundPixRequest),
        callback
    )
}

Example of the RefundByTxIdPixRequest class:

data class RefundByTxIdPixRequest(
    @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
)

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
)