Creating Credit and Rebill Credit Memos

This API allows you to credit an entire invoice and rebill it. However, this API does not calculate tax for the credit memo. You must call the calculateTaxForCreditRebill API after calling the createCreditRebill API to calculate tax for the credit memo.

APISignature
createCreditRebillstatic Map createCreditRebill(Id invoiceId, Boolean autoApproveCreditMemo)

This API accepts the following input parameters. 

Request

Field

Type

Required?

Description

invoiceId

IDYes

ID of the invoice.

autoApproveCreditMemoBooleanYesIf set to true, Conga Billing auto-approves credit memos.
unrateUsageInputsBooleanNoIf set to true, Conga Billing unrates usage inputs.

The API returns a Map<String, Value> as a response parameter.

Response

Field

Type

Description

Result

MapThe result map contains the success string and a value

If the API executes successfully, the value contains the following keys: 

  • success - set to true
  • creditMemoId - the ID of the created credit memo

If the API is not executed successfully, the value contains the following keys: 

  • success - set to false
  • errorMessage - contains the error message
  • stackTrace - contains the stackTrace of the error details

Calculating Tax for Credit and Rebill

This API allows you to calculate tax for credit memo generated by the createCreditRebill API.

You must call the calculateTaxForCreditRebill API after calling the createCreditRebill API, when you have defined the TestTaxCallbackWithExternalCallout callback class in Setup > Develop > Custom Settings > Config Custom Classes > Tax Callback Class. You must pass values for both Auto Approve credit memo and Unrate the usage inputs options (True or False).

APISignature
calculateTaxForCreditRebillstatic Map calculateTaxForCreditRebill(Id creditMemoId, Boolean autoApproveCreditMemo, Boolean unrateUsageInputs)

This API accepts the following input parameters. 

Request

Field

Type

Required?

Description

creditMemoId

IdYes

ID of the credit memo.

autoApproveCreditMemoBooleanYesIf set to true, Conga Billing auto-approves credit memos.
unrateUsageInputsBooleanYesIf set to true, Conga Billing unrates usage inputs.

The API returns a Map<String, Value> as a response parameter.

Response

Field

Type

Description

Result

MapThe result map contains the success string and a value

If the API executes successfully, the value contains the following keys: 

  • success - set to true
  • creditMemoId - the ID of the created credit memo

If the API is not executed successfully,  the value contains the following keys: 

  • success - set to false
  • errorMessage - contains the error message
  • stackTrace - contains the stackTrace of the error details

Code Sample 

public class CreateCreditRebillWithTaxCalculate{
 

    public static void createCreditRebill(Id invoiceId, Boolean autoApproveCreditMemo, Boolean unrateUsageInputs){
        Map<String, Object> response = Apttus_Billing.BillingService.createCreditRebill(invoiceId, // Invoice Id
                                                 autoApproveCreditMemo, // Auto Approve Credit Memo flag (true/false)
                                                 unrateUsageInputs // Unrate usage input flag (true/false)
                                                 );
        
        System.debug('=========='+response);

        Boolean isSuccess = (Boolean)response.get('success');
        Id creditMemoId = (Id)response.get('creditMemoId');

 

        // Call "calculateTax" method only if Tax callback is registered
        if(isSuccess){
            // Call tax calculation from Async method having callout=true if tax callback is calling external callout
            // Call tax calculation from sync method if tax callback is not calling external callout
            CreateCreditRebillWithTaxCalculate.calculateTax(creditMemoId, autoApproveCreditMemo, unrateUsageInputs);
        }
    }

    @future(callout=true)
    public static void calculateTax(Id creditMemoId, Boolean autoApproveCreditMemo, Boolean unrateUsageInputs){
        Map<String, Object> response = Apttus_Billing.BillingService.calculateTaxForCreditRebill(creditMemoId, // Credit memo Id
                                                         autoApproveCreditMemo, // Auto Approve Credit Memo flag (true/false)
                                                         unrateUsageInputs // Unrate usage input flag (true/false)
                                                         );
        System.debug('=========='+response);
    } 
}


// Call above class method from executing below line from Developer Console.
CreateCreditRebillWithTaxCalculate.createCreditRebill('a5T8B000000LXZG', // Invoice Id
                                                      false, // Auto Approve Credit Memo flag (true/false)
                                                      false // Unrate usage input flag (true/false)
                                                      );
CODE