# Local delete a payment source

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


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

Delete a **payment source** reference from a Chargebee customer without deleting or altering payment source data stored at the payment gateway.

### Impacts

**

Payment Source

**

Sets `deleted` = `true` on the specified `payment_source` and detaches it from the customer. The payment source is no longer accessible through the API or the UI.

**

Customer

**

If the deleted `payment_source` is the customer's only payment method and [`auto_collection`](/docs/api/customers/customer-object#auto_collection) is `on`, [automatic payment collection](https://www.chargebee.com/docs/billing/2.0/customers/customers#auto-collection-status) for future invoices fails.

If the deleted payment source was the [primary](/docs/api/customers/customer-object#primary_payment_source_id) payment method for the customer, and a [backup](/docs/api/customers/customer-object#backup_payment_source_id) exists, Chargebee promotes the backup to primary.

If no backup is set but other `payment_source` objects exist for the [customer](/docs/api/payment_sources/payment_source-object#customer_id), Chargebee promotes one of them to primary.

**

Subscription

**

When you delete a payment source [linked](/docs/api/subscriptions/subscription-object#payment_source_id) to an active [subscription](/docs/api/subscriptions), Chargebee immediately clears the `payment_source_id` on that subscription. Future charges use the customer's `primary_payment_source_id`.

#### Related APIs

Delete a payment source

List payment sources

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/pm___test__XpbTXGTSRp4V0hEw/delete_local \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.DeleteLocal("pm___test__XpbTXGTSRp4V0hEw").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"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentsourceAction.DeleteLocal("pm___test__XpbTXGTSRp4V0hEw").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)
  
  res, err := client.PaymentSource.DeleteLocal("pm___test__XpbTXGTSRp4V0hEw")
      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.deleteLocal("pm___test__XpbTXGTSRp4V0hEw").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.PaymentSourceDeleteLocalParams;
import com.chargebee.v4.models.paymentSource.responses.PaymentSourceDeleteLocalResponse;

public class PaymentSourceDeleteLocal {

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

        PaymentSourceDeleteLocalResponse response = client.paymentSources().deleteLocal("pm___test__XpbTXGTSRp4V0hEw");

        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.deleteLocal("pm___test__XpbTXGTSRp4V0hEw");

    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()->deleteLocal("pm___test__XpbTXGTSRp4V0hEw");
$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.delete_local("pm___test__XpbTXGTSRp4V0hEw")
customer = response.customer
payment_source = response.payment_source
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PaymentSource.delete_local("pm___test__XpbTXGTSRp4V0hEw")

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

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "no_card",
    "created_at": 1517487247,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp4UhfEv",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517487248592,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517487248
  },
  "payment_source": {
    "card": {
      "brand": "visa",
      "expiry_month": 12,
      "expiry_year": 2022,
      "funding_type": "credit",
      "iin": "411111",
      "last4": "1111",
      "masked_number": "************1111",
      "object": "card"
    },
    "created_at": 1517487248,
    "customer_id": "__test__XpbTXGTSRp4UhfEv",
    "deleted": true,
    "gateway": "stripe",
    "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
    "id": "pm___test__XpbTXGTSRp4V0hEw",
    "issuing_country": "US",
    "object": "payment_source",
    "reference_id": "cus_J7rVsWKqWFpyBS/card_1IVbmmJv9j0DyntJVAKlFn5a",
    "resource_version": 1517487248475,
    "status": "valid",
    "type": "card",
    "updated_at": 1517487248
  }
}
```

## URL Format

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

## Returns

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

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