# Deduct promotional credits

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


[Idempotency Supported](/docs/api/v2/pcv-1/idempotency)

This API call can be used to deduct promotional credits for a customer. [Learn more about Promotional Credits](https://www.chargebee.com/docs/2.0/credit-notes.html#creating-promotional-credits).

For example, if a customer has a credit balance of $20, if you pass the **amount** as $5, then the customer's credit balance would become $15.

If you do not pass any amount as the input parameter then, it will deduct the whole available amount from the credit balance.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/promotional_credits/deduct \
     -u {site_api_key}:\
     -d customer_id="__test__KyVnHhSBWSuFQ4x" \
     -d amount=100 \
     -d description="deduct promotional credits"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PromotionalCredit.Deduct()
		.CustomerId("__test__KyVnHhSBWSuFQ4x")
		.Amount(100)
		.Description("deduct promotional credits")
		.Request();

Customer customer = result.Customer;
PromotionalCredit promotionalCredit = result.PromotionalCredit;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    promotionalcreditAction "github.com/chargebee/chargebee-go/v3/actions/promotionalcredit"
    "github.com/chargebee/chargebee-go/v3/models/promotionalcredit"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := promotionalcreditAction.Deduct(&promotionalcredit.DeductRequestParams{
        CustomerId : "__test__KyVnHhSBWSuFQ4x",
        Amount : chargebee.Int64(100),
        Description : "deduct promotional credits",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PromotionalCredit := res.PromotionalCredit
    }
}
```

#### 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.PromotionalCreditDeductRequest{
    CustomerId : "__test__KyVnHhSBWSuFQ4x",
    Amount : chargebee.Int64(100),
    Description : "deduct promotional credits",
}
  res, err := client.PromotionalCredit.Deduct(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PromotionalCredit := res.PromotionalCredit
    }
}
```

#### 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 = PromotionalCredit.deduct()
            .customerId("__test__KyVnHhSBWSuFQ4x")
            .amount(100L)
            .description("deduct promotional credits")
            .request();

        Customer customer = result.customer();
        PromotionalCredit promotionalCredit = result.promotionalCredit();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.promotionalCredit.PromotionalCredit;
import com.chargebee.v4.models.promotionalCredit.params.PromotionalCreditDeductParams;
import com.chargebee.v4.models.promotionalCredit.responses.PromotionalCreditDeductResponse;

public class PromotionalCreditDeduct {

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

        PromotionalCreditDeductParams params = PromotionalCreditDeductParams.builder()
            .customerId("__test__KyVnHhSBWSuFQ4x")
            .amount(100L)
            .description("deduct promotional credits")
            .build();

        PromotionalCreditDeductResponse response = client.promotionalCredits().deduct(params);

        Customer customer = response.getCustomer();
        PromotionalCredit promotionalCredit = response.getPromotionalCredit();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.promotionalCredit.deduct({
        customer_id: "__test__KyVnHhSBWSuFQ4x",
        amount: 100,
        description: "deduct promotional credits"
    });

    console.log(result);
    const customer = result.customer;
    const promotionalCredit = result.promotional_credit;
} 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->promotionalCredit()->deduct([
    "customer_id" => "__test__KyVnHhSBWSuFQ4x",
    "amount" => 100,
    "description" => "deduct promotional credits"
]);
$customer = $result->customer;
$promotionalCredit = $result->promotional_credit;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PromotionalCredit.deduct(
    cb_client.PromotionalCredit.DeductParams(
        customer_id="__test__KyVnHhSBWSuFQ4x",
        amount=100,
        description="deduct promotional credits"
    )
)
customer = response.customer
promotional_credit = response.promotional_credit
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PromotionalCredit.deduct({
  :customer_id => "__test__KyVnHhSBWSuFQ4x",
  :amount => 100,
  :description => "deduct promotional credits"
})

customer = result.customer
promotional_credit = result.promotional_credit
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "no_card",
    "created_at": 1517501389,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mikel",
    "id": "__test__KyVnHhSBWSuFQ4x",
    "last_name": "Fox",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517501389000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517501389
  },
  "promotional_credit": {
    "amount": 100,
    "closing_balance": 0,
    "created_at": 1517501389,
    "credit_type": "general",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWSuFQ4x",
    "description": "deduct promotional credits",
    "done_by": "full_access_key_v1",
    "id": "pc___test__KyVnHhSBWSuGz52",
    "object": "promotional_credit",
    "type": "decrement"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/promotional_credits/deduct

## Input Parameters

- `customer_id` (required, string, max chars=50)
  Identifier of the customer.

- `amount` (optional, in cents, min=0)
  Promotional credits amount.

- `amount_in_decimal` (optional, string, max chars=33)
  Amount in decimal.

- `currency_code` (required if Multicurrency is enabled, string, max chars=3)
  The currency code (ISO 4217 format) for promotional credit.

- `description` (required, string, max chars=250)
  Detailed description of this promotional credits.

- `credit_type` (optional, enumerated string, default=general)
  Type of promotional credits provided to customer.
  Possible enum values:
    - `loyalty_credits`
      Loyalty Credits
    - `referral_rewards`
      Referral
    - `general`
      General

- `reference` (optional, string, max chars=500)
  Describes why promotional credits were provided.

## Returns

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

- `promotional_credit` (Promotional credit object)
  Resource object representing promotional\_credit
