Skip to content
Last updated

AddTransaction

Add a transaction to the system

Request Parameters

ParameterTypeDescriptionRequired
actionstring"AddTransaction"Required
paymentmethodstringThe payment method of the transaction in system formatRequired
useridintThe ID of the user to apply the transaction toOptional
invoiceidintThe ID of the invoice the transaction is forOptional
transidstringThe unique transaction id for this paymentOptional
datestringThe date of the transaction in your Localisation Format (eg DD/MM/YYYY)Optional
currencyidintThe currency id for the transaction if not associated with a userOptional
descriptionstringThe description of the transactionOptional
amountinfloatThe amount received by the paymentOptional
feesfloatThe amount of fee charged on the transaction by the merchant - This can be negativeOptional
amountoutfloatThe amount paid out by the paymentOptional
ratefloatThe exchange rate for the payment based on the default currencyOptional
creditboolShould the payment be applied to credit on the client account. Invoice ID must not be provided.Optional
allowduplicatetransidboolShould an already existing transaction id be allowed. Defaults to false.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error

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' => 'AddTransaction',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'paymentmethod' => 'paypal',
            'userid' => '1',
            'transid' => 'FJWEK32DWO329JFW',
            'date' => '01/01/2016',
            'description' => 'A sample API payment',
            'amountin' => '10.00',
            'fees' => '0.89',
            'rate' => '1.00000',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'AddTransaction';
$postData = array(
    'paymentmethod' => 'paypal',
    'userid' => '1',
    'transid' => 'FJWEK32DWO329JFW',
    'date' => '01/01/2016',
    'description' => 'A sample API payment',
    'amountin' => '10.00',
    'fees' => '0.89',
    'rate' => '1.00000',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

Example Response JSON

{
    "result": "success"
}

Error Responses

Possible error condition responses include:

  • Client ID Not Found
  • Invoice ID Not Found
  • User ID does not own the given Invoice ID
  • Currency ID Not Found
  • Currency ID does not match Client currency
  • A Currency ID is required for non-customer related transactions
  • Payment Method is required
  • Transaction ID must be Unique

Version History

VersionChangelog
1.0Initial Version