Refund Lineitem
The refund_lineitem call is used to attempt to issue a full refund on a lineitem. This call will send the REFUND_ISSUED INS message.
URL: https://www.2checkout.com/api/sales/refund_lineitem
HTTP Method: POST
Input Parameters
Parameter |
Description |
lineitem_id |
Line item to issue refund on. Required. |
category |
ID representing the reason the refund was issued. Required. (values: 1-17 from the following list can be used except for 7 as it is for internal use only) |
ID |
Description |
1 |
Did not receive order |
2 |
Did not like item |
3 |
Item(s) not as described |
4 |
Fraud |
5 |
Other |
6 |
Item not available |
7 |
Do Not Use (Internal use only) |
8 |
No response from merchant |
9 |
Recurring last installment |
10 |
Cancellation |
11 |
Billed in error |
12 |
Prohibited product |
13 |
Service refunded at merchants request |
14 |
Non delivery |
15 |
Not as described |
16 |
Out of stock |
17 |
Duplicate |
Data Returned
Parameter |
Description |
response_code |
Tells the user whether or not the operation was successful |
response_message |
Tells the user why the operation was or was not successful |
Example API Call
Twocheckout::username('testlibraryapi901248204');
Twocheckout::password('testlibraryapi901248204PASS');
// Twocheckout::sandbox(true); #Uncomment to use Sandbox
$args = array(
'lineitem_id' => 4753371371,
'category' => 1,
'comment' => 'Order never sent.'
);
try {
$result = Twocheckout_Sale::refund($args);
} catch (Twocheckout_Error $e) {
$e->getMessage();
}
Twocheckout::API.credentials = {
:username => 'APIuser1817037',
:password => 'APIpass1817037',
# :sandbox => 1 #Uncomment to use Sandbox
}
begin
sale = Twocheckout::Sale.find(:sale_id => 4786293822)
last_invoice = sale.invoices.last
last_lineitem = last_invoice.lineitems.last
result = last_lineitem.refund!({:comment => "test refund", :category => 1})
rescue Twocheckout::TwocheckoutError => e
puts e.message
end
var tco = new Twocheckout({
apiUser: "APIuser1817037",
apiPass: "APIpass1817037",
sandbox: false
});
args = {
sale_id: "4774380224",
comment: "test",
category: "5"
};
tco.sales.refund(args, function (error, data) {
if (error) {
console.log(error);
} else {
console.log(data.response_code);
}
});
twocheckout.Api.auth_credentials({
'username': APIuser1817037',
'password': 'APIpass1817037',
# 'mode': 'sandbox' #Uncomment to use Sandbox
})
params = {
'sale_id': 4834917619,
'category': 1,
'comment': "Refunding Sale"
}
try:
sale = twocheckout.Sale.find(params)
invoice = sale.invoices[0]
lineitem = invoice.lineitems[0]
result = lineitem.refund(params)
except TwocheckoutError as error:
print error.message
TwoCheckoutConfig.ApiUsername = "APIuser1817037";
TwoCheckoutConfig.ApiPassword = "APIpass1817037";
// TwoCheckoutConfig.Sandbox = true; #Uncomment to use Sandbox
try
{
var ServiceObject = new SaleService();
var ArgsObject = new SaleRefundServiceOptions();
ArgsObject.lineitem_id = lineitem_id;
ArgsObject.comment = "test refund";
ArgsObject.category = 5;
var result = ServiceObject.Refund(ArgsObject);
}
catch (TwoCheckoutException e)
{
Console.Write(e);
}
TwoCheckoutConfig.ApiUsername = "APIuser1817037";
TwoCheckoutConfig.ApiPassword = "APIpass1817037";
// Twocheckout.mode = "sandbox"; #Uncomment to use Sandbox
HashMap params = new HashMap();
params.put("comment", "test");
params.put("category", "1");
try {
Sale sale = TwocheckoutSale.retrieve("9093717691800");
Invoice[] invoices = sale.getInvoices();
Invoice invoice = invoices[invoices.length-1];
Lineitem[] lineitems = invoice.getLineitems();
Lineitem lineitem = lineitems[0];
TwocheckoutResponse result = lineitem.refund(params);
String message = result.getResponseMessage();
} catch (TwocheckoutException e) {
String message = e.toString();
}
curl -X POST https://www.2checkout.com/api/sales/refund_lineitem \
-u 'username:password' -d 'lineitem_id=1234567890' -d 'category=16' \
-d 'comment=Item not in stock.' -H 'Accept: application/json'
Example Successful Response
{
"response_code" : "OK",
"response_message" : "lineitem refunded"
}
Common Error Codes
Code |
Description |
PARAMETER_MISSING |
Required parameter missing: |
PARAMETER_INVALID |
Required parameter is invalid: |
RECORD_NOT_FOUND |
Unable to find record. |
FORBIDDEN |
Access denied to sale. |
Method-Specific Error Codes
Code |
Description |
FORBIDDEN |
Permission denied to set refund category to 7. |
INVALID_PARAMETER |
This lineitem cannot be refunded. |
NOTHING_TO_DO |
Lineitem was already refunded. |
TOO_LATE |
Invoice too old to refund lineitem. (Will occur if sale is over 180 days) |
TOO_HIGH |
Lineitem amount greater than remaining balance on invoice. |
TOO_LOW |
Lineitem amount must be at least 0.01. |