> 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.

# Save a tokenized payment method for a customer

POST https://pay.mvscloud.com/api/customers/{id}/payment-methods
Content-Type: application/json

Saves a payment method for the customer from a one-time `token`. The customer must already have a linked Hyperswitch customer identity (otherwise 404). The request is routed to the engine's `/v1/customers/{id}/payment-methods` extension path; the response is the engine payment-method object (loosely typed; extra fields pass through). Pass an `Idempotency-Key` header to make retries safe.

Reference: https://docs.mvscloud.com/mvs-pay/api/customers/create-customer-payment-method

## 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 org-scoped billing customer id.

### Headers

- `Idempotency-Key` (string, optional) — Client-supplied idempotency key for safe retries.

### Body (application/json)

This endpoint expects a CustomerPaymentMethodCreateRequest.

- `token` (string, required) — One-time token representing the card to save.
- `tags` (map from string to any, optional) — Optional free-form tags forwarded to the engine.

## Response

### 200

The saved payment method as returned by the engine.

- `payment_method_id` (string, optional)
- `brand` (string, optional, nullable)
- `last4` (string, optional, nullable)

## 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)

### 404 Not Found Error

The resource does not exist for this 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

### ErrorResponseError

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

## Examples

**Request**

```json
{
  "token": "tok_save_card_abc123",
  "tags": {
    "label": "Primary card"
  }
}
```

**Response**

```json
{
  "payment_method_id": "pm_01H8sample456",
  "brand": "visa",
  "last4": "4242"
}
```

**SDK Code**

```python Customers_createCustomerPaymentMethod_example
import requests

url = "https://pay.mvscloud.com/api/customers/id/payment-methods"

payload = {
    "token": "tok_save_card_abc123",
    "tags": { "label": "Primary card" }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Customers_createCustomerPaymentMethod_example
const url = 'https://pay.mvscloud.com/api/customers/id/payment-methods';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"token":"tok_save_card_abc123","tags":{"label":"Primary card"}}'
};

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

```go Customers_createCustomerPaymentMethod_example
package main

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

func main() {

	url := "https://pay.mvscloud.com/api/customers/id/payment-methods"

	payload := strings.NewReader("{\n  \"token\": \"tok_save_card_abc123\",\n  \"tags\": {\n    \"label\": \"Primary card\"\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 Customers_createCustomerPaymentMethod_example
require 'uri'
require 'net/http'

url = URI("https://pay.mvscloud.com/api/customers/id/payment-methods")

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  \"token\": \"tok_save_card_abc123\",\n  \"tags\": {\n    \"label\": \"Primary card\"\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://pay.mvscloud.com/api/customers/id/payment-methods")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"token\": \"tok_save_card_abc123\",\n  \"tags\": {\n    \"label\": \"Primary card\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://pay.mvscloud.com/api/customers/id/payment-methods', [
  'body' => '{
  "token": "tok_save_card_abc123",
  "tags": {
    "label": "Primary card"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Customers_createCustomerPaymentMethod_example
using RestSharp;

var client = new RestClient("https://pay.mvscloud.com/api/customers/id/payment-methods");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"token\": \"tok_save_card_abc123\",\n  \"tags\": {\n    \"label\": \"Primary card\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Customers_createCustomerPaymentMethod_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "token": "tok_save_card_abc123",
  "tags": ["label": "Primary card"]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://pay.mvscloud.com/api/customers/id/payment-methods")! 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()
```