> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AutoBill.grantCredit

The `grantCredit` method adds credit to an `AutoBill` object. With credit available to an `Account`, you may extend the life of an `AutoBill` object, thus allowing a customer to keep their subscription active.

* Token-based credit may be granted to an AutoBill to pay for billing transactions. To grant Token-based credit to an AutoBill, the credit must be of the same token type as the Payment Method on the AutoBill, and the BillingPlan must also be defined in terms of the same Token Type. Token Credits granted will be deducted from the amount billed to the AutoBill's payment method at the next billing cycle.
* You may also grant time-based credit to an `AutoBill`. With a `TimeInterval` object, define a time extension to be given to an `AutoBill` in terms of years, months, weeks, or days. When you grant time credit to an `AutoBill`, Subscribe delays the next billing for the `AutoBill` by the specified amount of time, similar to calling `delayBillingByDays()` on an `AutoBill` object. This delay does not occur until the billing date following the time credit grant. Until then, the time credit remains on the AutoBill, and the next billing date appears unchanged. Note that Subscribe does not generate a transaction to account for such a time-based credit grant.
* When granting a currency credit to an `AutoBill`, the currency (i.e. USD) for the credit grants must be the same as the currency the customer has specified for the `AutoBill`.
* Time and Currency Credits may be tracked by `timestamp` and `sortValue`. When granted, they are assigned a VID, which may be used when revoking credit.

See the [Credit Subobject](Credit_Subobject) for a list of data members of the `Credit` object and related subobjects. See Credit Grants and Gift Cards in the Subscribe Programming Guide for more information.

## Input

*srd*: sparse response description, a SOAP string (which must be a JSON object), in which you specify the elements you want returned.This parameter enables the calling system to constrain a `method` call to return only components you specify. This gives you greater control over returned content, and improves response time within the Vindicia platform by reducing the processing needed for the call.

Some fields are required, either practically or in the WSDL, and will be returned regardless of the *srd*. A null *srd* returns the complete response.

*autobill*: an `AutoBill` object to which you wish to grant credit. Identify the `AutoBill` using its or `VID`.

*credit*: a `Credit` object specifying the amount and type of credit you wish to grant to the `AutoBill`.

*note*: an optional note regarding the credit granted.

## Output

*return*: an object of type `Return` that indicates the success or failure of the call.

*autobill*: the `AutoBill` object to which you granted credit. This object contains the updated array of `Credit` objects.

## Returns

In addition to those listed in [The Return Object](Subscribe_API_Overview_1), this call returns:

| Return Code | Return String |
| - | - |
| `400` | One of the following: - `AutoBill not found.` - `Failed to translate credit *error-description*.` - `Failed to grant credit *error-description*.` - `Failed to save AutoBill after granting credit.` - `Failed to reload AutoBill after granting credit *error-description*.` - `Time interval credit cannot have amount 0.` |

## Example

```

$abill = new AutoBill();

// autobill id for an existing subscription

$abill->set('SBCR312345');

// We want to grant 2 days of credit
$time = new TimeInterval();
$time->setDays(’2’);

$cr = new Credit();
$cr->setTimeIntervals(array($time));
$note = “optional note explaining credit grant”;

// Now make the SOAP API call to grant credit to the autobill
$response = $abill->grantCredit($cr,$note);

if ($response['returnCode'] == 200) {

   // Credit successfully granted to the autobill

   $updatedABill = $response['data']->autobill;
   print "Current entitlements are valid till: ";
   print $updatedABill->getEndDate() . "\n";

}
else {
   // Error while granting credit to the account

   print $response['returnString'] . "\n";
}
```

**Parent topic:**[AutoBill Methods](../topics/AutoBill_Methods)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.