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

Storing card after successful 3DS completion is not supported in this API. Use [create using Payment Intent API](/docs/api/payment_sources/create-using-payment-intent) under Payment source to store the card after successful 3DS flow completion.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/create_card \
     -u {site_api_key}:\
     -d customer_id="__test__XpbTXGTSRp4Mg0Dr" \
     -d "card[number]"="378282246310005" \
     -d "card[cvv]"="100" \
     -d "card[expiry_year]"=2022 \
     -d "card[expiry_month]"=12
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.CreateCard()
		.CustomerId("__test__XpbTXGTSRp4Mg0Dr")
		.CardNumber("378282246310005")
		.CardCvv("100")
		.CardExpiryYear(2022)
		.CardExpiryMonth(12)
		.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.CreateCard(&paymentsource.CreateCardRequestParams{
        CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
        Card : &paymentsource.CreateCardCardParams{
            Number : "378282246310005",
            Cvv : "100",
            ExpiryYear : chargebee.Int32(2022),
            ExpiryMonth : chargebee.Int32(12),
        },
    }).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.PaymentSourceCreateCardRequest{
    CustomerId : "__test__XpbTXGTSRp4Mg0Dr",
    Card : &chargebee.PaymentSourceCreateCardCard{
        Number : "378282246310005",
        Cvv : "100",
        ExpiryYear : chargebee.Int32(2022),
        ExpiryMonth : chargebee.Int32(12),
    },
}
  res, err := client.PaymentSource.CreateCard(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.createCard()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .cardNumber("378282246310005")
            .cardCvv("100")
            .cardExpiryYear(2022)
            .cardExpiryMonth(12)
            .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.PaymentSourceCreateCardParams;
import com.chargebee.v4.models.paymentSource.responses.PaymentSourceCreateCardResponse;

public class PaymentSourceCreateCard {

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

        PaymentSourceCreateCardParams.CardParams cardParams =
            PaymentSourceCreateCardParams.CardParams.builder()
                .number("378282246310005")
                .cvv("100")
                .expiryYear(2022)
                .expiryMonth(12)
                .build();

        PaymentSourceCreateCardParams params = PaymentSourceCreateCardParams.builder()
            .customerId("__test__XpbTXGTSRp4Mg0Dr")
            .card(cardParams)
            .build();

        PaymentSourceCreateCardResponse response = client.paymentSources().createCard(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.createCard({
        customer_id: "__test__XpbTXGTSRp4Mg0Dr",
        card: {
            number: 378282246310005,
            cvv: 100,
            expiry_year: 2022,
            expiry_month: 12
        }
    });

    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()->createCard([
    "customer_id" => "__test__XpbTXGTSRp4Mg0Dr",
    "card" => [
        "number" => "378282246310005",
        "cvv" => "100",
        "expiry_year" => 2022,
        "expiry_month" => 12
    ]
]);
$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.create_card(
    cb_client.PaymentSource.CreateCardParams(
        customer_id="__test__XpbTXGTSRp4Mg0Dr",
        card=cb_client.PaymentSource.CreateCardCardParams(
            number="378282246310005",
            cvv="100",
            expiry_year=2022,
            expiry_month=12
        )
    )
)
customer = response.customer
payment_source = response.payment_source
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PaymentSource.create_card({
  :customer_id => "__test__XpbTXGTSRp4Mg0Dr",
  :card => {
    :number => "378282246310005",
    :cvv => "100",
    :expiry_year => 2022,
    :expiry_month => 12
  }
})

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

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517487216,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp4Mg0Dr",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "payment_method": {
      "gateway": "chargebee",
      "gateway_account_id": "gw___test__5SK2lMpwSRp4LJJ1y",
      "object": "payment_method",
      "reference_id": "tok___test__XpbTXGTSRp4MkpDu",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__XpbTXGTSRp4Ml3Dv",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517487216760,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517487216
  },
  "payment_source": {
    "card": {
      "brand": "american_express",
      "expiry_month": 12,
      "expiry_year": 2022,
      "funding_type": "not_known",
      "iin": "378282",
      "last4": "0005",
      "masked_number": "***********0005",
      "object": "card"
    },
    "created_at": 1517487216,
    "customer_id": "__test__XpbTXGTSRp4Mg0Dr",
    "deleted": false,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__5SK2lMpwSRp4LJJ1y",
    "id": "pm___test__XpbTXGTSRp4Ml3Dv",
    "object": "payment_source",
    "reference_id": "tok___test__XpbTXGTSRp4MkpDu",
    "resource_version": 1517487216756,
    "status": "valid",
    "type": "card",
    "updated_at": 1517487216
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/payment_sources/create_card

## Input Parameters

- `customer_id` (required, string, max chars=50)
  Identifier of the customer with whom this payment source is associated.

- `brand_id` (optional, string, max chars=50)
  The unique ID of the [brand](/docs/api/brands) this payment source should be linked to. Applicable only when multiple brands have been created for the site. This need not match the brand of the `customer_id`; when the two differ, the value provided here is used for the payment source. An alternative way of passing this parameter is by means of the `chargebee-brand-id` custom HTTP header; when both are provided, they must specify the same brand.
  
  **Default behavior**
  
  -   When not provided, the payment source is linked to the brand of the customer it is created for.

- `replace_primary_payment_source` (optional, boolean, default=false)
  Indicates whether the primary payment source should be replaced with this payment source. In case of Create Subscription for Customer endpoint, the default value is True. Otherwise, the default value is False.

- `card` (optional, string)
  Parameters for card
  - `gateway_account_id` (optional, string, max chars=50)
    The gateway account in which this payment source is stored.
  - `first_name` (optional, string, max chars=50)
    Cardholder's first name
  - `last_name` (optional, string, max chars=50)
    Cardholder's last name
  - `number` (required, string, max chars=1500)
    The credit card number without any format. If you are using [Braintree.js](https://developer.paypal.com/braintree/docs/guides/client-sdk/setup/javascript/v2#getting-braintree.js) , you can specify the Braintree encrypted card number here.
  - `expiry_month` (required, integer, min=1, max=12)
    Card expiry month.
  - `expiry_year` (required, integer)
    Card expiry year.
  - `cvv` (optional, string, max chars=520)
    The card verification value (CVV). If you are using [Braintree.js](https://developer.paypal.com/braintree/docs/guides/client-sdk/setup/javascript/v2#getting-braintree.js) , you can specify the Braintree encrypted CVV here.
  - `preferred_scheme` (optional, enumerated string)
    The customer's preferred card scheme for co-branded cards.
    
    **Note**: Currently, this parameter is only supported for Stripe.
    Possible enum values:
      - `cartes_bancaires`
        A Cartes Bancaires card scheme.
      - `mastercard`
        A MasterCard scheme.
      - `visa`
        A Visa card scheme.
  - `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_state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) 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. Is set by Chargebee automatically for US, Canada, India and UAE, if `billing_state_code` is provided.
  - `billing_zip` (optional, string, max chars=20)
    Postal or Zip code, as available in card billing address.
  - `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)
    -   `checkout_com`: While adding a new payment method using [permanent token](/docs/api/payment_sources/create-using-permanent-token) or passing raw card details to Checkout.com, `document` ID and `country_of_residence` are required to support payments through [dLocal](https://www.checkout.com/docs/previous/payments/payment-methods/cards/dlocal).
        
        -   `payer`: User related information.
            -   `country_of_residence`: This is required since the billing country associated with the user's payment method may not be the same as their country of residence. Hence the user's country of residence needs to be specified. The country code should be a [two-character ISO code](https://docs.checkout.com/resources/codes/country-codes).
            -   `document`: Document ID is the user's [identification number](https://docs.dlocal.com/api-documentation/payins-api-reference/country-reference#documents) based on their country.
    -   `bluesnap`: While passing raw card details to BlueSnap, if `fraud_session_id` is added, [additional validation](https://developers.bluesnap.com/docs/fraud-prevention) is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your [BlueSnap fraud session ID](https://developers.bluesnap.com/docs/fraud-prevention#section-implementing-device-data-collector) required to perform anti-fraud validation.
    -   `braintree`: While passing raw card details to Braintree, your `fraud_merchant_id` and the user's `device_session_id` can be added to perform [additional validation](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
            -   `fraud_merchant_id`: Your [merchant ID](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) for fraud detection.
    -   `chargebee_payments`: While passing raw card details to Chargebee Payments, if `fraud_session_id` is added, additional validation is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your Chargebee Payments fraud session ID required to perform anti-fraud validation.
    -   `bank_of_america`: While passing raw card details to Bank of America, your user's `device_session_id` can be added to perform additional validation and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
    -   `ecentric`: This parameter is used to verify and process payment method details in Ecentric. If the `merchant_id` parameter is included, Chargebee will vault it / perform a lookup and verification against this `merchant_id`, overriding the one configured in Chargebee. If tokens and processing occur in the same Merchant GUID, you can just skip this part.
        
        -   `merchant_id`: Merchant GUID where the card is vaulted or need to be vaulted.
    -   `ebanx`: While passing raw card details to EBANX, the user's `document` is required for some countries and `device_session_id` can be added to perform [additional validation](https://developer.ebanx.com/docs/payments/guides/features/device-fingerprint#device-fingerprint) and avoid fraudulent transactions.
        
        -   `payer`: User related information.
            -   `document`: Document is the user's identification number based on their country.
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device

## Returns

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

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