== transaction.refund ==
==== Description ====
Refund transaction for passed tran_id and pp_type. If optional amount parameter is sent then:
- if less than the one used in original transaction then PV2 will try to issue partial refund.
- If passed amount is equal to the one used in original transaction, full refund will be issued
- If passed amount is bigger than the one used in original transaction or partial refund is already sent and total sum of refunds is bigger than amount used in original transaction - an error will be issued on PP level.
==== Input Parameters ====
<table>
<tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
<tr><td>tran_id</td><td>Int</td><td>Yes</td><td>PV2 Transaction ID (i.e. obtained with transaction.list)</td></tr>
<tr><td>pp_type</td><td>string</td><td>Yes</td><td>PP Type (NB|RG|PO|...)</td></tr>
<tr><td>amount</td><td>float</td><td>No</td><td>Amount to be refunded</td></tr>
</table>
==== Returned result ====
<table>
<tr><th>Name</th><th>Type</th><th>Description</th></tr>
<tr><td>success</td><td>boolean</td><td>True on success false on failure</td></tr>
<tr><td>error_msg</td><td>string</td><td>Error msg in case of error</td></tr>
</table>
==== Usage Example ====
```
<?php
require_once "curl_http_client/curl_http_client.php";
$curl = new Curl_HTTP_Client();
//setup payment url and timeout
$payment_url = 'https://dev-payment.datingvip.com';
$timeout = 30;
//generate post data
$post_data = array
(
'token' => 'some-token',
'password' => '130d04b8123456857e47b254ebfbb53f',
'command' => 'transaction.refund',
'data' => array(
'tran_id' => 1,
'pp_type' => 'RG',
'amount' => 24.99
),
);
$response = $curl->send_post_data($payment_url, $post_data, null, $timeout);
if($response === false)
{
//handle errors
}
//decode json to get array
$response = json_decode($response, true);
var_dump($response);
?>
```
Excepted output after running this script should be:
```
array (size=9)
'code' => int 700
'status' => string 'Action completed succesfully' (length=28)
'command' => string 'transaction.refund' (length=18)
'result' =>
array (size=2)
'success' => boolean true
'error_msg' => string '' (length=0)
'request' =>
array (size=4)
'token' => string 'some-token' (length=10)
'password' => string '130d04b8123456857e47b254ebfbb53f' (length=32)
'command' => string 'transaction.refund' (length=18)
'data' =>
array (size=3)
'tran_id' => int 1
'amount' => float 24.99
'pp_type' => string 'RG' (length=2)
'ts' => int 1382547800
'origin_ip' => boolean false
'debug' => null
'errors' => null
```