# POST /paymentmethod/{{customer_id}} — Create Payment Method

> Product: **Pabbly Subscription Billing** (v1)
> Base URL: `https://payments.pabbly.com/api/v1`
> Auth: Basic via `Authorization` header
> Canonical: `/subscription-billing/payment-method/create-payment-method`

POST request API. Can be used t add a new payment method for an existing customer. In response you will get the ‘success’ status and then you can bill this customer using the newly added payment method.

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| customer_id | string | Yes |  |

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| gateway_type | string | Yes | Can be stripe only. |
| first_name | string | No |  |
| last_name | string | No |  |
| email | string | No |  |
| card_number | string | No |  |
| month | string | No |  |
| year | string | No |  |
| cvv | string | No |  |
| street | string | No |  |
| city | string | No |  |
| state | string | No |  |
| zip_code | string | No |  |
| country | string | No |  |
| Basic Details | string | Yes | Nedd to provide the first name, last name, and email address of the customer. |
| Card Details | string | Yes | Card Number, Expiry and CVV will be added in the respective fields. These details will be stored in the payment gateways only. |

**Example request body:**

```json
{
	"gateway_type":"stripe",
	"first_name":"Akash",
	"last_name":"Agrsh",
	"email":"akash@domain.com",
	"card_number":"4111111111111111",
	"month":"01",
	"year":"2029",
	"cvv":"864",
	"street":"",
	"city":"",
	"state":"",
	"zip_code":"",
	"country":""
}
```

**Response (200)** — Create Payment Method:

```json
{
    "status": "success",
    "message": "Payment method created successfully",
    "data": {
        "id": "5e5f46ff7c5aeb3675f41696",
        "gateway": {
            "id": "5e3a96413c92e44b424b6d51",
            "name": "Stripe",
            "type": "stripe"
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "gateway_type": "stripe",
    "first_name": "Akash",
    "last_name": "Agrsh",
    "email": "akash@domain.com",
    "card_number": "4111111111111111",
    "month": "01",
    "year": "2029",
    "cvv": "864",
    "street": "",
    "city": "",
    "state": "",
    "zip_code": "",
    "country": ""
  }'
```

_Ruby_

```ruby
require 'net/http'
require 'json'

uri = URI('https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"gateway_type\":\"stripe\",\"first_name\":\"Akash\",\"last_name\":\"Agrsh\",\"email\":\"akash@domain.com\",\"card_number\":\"4111111111111111\",\"month\":\"01\",\"year\":\"2029\",\"cvv\":\"864\",\"street\":\"\",\"city\":\"\",\"state\":\"\",\"zip_code\":\"\",\"country\":\"\"}"

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

data = JSON.parse(response.body)
```

_Python_

```python
import requests
from requests.auth import HTTPBasicAuth

response = requests.post(
    'https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'gateway_type': 'stripe',
    'first_name': 'Akash',
    'last_name': 'Agrsh',
    'email': 'akash@domain.com',
    'card_number': '4111111111111111',
    'month': '01',
    'year': '2029',
    'cvv': '864',
    'street': '',
    'city': '',
    'state': '',
    'zip_code': '',
    'country': ''
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_USERPWD, '{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"gateway_type":"stripe","first_name":"Akash","last_name":"Agrsh","email":"akash@domain.com","card_number":"4111111111111111","month":"01","year":"2029","cvv":"864","street":"","city":"","state":"","zip_code":"","country":""}');

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

_Java_

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;

String credentials = Base64.getEncoder().encodeToString("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}".getBytes());

HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder builder = HttpRequest.newBuilder()
    .uri(URI.create("https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"gateway_type\":\"stripe\",\"first_name\":\"Akash\",\"last_name\":\"Agrsh\",\"email\":\"akash@domain.com\",\"card_number\":\"4111111111111111\",\"month\":\"01\",\"year\":\"2029\",\"cvv\":\"864\",\"street\":\"\",\"city\":\"\",\"state\":\"\",\"zip_code\":\"\",\"country\":\"\"}"));

HttpRequest request = builder.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

_Node.js_

```node
const credentials = Buffer.from('{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}').toString('base64');

const response = await fetch('https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "gateway_type": "stripe",
    "first_name": "Akash",
    "last_name": "Agrsh",
    "email": "akash@domain.com",
    "card_number": "4111111111111111",
    "month": "01",
    "year": "2029",
    "cvv": "864",
    "street": "",
    "city": "",
    "state": "",
    "zip_code": "",
    "country": ""
  }),
});

const data = await response.json();
```

_Go_

```go
package main

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

func main() {
    payload := strings.NewReader("{\"gateway_type\":\"stripe\",\"first_name\":\"Akash\",\"last_name\":\"Agrsh\",\"email\":\"akash@domain.com\",\"card_number\":\"4111111111111111\",\"month\":\"01\",\"year\":\"2029\",\"cvv\":\"864\",\"street\":\"\",\"city\":\"\",\"state\":\"\",\"zip_code\":\"\",\"country\":\"\"}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}", payload)
    req.Header.Set("Content-Type", "application/json")
    req.SetBasicAuth("{{YOUR_API_KEY}}", "{{YOUR_SECRET_KEY}}")

    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)
    fmt.Println(string(body))
}
```

_.NET_

```dotnet
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}"));

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://payments.pabbly.com/api/v1/paymentmethod/{{customer_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"gateway_type\":\"stripe\",\"first_name\":\"Akash\",\"last_name\":\"Agrsh\",\"email\":\"akash@domain.com\",\"card_number\":\"4111111111111111\",\"month\":\"01\",\"year\":\"2029\",\"cvv\":\"864\",\"street\":\"\",\"city\":\"\",\"state\":\"\",\"zip_code\":\"\",\"country\":\"\"}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
```

---

**Other endpoints in Payment Method:**

- [GET /paymentmethods/{{customer_id}} — List All Payment Methods By Customer Id](/subscription-billing/payment-method/list-all-payment-methods-by-customer-id)
- [PUT /paymentmethod/{{customer_id}} — Update Payment Method For Existing Customer](/subscription-billing/payment-method/update-payment-method-for-existing-customer)

