Skip to content
Last updated

ApplyCredit

Applies the Client's Credit to an invoice

Request Parameters

ParameterTypeDescriptionRequired
actionstring"ApplyCredit"Required
invoiceidintThe ID of the invoice to apply creditRequired
amountfloat|stringThe amount of credit to apply to the invoice.Optional
noemailboolSet to true to stop the invoice payment email being sent if the invoice becomes paidOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
invoiceidintThe id of the invoice the credit has been applied to
amountfloatThe amount of credit applied
invoicepaidstringtrue/false string

Example Request (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'ApplyCredit',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'invoiceid' => '1',
            'amount' => '10.00',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'ApplyCredit';
$postData = array(
    'invoiceid' => '1',
    'amount' => '10.00',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

Example Response JSON

{
    "result": "success",
    "invoiceid": "1",
    "amount": "10.00",
    "invoicepaid": "false"
}

Error Responses

Possible error condition responses include:

  • Invoice ID Not Found
  • Invoice Not in Unpaid Status
  • Amount exceeds customer credit balance
  • Amount Exceeds Invoice Balance
  • Credit Amount to apply must be greater than zero

Version History

VersionChangelog
1.0Initial Version