Reembolsar una orden
La funcionalidad de devolución de órdenes permite hacer solicitudes de reembolso para los cargos de una orden. Existen dos opciones de devolución disponibles: devolución total y devolución parcial.
Reembolso total
La devolución total permite reembolsar todos los cargos de una orden. Para hacer una solicitud de devolución total, se necesita el ID de la orden y se debe hacer una petición HTTP POST al siguiente endpoint: https://api.conekta.io/orders/ORDER_ID/refunds
. El único parámetro requerido es ORDER_ID
. También puedes proporcionar un parámetro opcional reason
, que especifica el motivo de la devolución.
Para realizar una devolución total de una orden, utiliza el siguiente endpoint:
POST https://api.conekta.io/orders/{order_id}/refunds
Parámetros opcionales
Parámetro | Tipo | Descripción | Posibles valores |
---|---|---|---|
reason | string | Motivo del reembolso | requested_by_client, cannot_be_fulfilled, duplicated_transaction, suspected_fraud, other |
Ejemplo
curl --location 'https://api.conekta.io/orders/ORDER_ID/refunds' \
--header 'Accept: application/vnd.conekta-v2.1.0+json' \
--header 'Content-type: application/json' \
--header 'Authorization: Basic ACCESS_TOKEN' \
--data '{
"reason": "requested_by_client"
}'
order = Conekta::Order.find("ORDER_ID")
order.refund({
reason: 'requested_by_client'
})
<?php
// Configuración de Conekta
\Conekta\Conekta::setApiKey("ACCESS_TOKEN");
\Conekta\Conekta::setApiVersion("2.1.0");
\Conekta\Conekta::setLocale('es');
// Obtener la orden
$order = \Conekta\Order::find('ORDER_ID');
// Reembolso
$order->refund(['reason' => 'requested_by_client']);
?>
const Conekta = require('conekta');
Conekta.apiKey = "ACCESS_TOKEN";
Conekta.apiVersion = "2.1.0";
Conekta.locale = 'es';
// Obtener la orden
Conekta.Order.find('ORDER_ID', (err, order) => {
if (err) {
console.log(err);
} else {
// Reembolso
order.createRefund({reason: 'requested_by_client'}, (err, res) => {
if (err) {
console.log(err);
} else {
console.log(res);
}
});
}
});
import conekta
conekta.api_key = "ACCESS_TOKEN"
conekta.api_version = "2.1.0"
conekta.locale = "es"
# Obtener la orden
order = conekta.Order.find("ORDER_ID")
# Reembolso
order.refund({'reason': 'requested_by_client'})
Order order = Order.find("ORDER_ID");
JSONObject validRefund = new JSONObject("{"
+ "'reason': 'requested_by_client'"
+ "}");
order.refund(validRefund);
Order order = new Order().find("ORDER_ID");
order.refund(@"{
""reason"": "requested_by_client"
}");
import (
conekta "github.com/conekta/conekta-go"
"github.com/conekta/conekta-go/order"
)
orderRefund := &conekta.OrderRefundParams{}
orderRefund.Reason = ""
order.Refund("ORDER_ID", orderRefund)
Reembolso parcial
La devolución parcial permite hacer una solicitud de reembolso de sólo una parte de los cargos de una orden. Para hacer una solicitud de devolución parcial, se necesitan dos parámetros: el ID de la orden y el ID del cargo que se desea reembolsar.
También puedes proporcionar un parámetro opcional reason
, que especifica el motivo de la devolución, y un parámetro opcional amount
, que indica el monto que se desea reembolsar.
Importante
Si no se proporciona el parámetro
amount
, se reembolsará el total del cargo especificado.
Para hacer una solicitud de devolución parcial, se debe hacer una petición HTTP POST al siguiente endpoint: https://api.conekta.io/orders/ORDER_ID/refunds
. Los parámetros requeridos son order_id
y charge_id
. Los parámetros opcionales son reason
y amount
.
Para realizar una devolución parcial de una orden, utiliza el siguiente endpoint:
POST https://api.conekta.io/orders/{order_id}/refunds
Parámetros requeridos
Parámetro | Tipo | Descripción |
---|---|---|
charge_id | string | ID del cargo a devolver. |
Parámetros opcionales
Parámetro | Tipo | Descripción | Posibles valores |
---|---|---|---|
reason | string | Motivo del reembolso | requested_by_client, cannot_be_fulfilled, duplicated_transaction, suspected_fraud, other |
amount | int | Monto a reembolsar |
Petición
curl --location 'https://api.conekta.io/orders/ORDER_ID/refunds' \
--header 'Accept: application/vnd.conekta-v2.1.0+json' \
--header 'Content-type: application/json' \
--header 'Authorization: Basic ACCESS_TOKEN' \
--data '{
"amount": 10000,
"charge_id": "CHARGE_ID",
"reason": "requested_by_client"
}'
order = Conekta::Order.find("ORDER_ID")
order.refund({
charge_id: "CHARGE_ID",
amount: 10000,
reason: 'requested_by_client'
})
<?php
// Configuración de Conekta
\Conekta\Conekta::setApiKey("ACCESS_TOKEN");
\Conekta\Conekta::setApiVersion("2.1.0");
\Conekta\Conekta::setLocale('es');
// Obtener la orden
$order = \Conekta\Order::find('ORDER_ID');
// Reembolso
$order->refund(['charge_id' => 'CHARGE_ID', 'amount' => 10000, 'reason' => 'requested_by_client']);
?>
const Conekta = require('conekta');
Conekta.apiKey = "ACCESS_TOKEN";
Conekta.apiVersion = "2.1.0";
Conekta.locale = 'es';
// Obtener la orden
Conekta.Order.find('ORDER_ID', (err, order) => {
if (err) {
console.log(err);
} else {
// Reembolso
order.createRefund({charge_id: 'CHARGE_ID', amount: 10000, reason: 'requested_by_client'}, (err, res) => {
if (err) {
console.log(err);
} else {
console.log(res);
}
});
}
});
import conekta
conekta.api_key = "ACCESS_TOKEN"
conekta.api_version = "2.1.0"
conekta.locale = "es"
# Obtener la orden
order = conekta.Order.find("ORDER_ID")
# Reembolso
order.refund({'charge_id': 'CHARGE_ID', 'amount': 10000, 'reason': 'requested_by_client'})
Order order = Order.find("ORDER_ID");
JSONObject validRefund = new JSONObject("{"
+ "'charge_id': 'CHARGE_ID',"
+ "'amount': 10000,"
+ "'reason': 'requested_by_client'"
+ "}");
order.refund(validRefund);
Order order = new Order().find("ORDER_ID");
order.refund(@"{
""charge_id"": ""CHARGE_ID"",
""amount"": 10000,
""reason"": ""requested_by_client""
}");
import (
conekta "github.com/conekta/conekta-go"
"github.com/conekta/conekta-go/order"
)
orderRefund := &conekta.OrderRefundParams{}
orderRefund.Reason = "requested_by_client"
orderRefund.ChargeID = "CHARGE_ID"
orderRefund.Amount = 10000
order.Refund("ORDER_ID", orderRefund)
Respuesta
{
"livemode": false,
"amount": 50000,
"currency": "MXN",
"payment_status": "refunded",
"amount_refunded": 50000,
"split_payment": true,
"customer_info": {
"email": "[email protected]",
"phone": "5522997233",
"name": "Nicolás Cedrón",
"corporate": true,
"customer_id": null,
"object": "customer_info"
},
"shipping_contact": null,
"channel": null,
"fiscal_entity": null,
"object": "order",
"id": "ord_2tgvDBAmxTMqSftQE",
"metadata": {},
"is_refundable": false,
"created_at": 1681358076,
"updated_at": 1681358168,
"line_items": {
"object": "list",
"has_more": false,
"total": 1,
"data": [
{
"name": "Box of Cohiba S1s",
"description": null,
"unit_price": 50000,
"quantity": 1,
"sku": null,
"tags": null,
"brand": null,
"type": null,
"object": "line_item",
"id": "line_item_2tgvDBAmxTMqSftQC",
"parent_id": "ord_2tgvDBAmxTMqSftQE",
"metadata": {},
"antifraud_info": {}
}
]
},
"shipping_lines": null,
"tax_lines": null,
"discount_lines": null,
"charges": {
"object": "list",
"has_more": false,
"total": 2,
"data": [
{
"id": "64377cfe77a374b7a7580b01",
"livemode": false,
"created_at": 1681358078,
"currency": "MXN",
"failure_code": null,
"failure_message": null,
"monthly_installments": null,
"device_fingerprint": null,
"channel": null,
"payment_method": {
"name": "Ezequiel Haydossian",
"exp_month": "02",
"exp_year": "30",
"auth_code": "1776",
"object": "card_payment",
"type": "credit",
"normalized_device_fingerprint": null,
"last4": "4242",
"brand": "visa",
"issuer": "bbva",
"account_type": "cuenta oro",
"country": "MX",
"fraud_score": null,
"fraud_indicators": []
},
"object": "charge",
"description": "Payment from order",
"is_refundable": false,
"reference_id": null,
"status": "refunded",
"amount": 30000,
"paid_at": 1681358079,
"customer_id": "",
"order_id": "ord_2tgvDBAmxTMqSftQE",
"refunds": {
"object": "list",
"has_more": false,
"total": 1,
"data": [
{
"object": "refund",
"amount": -30000,
"id": "64377d5877a374b7a7580b21",
"created_at": 1681358168,
"auth_code": "1776"
}
]
}
},
{
"id": "64377cfc77a374b7a7580af2",
"livemode": false,
"created_at": 1681358076,
"currency": "MXN",
"failure_code": null,
"failure_message": null,
"monthly_installments": null,
"device_fingerprint": null,
"channel": null,
"payment_method": {
"name": "Ezequiel Haydossian",
"exp_month": "02",
"exp_year": "30",
"auth_code": "1991",
"object": "card_payment",
"type": "credit",
"normalized_device_fingerprint": null,
"last4": "4242",
"brand": "visa",
"issuer": "bbva",
"account_type": "cuenta oro",
"country": "MX",
"fraud_score": null,
"fraud_indicators": []
},
"object": "charge",
"description": "Payment from order",
"is_refundable": false,
"reference_id": null,
"status": "refunded",
"amount": 20000,
"paid_at": 1681358078,
"customer_id": "",
"order_id": "ord_2tgvDBAmxTMqSftQE",
"refunds": {
"object": "list",
"has_more": false,
"total": 1,
"data": [
{
"object": "refund",
"amount": -20000,
"id": "64377d5777a374b7a7580b17",
"created_at": 1681358167,
"auth_code": "1991"
}
]
}
}
]
}
}
Errores
Si intentas reembolsar una orden y alguno de sus cargos no puede ser reembolsable, recibirás el siguiente error:
{
"details": [
{
"debug_message": "The order can not be returned.",
"message": "No se puede devolver la orden.",
"param": null,
"code": "conekta.errors.precondition_required.combo.order.is_not_returnable"
}
],
"object": "error",
"type": "precondition_required_error",
"log_id": "64377c4b77a374b7a7580ac7"
}
Si agregas el parámetro amount y el monto es menor al total de la orden, recibirás:
{
"details": [
{
"debug_message": "Charge id is required for refund split payments",
"message": "El id del cargo es requerido para reembolsar pagos fraccionados",
"param": null,
"code": "conekta.errors.processing.charge_operations.refund.split_payment.charge_id_is_required"
}
],
"object": "error",
"type": "processing_error",
"log_id": "64377d1377a374b7a7580b0f",
"data": {
"livemode": false,
"amount": 50000,
"currency": "MXN",
"payment_status": "paid",
"amount_refunded": 0,
"customer_info": {
"email": "[email protected]",
"phone": "5522997233",
"name": "Nicolás Cedrón",
"corporate": true,
"customer_id": null,
"object": "customer_info"
},
"shipping_contact": null,
"channel": null,
"fiscal_entity": null,
"object": "order",
"id": "ord_2tgvDBAmxTMqSftQE",
"metadata": {},
"is_refundable": true,
"created_at": 1681358076,
"updated_at": 1681358079,
"line_items": {
"object": "list",
"has_more": false,
"total": 1,
"data": [
{
"name": "Box of Cohiba S1s",
"description": null,
"unit_price": 50000,
"quantity": 1,
"sku": null,
"tags": null,
"brand": null,
"type": null,
"object": "line_item",
"id": "line_item_2tgvDBAmxTMqSftQC",
"parent_id": "ord_2tgvDBAmxTMqSftQE",
"metadata": {},
"antifraud_info": {}
}
]
},
"shipping_lines": null,
"tax_lines": null,
"discount_lines": null,
"charges": {
"object": "list",
"has_more": false,
"total": 2,
"data": [
{
"id": "64377cfe77a374b7a7580b01",
"livemode": false,
"created_at": 1681358078,
"currency": "MXN",
"failure_code": null,
"failure_message": null,
"monthly_installments": null,
"device_fingerprint": null,
"channel": null,
"payment_method": {
"name": "Ezequiel Haydossian",
"exp_month": "02",
"exp_year": "30",
"auth_code": "1776",
"object": "card_payment",
"type": "credit",
"normalized_device_fingerprint": null,
"last4": "4242",
"brand": "visa",
"issuer": "bbva",
"account_type": "cuenta oro",
"country": "MX",
"fraud_score": null,
"fraud_indicators": [],
"antifraud_flag": ""
},
"object": "charge",
"description": "Payment from order",
"reference_id": null,
"status": "paid",
"amount": 30000,
"paid_at": 1681358079,
"fee": 1241,
"customer_id": "",
"order_id": "ord_2tgvDBAmxTMqSftQE",
"refunds": null
},
{
"id": "64377cfc77a374b7a7580af2",
"livemode": false,
"created_at": 1681358076,
"currency": "MXN",
"failure_code": null,
"failure_message": null,
"monthly_installments": null,
"device_fingerprint": null,
"channel": null,
"payment_method": {
"name": "Ezequiel Haydossian",
"exp_month": "02",
"exp_year": "30",
"auth_code": "1991",
"object": "card_payment",
"type": "credit",
"normalized_device_fingerprint": null,
"last4": "4242",
"brand": "visa",
"issuer": "bbva",
"account_type": "cuenta oro",
"country": "MX",
"fraud_score": null,
"fraud_indicators": [],
"antifraud_flag": ""
},
"object": "charge",
"description": "Payment from order",
"reference_id": null,
"status": "paid",
"amount": 20000,
"paid_at": 1681358078,
"fee": 905,
"customer_id": "",
"order_id": "ord_2tgvDBAmxTMqSftQE",
"refunds": null
}
]
}
}
}
Updated about 1 year ago