# Update a card payment source

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Merchants look to update card details when:

-   The billing address of a customer has changed. In such a case, modify the billing address in the Chargebee and the payment gateway.
-   The expiration date of the card has been extended by the bank. (This usually happens when the date of card expiry is in near future).

Multiple parameters such as address, expiry date, month, and so on, can be updated through this API.

Meta data can also be added additionally(supported in Stripe only). Metadata is a JSON object. It is used to store additional information about customers.

In **Stripe** and **Braintree** payment gateways, changes in card details are auto-updated. This feature can also be used for other payment gateways in which auto-update is not enabled or is not supported by Chargebee.

**Note** : This endpoint supports Chargebee Test Gateway, [Stripe](https://www.chargebee.com/docs/2.0/stripe.html) , [Braintree](https://www.chargebee.com/docs/2.0/braintree.html) , [Authorize.net](https://www.chargebee.com/docs/2.0/authorize-index.html) , [Worldpay US eCom](https://www.chargebee.com/docs/2.0/vantiv_worldpay.html) , and [WorldPay Direct Integration](https://www.chargebee.com/docs/2.0/worldpay-direct.html) . For all other gateways, your customers must re-enter the full [card details](/docs/api/payment_sources/update-a-card-payment-source#card_first_name) to update existing card details. For example, consider a customer not using the gateways mentioned above and wants to update the [card\[billing\_addr1\]](/docs/api/payment_sources/update-a-card-payment-source#card_billing_addr1) parameter. In such a case, the customer must re-enter the value of all the parameters present in the [card](/docs/api/payment_sources/update-a-card-payment-source#card_first_name) object.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/pm___test__XpbTXGTSRp4Xy9FR/update_card \
     -u {site_api_key}:\
     -d "card[first_name]"="John" \
     -d "card[last_name]"="Doe" \
     -d "card[expiry_month]"=5 \
     -d "card[expiry_year]"=2022 \
     -d "card[billing_addr1]"="#678 Mission Street" \
     -d "card[billing_city]"="New York City" \
     -d "card[billing_zip]"="10002" \
     -d "card[billing_state_code]"="NY" \
     -d "card[billing_country]"="US"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.UpdateCard("pm___test__XpbTXGTSRp4Xy9FR")
		.CardFirstName("John")
		.CardLastName("Doe")
		.CardExpiryMonth(5)
		.CardExpiryYear(2022)
		.CardBillingAddr1("#678 Mission Street")
		.CardBillingCity("New York City")
		.CardBillingZip("10002")
		.CardBillingStateCode("NY")
		.CardBillingCountry("US")
		.Request();

Customer customer = result.Customer;
PaymentSource paymentSource = result.PaymentSource;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    paymentsourceAction "github.com/chargebee/chargebee-go/v3/actions/paymentsource"
    "github.com/chargebee/chargebee-go/v3/models/paymentsource"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentsourceAction.UpdateCard("pm___test__XpbTXGTSRp4Xy9FR", &paymentsource.UpdateCardRequestParams{
        Card : &paymentsource.UpdateCardCardParams{
            FirstName : "John",
            LastName : "Doe",
            ExpiryMonth : chargebee.Int32(5),
            ExpiryYear : chargebee.Int32(2022),
            BillingAddr1 : "#678 Mission Street",
            BillingCity : "New York City",
            BillingZip : "10002",
            BillingStateCode : "NY",
            BillingCountry : "US",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PaymentSourceUpdateCardRequest{
    Card : &chargebee.PaymentSourceUpdateCardCard{
        FirstName : "John",
        LastName : "Doe",
        ExpiryMonth : chargebee.Int32(5),
        ExpiryYear : chargebee.Int32(2022),
        BillingAddr1 : "#678 Mission Street",
        BillingCity : "New York City",
        BillingZip : "10002",
        BillingStateCode : "NY",
        BillingCountry : "US",
    },
}
  res, err := client.PaymentSource.UpdateCard("pm___test__XpbTXGTSRp4Xy9FR", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = PaymentSource.updateCard("pm___test__XpbTXGTSRp4Xy9FR")
            .cardFirstName("John")
            .cardLastName("Doe")
            .cardExpiryMonth(5)
            .cardExpiryYear(2022)
            .cardBillingAddr1("#678 Mission Street")
            .cardBillingCity("New York City")
            .cardBillingZip("10002")
            .cardBillingStateCode("NY")
            .cardBillingCountry("US")
            .request();

        Customer customer = result.customer();
        PaymentSource paymentSource = result.paymentSource();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.paymentSource.PaymentSource;
import com.chargebee.v4.models.paymentSource.params.PaymentSourceUpdateCardParams;
import com.chargebee.v4.models.paymentSource.responses.PaymentSourceUpdateCardResponse;

public class PaymentSourceUpdateCard {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PaymentSourceUpdateCardParams.CardParams cardParams =
            PaymentSourceUpdateCardParams.CardParams.builder()
                .firstName("John")
                .lastName("Doe")
                .expiryMonth(5)
                .expiryYear(2022)
                .billingAddr1("#678 Mission Street")
                .billingCity("New York City")
                .billingZip("10002")
                .billingStateCode("NY")
                .billingCountry("US")
                .build();

        PaymentSourceUpdateCardParams params = PaymentSourceUpdateCardParams.builder()
            .card(cardParams)
            .build();

        PaymentSourceUpdateCardResponse response = client
            .paymentSources()
            .updateCard("pm___test__XpbTXGTSRp4Xy9FR", params);

        Customer customer = response.getCustomer();
        PaymentSource paymentSource = response.getPaymentSource();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.paymentSource.updateCard("pm___test__XpbTXGTSRp4Xy9FR", {
        card: {
            first_name: "John",
            last_name: "Doe",
            expiry_month: 5,
            expiry_year: 2022,
            billing_addr1: "#678 Mission Street",
            billing_city: "New York City",
            billing_zip: 10002,
            billing_state_code: "NY",
            billing_country: "US"
        }
    });

    console.log(result);
    const customer = result.customer;
    const paymentSource = result.payment_source;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->paymentSource()->updateCard("pm___test__XpbTXGTSRp4Xy9FR", [
    "card" => [
        "first_name" => "John",
        "last_name" => "Doe",
        "expiry_month" => 5,
        "expiry_year" => 2022,
        "billing_addr1" => "#678 Mission Street",
        "billing_city" => "New York City",
        "billing_zip" => "10002",
        "billing_state_code" => "NY",
        "billing_country" => "US"
    ]
]);
$customer = $result->customer;
$paymentSource = $result->payment_source;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentSource.update_card("pm___test__XpbTXGTSRp4Xy9FR",
    cb_client.PaymentSource.UpdateCardParams(
        card=cb_client.PaymentSource.UpdateCardCardParams(
            first_name="John",
            last_name="Doe",
            expiry_month=5,
            expiry_year=2022,
            billing_addr1="#678 Mission Street",
            billing_city="New York City",
            billing_zip="10002",
            billing_state_code="NY",
            billing_country="US"
        )
    )
)
customer = response.customer
payment_source = response.payment_source
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::PaymentSource.update_card("pm___test__XpbTXGTSRp4Xy9FR",{
  :card => {
    :first_name => "John",
    :last_name => "Doe",
    :expiry_month => 5,
    :expiry_year => 2022,
    :billing_addr1 => "#678 Mission Street",
    :billing_city => "New York City",
    :billing_zip => "10002",
    :billing_state_code => "NY",
    :billing_country => "US"
  }
})

customer = result.customer
payment_source = result.payment_source
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517487258,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp4Xi1FQ",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "payment_method": {
      "gateway": "stripe",
      "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
      "object": "payment_method",
      "reference_id": "cus_J7rVemdQKHVECd/card_1IVbmxJv9j0DyntJlQ8osjf2",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__XpbTXGTSRp4Xy9FR",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517487261178,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517487261
  },
  "payment_source": {
    "card": {
      "billing_addr1": "#678 Mission Street",
      "billing_city": "New York City",
      "billing_country": "US",
      "billing_zip": "10002",
      "brand": "visa",
      "expiry_month": 5,
      "expiry_year": 2022,
      "first_name": "John",
      "funding_type": "credit",
      "iin": "******",
      "last4": "1111",
      "last_name": "Doe",
      "masked_number": "************1111",
      "object": "card"
    },
    "created_at": 1517487259,
    "customer_id": "__test__XpbTXGTSRp4Xi1FQ",
    "deleted": false,
    "gateway": "stripe",
    "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
    "id": "pm___test__XpbTXGTSRp4Xy9FR",
    "issuing_country": "US",
    "object": "payment_source",
    "reference_id": "cus_J7rVemdQKHVECd/card_1IVbmxJv9j0DyntJlQ8osjf2",
    "resource_version": 1517487261179,
    "status": "valid",
    "type": "card",
    "updated_at": 1517487261
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/payment_sources/{cust-payment-source-id}/update_card

## Input Parameters

- `gateway_meta_data` (optional, jsonobject)
  Additional data about this resource can be passed to **Stripe** gateway here in the JSON Format. This will be stored along with payment source at the gateway account.

- `reference_transaction` (optional, string, max chars=50)
  Reference transaction is used for future purchases. This is only applicable for Vantiv.

- `card` (optional, string)
  Parameters for card
  - `first_name` (optional, string, max chars=50)
    Cardholder's first name
  - `last_name` (optional, string, max chars=50)
    Cardholder's last name
  - `expiry_month` (optional, integer, min=1, max=12)
    Card expiry month.
  - `expiry_year` (optional, integer)
    Card expiry year.
  - `billing_addr1` (optional, string, max chars=150)
    Address line 1, as available in card billing address.
  - `billing_addr2` (optional, string, max chars=150)
    Address line 2, as available in card billing address.
  - `billing_city` (optional, string, max chars=50)
    City, as available in card billing address.
  - `billing_zip` (optional, string, max chars=20)
    Postal or Zip code, as available in card billing address.
  - `billing_state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search) without the country prefix. Currently supported for USA, Canada, India and UAE. For instance, for Arizona (USA), set `billing_state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ). For Dubai (UAE), set as `DU` (not `AE-DU` ).
  - `billing_state` (optional, string, max chars=50)
    The state/province name.
  - `billing_country` (optional, string, max chars=50)
    The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html) .
    
    **Note**: If you enter an invalid country code, the system will return an error.
    
    **Brexit**
    
    If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  - `additional_information` (optional, jsonobject)
    -   `ebanx`: While passing raw card details to EBANX, the user's `document` is required for some countries.
        
        -   `payer`: User related information.
            -   `document`: Document is the user's identification number based on their country.

## Returns

- `customer` (Customer object)
  Resource object representing customer

- `payment_source` (Payment source object)
  Resource object representing payment\_source
