> For the complete documentation index, see [llms.txt](https://edrus.gitbook.io/appgregator-api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edrus.gitbook.io/appgregator-api-docs/appgregators/payment-gateway/stripe/api/payments/payment-method/attach-a-payment-method-to-a-customer.md).

# Attach a Payment Method to a Customer

<mark style="color:green;">`POST`</mark> `https://us-central1-appgregator.cloudfunctions.net/stripe/payment/methods/:id/attach`

#### Query Parameters

| Name                                               | Type   | Description |
| -------------------------------------------------- | ------ | ----------- |
| name<mark style="color:red;">\*</mark>             | String | ft-4        |
| connection\_name<mark style="color:red;">\*</mark> | String | stripe-1    |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| x-api-key<mark style="color:red;">\*</mark> | String | XXX         |

#### Request Body

| Name                                       | Type   | Description         |
| ------------------------------------------ | ------ | ------------------- |
| customer<mark style="color:red;">\*</mark> | String | cus\_MQqeLuPp19Qbk8 |

{% tabs %}
{% tab title="201: Created " %}

```javascript
{
    "id": "pm_1MZTFzIyq0PiFIhU8bezpCMk",
    "object": "payment_method",
    "billing_details": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "postal_code": null,
            "state": null
        },
        "email": null,
        "name": null,
        "phone": null
    },
    "card": {
        "brand": "visa",
        "checks": {
            "address_line1_check": null,
            "address_postal_code_check": null,
            "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 8,
        "exp_year": 2023,
        "fingerprint": "UDAye2KvD1pcOwWy",
        "funding": "credit",
        "generated_from": null,
        "last4": "4242",
        "networks": {
            "available": [
                "visa"
            ],
            "preferred": null
        },
        "three_d_secure_usage": {
            "supported": true
        },
        "wallet": null
    },
    "created": 1675922720,
    "customer": "cus_MQqeLuPp19Qbk8",
    "livemode": false,
    "metadata": {},
    "type": "card"
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="cURL" %}

```shell
curl --location --request POST 'https://us-central1-appgregator.cloudfunctions.net/stripe/payment/methods?name=ft-4&connection_name=stripe-1' \
--header 'x-api-key: XXX' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'type=card' \
--data-urlencode 'card[number]=4242424242424242' \
--data-urlencode 'card[exp_month]=8' \
--data-urlencode 'card[exp_year]=2023' \
--data-urlencode 'card[cvc]=314'
```

{% endtab %}

{% tab title="NodeJS - Axios" %}

```javascript
var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'type': 'card',
  'card[number]': '4242424242424242',
  'card[exp_month]': '8',
  'card[exp_year]': '2023',
  'card[cvc]': '314' 
});
var config = {
  method: 'post',
  url: 'https://us-central1-appgregator.cloudfunctions.net/stripe/payment/methods?name=ft-4&connection_name=stripe-1',
  headers: { 
    'x-api-key': 'XXX', 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="PHP - cURL" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://us-central1-appgregator.cloudfunctions.net/stripe/payment/methods?name=ft-4&connection_name=stripe-1',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => 'type=card&card%5Bnumber%5D=4242424242424242&card%5Bexp_month%5D=8&card%5Bexp_year%5D=2023&card%5Bcvc%5D=314',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: XXX',
    'Content-Type: application/x-www-form-urlencoded'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}
{% endtabs %}
