Developer Documentation Chargent API

Chargent Developer API

Chargent has an extensive, PCI compliant API for web site integrations. These web services are available as an extension to the standard SOAP API that Salesforce offers, so they can be called in the same way that you interact with other parts of the Salesforce API.

You can also call Chargent methods directly from inside Salesforce, without a user initiating them in the normal manner, such as from a customized Visualforce interface.

The Chargent web services API requires a Chargent Platform edition license. Please contact us for complete documentation and details.

Chargent API Overview

Chargent's API allows you to programmatically call the following actions:

  • Charge
  • Charge Authorized
  • Authorize
  • Refund
  • Void
  • Register Token
  • Generate Payment Request
  • Parse payment result message and status

For documentation with examples of how to use the Chargent API, please contact us.

Chargent Payment Request

In addition to the API, Chargent's Payment Request feature is a developer toolset that allows you to generate requests for payment to send to your customers, embedding unique links in Email templates or other documents, and customize your own site with an integrated, hosted credit card form.

Testing & Troubleshooting

Testing Callouts

When testing the callouts that Chargent makes, you can't use the HttpCalloutMock class in Salesforce because it has to be done from within the Chargent managed package/namespace. To create sample responses and make sure that your code behaves appropriately, here is a workaround:

Wrap the actually call to Chargent Webservices in a


     code that makes call out here


   //create a transaction record manually or set what ever values need for your test to continue


Uncommitted Work Errors


When building a custom visualforce page that will be using Chargent Webservice Methods to process a charge there is a potential that you may receive an error from Salesforce when executing the Chargent Webservice Method as follows:

       You have uncommitted work pending. Please commit or rollback before calling out


One of the framework requirements when developing on the Salesforce platform is that you cannot perform any DML prior to making a callout to any external service in the same transaction. Chargent Webservices, when executed, makes a callout to the appropriate gateway to process the charge, thus you cannot perform any DML prior to executing a method from Chargent Webservices.


Within the lifecycle of a Visualforce page, each execution of a controller method from the Visualforce page itself is a separate transaction. The key is that individual execution of the method must come from the page and not from the controller.

The following is an example of a minimalistic page and controller. It is intended only to show the typical pattern that causes the issue.

Error Example:

Uncommitted Work Error Example Visualforce page

Uncommitted Work Error Example Controller

When the command button is clicked it executes the update_and_charge() method. That method then updates the Opportunity record and then attempts to execute the charge() method. When the charge() method executes the ChargentWebservices Opportunity_Click method and attempts to make the callout to the gateway you will receive the error message.

The solution is to break up the calls using the oncomplete tag on the command button in conjunction with an apex:actionFunction to call the charge() method. This solution follows:

Working Example

Working Example Visualforce page

Working Example Controller

Notice that on the page we added an apex:actionFunction to call the charge() method in the controller on completion of the update_and_charge() method. Also, we removed the call to the charge() method from the controller that was on line 11 in the error example.

In doing this, on click of the command button the update_and_charge() method is executed which updates the Opportunity and then the transaction finishes and returns control to the page. The page then calls the actionFunction via the oncomplete tag and then executes the charge() method in the controller in a separate transaction without producing any errors.