# Switch gateway

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


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

#### Deprecated[](#deprecated)

This request is obsoleted by the [Switch gateway account API](/docs/api/payment_sources/switch-gateway-account) for Payment Sources.

Switches the gateway in which customer's card information is stored. This is applicable only if the payment method is `card`.

**Limitation**

This request does not support switching 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__XpbTXGTSRp3EldCh/switch_gateway \
     -u {site_api_key}:\
     -d gateway_account_id="gw___test__5SK2lMgOSRp3EaR32"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Card.SwitchGatewayForCustomer("__test__XpbTXGTSRp3EldCh")
		.GatewayAccountId("gw___test__5SK2lMgOSRp3EaR32")
		.Request();

Customer customer = result.Customer;
Card card = result.Card;
```

#### 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.SwitchGatewayForCustomer("__test__XpbTXGTSRp3EldCh", &card.SwitchGatewayForCustomerRequestParams{
        GatewayAccountId : "gw___test__5SK2lMgOSRp3EaR32",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        Card := res.Card
    }
}
```

#### 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.CardSwitchGatewayForCustomerRequest{
    GatewayAccountId : "gw___test__5SK2lMgOSRp3EaR32",
}
  res, err := client.Card.SwitchGatewayForCustomer("__test__XpbTXGTSRp3EldCh", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        Card := res.Card
    }
}
```

#### 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.switchGatewayForCustomer("__test__XpbTXGTSRp3EldCh")
            .gatewayAccountId("gw___test__5SK2lMgOSRp3EaR32")
            .request();

        Customer customer = result.customer();
        Card card = result.card();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.card.params.CardSwitchGatewayForCustomerParams;
import com.chargebee.v4.models.card.responses.CardSwitchGatewayForCustomerResponse;
import com.chargebee.v4.models.customer.Customer;

public class CardSwitchGatewayForCustomer {

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

        CardSwitchGatewayForCustomerParams params = CardSwitchGatewayForCustomerParams.builder()
            .gatewayAccountId("gw___test__5SK2lMgOSRp3EaR32")
            .build();

        CardSwitchGatewayForCustomerResponse response = client
            .cards()
            .switchGatewayForCustomer("__test__XpbTXGTSRp3EldCh", params);

        Customer customer = response.getCustomer();
        Card card = response.getCard();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.card.switchGatewayForCustomer("__test__XpbTXGTSRp3EldCh", {
        gateway_account_id: "gw___test__5SK2lMgOSRp3EaR32"
    });

    console.log(result);
    const customer = result.customer;
    const card = result.card;
} 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()->switchGatewayForCustomer("__test__XpbTXGTSRp3EldCh", [
    "gateway_account_id" => "gw___test__5SK2lMgOSRp3EaR32"
]);
$customer = $result->customer;
$card = $result->card;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Card.switch_gateway_for_customer("__test__XpbTXGTSRp3EldCh",
    cb_client.Card.SwitchGatewayForCustomerParams(
        gateway_account_id="gw___test__5SK2lMgOSRp3EaR32"
    )
)
customer = response.customer
card = response.card
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Card.switch_gateway_for_customer("__test__XpbTXGTSRp3EldCh",{
  :gateway_account_id => "gw___test__5SK2lMgOSRp3EaR32"
})

customer = result.customer
card = result.card
```

## Sample Response

```json
{
  "card": {
    "card_type": "visa",
    "created_at": 1517486948,
    "customer_id": "__test__XpbTXGTSRp3EldCh",
    "expiry_month": 12,
    "expiry_year": 2022,
    "funding_type": "not_known",
    "gateway": "pin",
    "gateway_account_id": "gw___test__5SK2lMgOSRp3EaR32",
    "iin": "411111",
    "last4": "1111",
    "masked_number": "************1111",
    "object": "card",
    "payment_source_id": "pm___test__XpbTXGTSRp3EwGCi",
    "resource_version": 1517486948483,
    "status": "valid",
    "updated_at": 1517486948
  },
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517486947,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp3EldCh",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "payment_method": {
      "gateway": "pin",
      "gateway_account_id": "gw___test__5SK2lMgOSRp3EaR32",
      "object": "payment_method",
      "reference_id": "EjZ45aBUKGOreGY1J5mObk2uJdp",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__XpbTXGTSRp3EwGCi",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517486948481,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517486948
  }
}
```

## URL Format

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

## Input Parameters

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

## Returns

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

- `card` (Card object)
  Resource object representing card
