== payment_subscriptions.refund-stop ==
=== Description ===
Stops user's subscription and refunds transaction. User will be demoted to free access.
IMPORTANT:
Refund-stop must be performed against appropriate system's url(system_id, retrieved by payment_subscriptions.search)
```
if system_id == m21
staging: https://cs-m21.dvipdev.com/
production: https://cs-m21.dvipapp.com/
```
==== Input Parameters ====
<table>
<tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th><th>Note</th></tr>
<tr><td>sub_id</td><td>int</td><td>Yes</td><td>Subscription ID</td><td>Subscription that will be stopped</td></tr>
<tr><td>tran_id</td><td>int</td><td>Yes</td><td>Transaction ID</td><td>Transaction that will be refunded</td></tr>
<tr><td>pp_type</td><td>string</td><td>No</td><td>Payment Processor Type</td><td>If not passed will be retrieved from subscription/transaction payment data</td></tr>
</table>
==== Return ====
<table>
<tr><th>Name</th><th>Type</th><th>Description</th><th>Note</th></tr>
<tr><td>success</td><td>bool</td><td>Is subscription stopped and is transaction refunded?</td><td>Checks state for both transaction and subscription - returns true if transaction is refunded and subscription is stopped - also true if transaction was refunded before, and/or subscription stoppped before.</td></tr>
<tr><td>refunded</td><td>bool</td><td>Is transaction refunded?</td><td>Checks transaction state - true if transaction is(or already was) refunded</td></tr>
<tr><td>stopped</td><td>bool</td><td>Is subscription stopped?</td><td>Checks subscription state - true if subscription is(or already was) stopped</td></tr>
</table>
==== Usage Example ====
example query:
```
/api.json?cmd=payment_subscriptions.refund-stop&tran_id=117303&sub_id=14624&pp_type=RG
```
example of successful execution:
```lang=json
{
"meta": {
"messages": [
{
"code": "refund_success",
"params": null,
"sticky": false,
"text": "refund_success"
}
],
"status": "OK"
},
"result": {
"success": true,
"refunded": true,
"stopped": true,
"id": 0,
"data": [
],
"item": [
]
}
}
```
Example of repeated call after successful one:
```lang=json
{
"meta": {
"errors": [
{
"code": "614: [102] Cannot Credit - A credit operation cannot be performed because the original transaction has already been voided, credited, or has not been settled.",
"params": null,
"sticky": false,
"text": "614: [102] Cannot Credit - A credit operation cannot be performed because the original transaction has already been voided, credited, or has not been settled."
},
{
"code": "refund_failed",
"params": null,
"sticky": false,
"text": "refund_failed"
}
],
"messages": [
{
"code": "err_sub_stopped_canceled",
"params": null,
"sticky": false,
"text": "err_sub_stopped_canceled"
}
],
"status": "ERROR"
},
"result": {
"success": true,
"refunded": true,
"stopped": true,
"id": 0,
"data": [
],
"item": [
]
}
}
```
Example of failed execution(refund failed - transaction is not refunded), subscription stopped successfully
```lang=json
{
"meta": {
"errors": [
{
"code": "820: Can't find matching transaction",
"params": null,
"sticky": false,
"text": "820: Can't find matching transaction"
},
{
"code": "refund_failed",
"params": null,
"sticky": false,
"text": "refund_failed"
}
],
"status": "ERROR"
},
"result": {
"success": false,
"refunded": false,
"stopped": true,
"id": 0,
"data": [
],
"item": [
]
}
}
```