> This page is for MVS Pay.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mvscloud.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mvscloud.com/_mcp/server.

# Refund a payment

POST https://pay.mvscloud.com/api/transactions/{id}/refund
Content-Type: application/json

Issues a refund against the payment identified by the path `id`. Omit `amount` to refund the full captured amount, or supply a positive integer (cents) for a partial refund. Pass an `idempotency-key` header to make the refund safe to retry; it is forwarded to the engine.

Reference: https://docs.mvscloud.com/mvs-pay/api/refunds/create-refund

## Authentication

- `x-api-key` header (required) — A scoped MvsPayApiKey, e.g. `mvspay_live_…`. Mint and scope keys from the dashboard (Settings → API Keys).

## Request

### Path parameters

- `id` (string, required) — The payment id (Hyperswitch payment_intent id) to refund.

### Headers

- `idempotency-key` (string, optional) — Client-supplied idempotency key; forwarded to the engine to make retries safe.

### Body (application/json)

This endpoint expects a RefundCreateRequest.

- `amount` (integer, optional) — Positive integer (cents) for a partial refund. Omit to refund the full captured amount.
- `reason` (string, optional) — Free-text refund reason forwarded to the engine.
- `metadata` (map from string to any, optional) — Arbitrary key/value pairs forwarded to the engine.

## Response

### 200

The created refund (returned under `refund`).

- `refund` (RefundResponseBody, required) — A refund as modeled by the payments engine. Loosely typed; extra Hyperswitch fields pass through. All amount fields are minor units (cents).

## Errors

### 400 Bad Request Error

Invalid request (e.g. malformed JSON, missing required field, amount below minimum).

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

Missing or invalid API key.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

The key lacks the required scope, or the body references a different organization.

- `error` (ErrorResponseError, required)

### 500 Internal Server Error

Unexpected server error.

- `error` (ErrorResponseError, required)

### 502 Bad Gateway Error

The payments engine (Hyperswitch/connector) returned an error.

- `error` (ErrorResponseError, required)

## Types

### RefundResponseBody

A refund as modeled by the payments engine. Loosely typed; extra Hyperswitch fields pass through. All amount fields are minor units (cents).

- `refund_id` (string, optional) — The refund id.
- `payment_id` (string, optional) — The payment id (Hyperswitch payment_intent id) this refund applies to.
- `amount` (integer, optional) — Refunded amount in minor units (cents).
- `currency` (string, optional)
- `status` (string, optional) — e.g. pending, succeeded, failed, review.

### ErrorResponseError

- `code` (string, required) — e.g. UNAUTHORIZED, FORBIDDEN, ERROR.
- `message` (string, required)
- `details` (map from string to any, optional)

## Examples

**Request**

```json
{
  "amount": 2500,
  "reason": "requested_by_customer",
  "metadata": {
    "ticket": "SUP-1042"
  }
}
```

**Response**

```json
{
  "refund": {
    "refund_id": "ref_Qp7sample123",
    "payment_id": "pay_Qp7sample123",
    "amount": 2500,
    "currency": "USD",
    "status": "pending"
  }
}
```

**SDK Code**

```python Refunds_createRefund_example
import requests

url = "https://pay.mvscloud.com/api/transactions/id/refund"

payload = {
    "amount": 2500,
    "reason": "requested_by_customer",
    "metadata": { "ticket": "SUP-1042" }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Refunds_createRefund_example
const url = 'https://pay.mvscloud.com/api/transactions/id/refund';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"amount":2500,"reason":"requested_by_customer","metadata":{"ticket":"SUP-1042"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Refunds_createRefund_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://pay.mvscloud.com/api/transactions/id/refund"

	payload := strings.NewReader("{\n  \"amount\": 2500,\n  \"reason\": \"requested_by_customer\",\n  \"metadata\": {\n    \"ticket\": \"SUP-1042\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Refunds_createRefund_example
require 'uri'
require 'net/http'

url = URI("https://pay.mvscloud.com/api/transactions/id/refund")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount\": 2500,\n  \"reason\": \"requested_by_customer\",\n  \"metadata\": {\n    \"ticket\": \"SUP-1042\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Refunds_createRefund_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://pay.mvscloud.com/api/transactions/id/refund")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount\": 2500,\n  \"reason\": \"requested_by_customer\",\n  \"metadata\": {\n    \"ticket\": \"SUP-1042\"\n  }\n}")
  .asString();
```

```php Refunds_createRefund_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://pay.mvscloud.com/api/transactions/id/refund', [
  'body' => '{
  "amount": 2500,
  "reason": "requested_by_customer",
  "metadata": {
    "ticket": "SUP-1042"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Refunds_createRefund_example
using RestSharp;

var client = new RestClient("https://pay.mvscloud.com/api/transactions/id/refund");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount\": 2500,\n  \"reason\": \"requested_by_customer\",\n  \"metadata\": {\n    \"ticket\": \"SUP-1042\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Refunds_createRefund_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "amount": 2500,
  "reason": "requested_by_customer",
  "metadata": ["ticket": "SUP-1042"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://pay.mvscloud.com/api/transactions/id/refund")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```