# Copy card

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


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

#### deprecated[](#deprecated)

The [Payment Sources API](/docs/api/payment_sources) , with its additional options and improvements, obsoletes the Cards APIs. This request is obsoleted by the [Export payment source API](/docs/api/payment_sources/export-payment-source) .

Copies the customer's card information to another payment gateway. This is useful if you want to port your customer's card details to another gateway.

**Limitation**

This request does not support copying of cards between Braintree and Stripe payment gateways. Contact [Chargebee Support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to perform those actions.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__XpbTXGTSRp3BmqCG/copy_card \
     -u {site_api_key}:\
     -d gateway_account_id="gw___test__5SK2lMgOSRp3BhV2u"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Card.CopyCardForCustomer("__test__XpbTXGTSRp3BmqCG")
		.GatewayAccountId("gw___test__5SK2lMgOSRp3BhV2u")
		.Request();

ThirdPartyPaymentMethod thirdPartyPaymentMethod = result.ThirdPartyPaymentMethod;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    cardAction "github.com/chargebee/chargebee-go/v3/actions/card"
    "github.com/chargebee/chargebee-go/v3/models/card"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := cardAction.CopyCardForCustomer("__test__XpbTXGTSRp3BmqCG", &card.CopyCardForCustomerRequestParams{
        GatewayAccountId : "gw___test__5SK2lMgOSRp3BhV2u",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        ThirdPartyPaymentMethod := res.ThirdPartyPaymentMethod
    }
}
```

#### 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.CardCopyCardForCustomerRequest{
    GatewayAccountId : "gw___test__5SK2lMgOSRp3BhV2u",
}
  res, err := client.Card.CopyCardForCustomer("__test__XpbTXGTSRp3BmqCG", req)
      if err != nil {
        fmt.Println(err)
    } else {
        ThirdPartyPaymentMethod := res.ThirdPartyPaymentMethod
    }
}
```

#### 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 = Card.copyCardForCustomer("__test__XpbTXGTSRp3BmqCG")
            .gatewayAccountId("gw___test__5SK2lMgOSRp3BhV2u")
            .request();

        ThirdPartyPaymentMethod thirdPartyPaymentMethod = result.thirdPartyPaymentMethod();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.params.CopyCardForCustomerParams;
import com.chargebee.v4.models.card.responses.CopyCardForCustomerResponse;
import com.chargebee.v4.models.thirdPartyPaymentMethod.ThirdPartyPaymentMethod;

public class CopyCardForCustomer {

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

        CopyCardForCustomerParams params = CopyCardForCustomerParams.builder()
            .gatewayAccountId("gw___test__5SK2lMgOSRp3BhV2u")
            .build();

        CopyCardForCustomerResponse response = client
            .cards()
            .copyCardForCustomer("__test__XpbTXGTSRp3BmqCG", params);

        ThirdPartyPaymentMethod thirdPartyPaymentMethod = response.getThirdPartyPaymentMethod();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.card.copyCardForCustomer("__test__XpbTXGTSRp3BmqCG", {
        gateway_account_id: "gw___test__5SK2lMgOSRp3BhV2u"
    });

    console.log(result);
    const thirdPartyPaymentMethod = result.third_party_payment_method;
} 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->card()->copyCardForCustomer("__test__XpbTXGTSRp3BmqCG", [
    "gateway_account_id" => "gw___test__5SK2lMgOSRp3BhV2u"
]);
$thirdPartyPaymentMethod = $result->third_party_payment_method;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Card.copy_card_for_customer("__test__XpbTXGTSRp3BmqCG",
    cb_client.Card.CopyCardForCustomerParams(
        gateway_account_id="gw___test__5SK2lMgOSRp3BhV2u"
    )
)
third_party_payment_method = response.third_party_payment_method
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Card.copy_card_for_customer("__test__XpbTXGTSRp3BmqCG",{
  :gateway_account_id => "gw___test__5SK2lMgOSRp3BhV2u"
})

third_party_payment_method = result.third_party_payment_method
```

## Sample Response

```json
{
  "third_party_payment_method": {
    "gateway": "stripe",
    "gateway_account_id": "gw___test__5SK2lMgOSRp3BhV2u",
    "object": "third_party_payment_method",
    "reference_id": "cus_J7rQxbSaNyG7Sd/card_1IVbhqJv9j0DyntJeFVNQdcz",
    "type": "card"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/customers/{customer-id}/copy_card

## Input Parameters

- `gateway_account_id` (required, string, max chars=50)
  The gateway account you want to copy the card.

## Returns

- `third_party_payment_method` (Third party payment method object)
  Resource object representing third\_party\_payment\_method
