Skip to main content

Payment Authorization

Overview

A payment authorization results in a hold on funds on future payment. Authorizations are for payment methods with credit card type only.

Prerequisite Resources

There are multiple prerequisite resources depending on the call method that must be created before requesting a payment authorization.

           Object           Definition
AccountSalesforce standard Account object.
Chargent OrderChargent Orders are central objects to payments lifecycle management.
Payment MethodPayment Methods are instruments that may be used to make or take payment.
Payment GatewayPayment Gateways track all the configuration settings that Chargent will use to proccess the payments and send requests to the gateway.

Create Methods

There are multiple methods available using input data to create a payment authorization. A payment gateway must exist for all create payment authorization methods.

PrerequisitesInputOutput
Chargent Order, Payment Method (Assigned)chargentOrderIDChargent Transaction
Chargent OrderchargentOrderID, paymentGatewayIdPayment Method Tokenization, Chargent Transaction
Chargent Order, Payment MethodchargentOrderID, paymentMethodId, paymentGatewayIdChargent Transaction
Chargent Order, Payment MethodchargentOrderID, paymentMethodIdChargent Transaction
AccountaccountId, paymentGatewayIdChargent Order, Payment Method Tokenization, Chargent Transaction
Account, Payment MethodaccountId, paymentMethodId, paymentGatewayIdChargent Order, Chargent Transaction

Transaction Fields

Learn more about Chargent Transaction Fields.

Create Payment Authorization

Resource URL

HTTP RequestURL
POST/services/apexrest/ChargentBase/payments/authorizations

chargentOrderId

Apex Example
try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('chargentOrderId', lastChargentOrder.Id);
paymentAuthorizationMap.put('amount', 200.00); //optional
paymentAuthorizationMap.put('currencyIsoCode', 'USD'); //optional
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization orderId'); //optional

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}

chargentOrderId, paymentGatewayId

Apex Example
try {
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = 'Stripe Test' LIMIT 1];

try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
// initialize variables
String phone = '{{$randomPhoneNumber}}';
String email = '{{$randomeEmail}}';

String cardNumber = '{{cardNumber}}';
String cardType = '{{cardType}}';
String cvv = '{{cvv}}';
String expiryMonth = String.valueOf(Date.today().month());
String expiryYear = String.valueOf(Date.today().year() + 3);

// credit card payment data
Map<String,Object> cardPaymentMethodMap = new Map<String, Object>();
cardPaymentMethodMap.put('cardType', cardType);
cardPaymentMethodMap.put('cardNumber', cardNumber);
cardPaymentMethodMap.put('expiryMonth', expiryMonth);
cardPaymentMethodMap.put('expiryYear', expiryYear);
cardPaymentMethodMap.put('cvv', cvv);
cardPaymentMethodMap.put('cardHolderName', 'Chargent Test');
cardPaymentMethodMap.put('cardHolderFirstName', 'Chargent');
cardPaymentMethodMap.put('cardHolderLastName', 'Test');

// billing address
Map<String,Object> addressMap = new Map<String, Object>();
addressMap.put('street', '123 Street St');
addressMap.put('state', 'California');
addressMap.put('city', 'San Francisco');
addressMap.put('postalcode', '94105');
addressMap.put('country', 'US');
addressMap.put('companyName', 'Chargent Test');

// payment method tokenization
Map<String,Object> paymentRequestMap = new Map<String, Object>();
paymentRequestMap.put('cardPaymentMethod', cardPaymentMethodMap);
paymentRequestMap.put('address', addressMap);

Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('chargentOrderId', lastChargentOrder.Id);
paymentAuthorizationMap.put('paymentGatewayId', paymentGateway.Id);
paymentAuthorizationMap.put('paymentMethod', paymentRequestMap);

paymentAuthorizationMap.put('amount', 300.00); //optional
paymentAuthorizationMap.put('currencyIsoCode', 'USD'); //optional
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization orderId gatewayId'); //optional

paymentAuthorizationMap.put('phone', phone); // optional
paymentAuthorizationMap.put('email', email); // optional

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Gateways: ' + e.getMessage());
}

chargentOrderId, paymentMethodId, paymentGatewayId

Apex Example
try {
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = 'Stripe Test' LIMIT 1];

try {
// Get the last payment method
ChargentBase__Payment_Method__c lastPaymentMethod = [SELECT Id FROM ChargentBase__Payment_Method__c WHERE ChargentBase__Name_on_Account__c = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('paymentGatewayId', paymentGateway.Id);
paymentAuthorizationMap.put('chargentOrderId', lastChargentOrder.Id);
paymentAuthorizationMap.put('amount', 400.00); // optional
paymentAuthorizationMap.put('currencyIsoCode', 'USD'); //optional
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization orderId paymentMethodId gatewayId'); //optional

Map<String, Object> paymentMethodMap = new Map<String, Object>();
paymentMethodMap.put('id', lastPaymentMethod.Id);
paymentAuthorizationMap.put('paymentMethod', paymentMethodMap);

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Method: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Gateways: ' + e.getMessage());
}

chargentOrderId, paymentMethodId

Apex Example
try {
// Get the last payment method
ChargentBase__Payment_Method__c lastPaymentMethod = [SELECT Id FROM ChargentBase__Payment_Method__c WHERE ChargentBase__Name_on_Account__c = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('chargentOrderId', lastChargentOrder.Id);
paymentAuthorizationMap.put('amount', 500.00); //optional
paymentAuthorizationMap.put('currencyIsoCode', 'USD'); //optional
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization orderId paymentMethodId'); //optional

Map<String, Object> paymentMethodMap = new Map<String, Object>();
paymentMethodMap.put('id', lastPaymentMethod.Id);
paymentAuthorizationMap.put('paymentMethod', paymentMethodMap);

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Method: ' + e.getMessage());
}

accountId, paymentGatewayId

Apex Example
try {
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = 'Stripe Test' LIMIT 1];

try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
// initialize variables
String phone = '{{$randomPhoneNumber}}';
String email = '{{$randomeEmail}}';

String cardNumber = '{{cardNumber}}';
String cardType = '{{cardType}}';
String cvv = '{{cvv}}';
String expiryMonth = String.valueOf(Date.today().month());
String expiryYear = String.valueOf(Date.today().year() + 3);

// credit card payment data
Map<String,Object> cardPaymentMethodMap = new Map<String, Object>();
cardPaymentMethodMap.put('cardType', cardType);
cardPaymentMethodMap.put('cardNumber', cardNumber);
cardPaymentMethodMap.put('expiryMonth', expiryMonth);
cardPaymentMethodMap.put('expiryYear', expiryYear);
cardPaymentMethodMap.put('cvv', cvv);
cardPaymentMethodMap.put('cardHolderName', 'Chargent Test');
cardPaymentMethodMap.put('cardHolderFirstName', 'Chargent');
cardPaymentMethodMap.put('cardHolderLastName', 'Test');

// billing address
Map<String,Object> addressMap = new Map<String, Object>();
addressMap.put('street', '123 Street St');
addressMap.put('state', 'California');
addressMap.put('city', 'San Francisco');
addressMap.put('postalcode', '94105');
addressMap.put('country', 'US');
addressMap.put('companyName', 'Chargent Test');

// payment method tokenization
Map<String,Object> paymentRequestMap = new Map<String, Object>();
paymentRequestMap.put('cardPaymentMethod', cardPaymentMethodMap);
paymentRequestMap.put('address', addressMap);

Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('accountId', lastChargentOrder.ChargentOrders__Account__c);
paymentAuthorizationMap.put('paymentGatewayId', paymentGateway.Id);
paymentAuthorizationMap.put('paymentMethod', paymentRequestMap);

paymentAuthorizationMap.put('amount', 600.00); //optional
paymentAuthorizationMap.put('currencyIsoCode', 'USD'); //optional
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization accountId gatewayId'); //optional

paymentAuthorizationMap.put('phone', phone); // optional
paymentAuthorizationMap.put('email', email); // optional

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Gateways: ' + e.getMessage());
}

accountId, paymentMethodId, paymentGatewayId

Apex Example
try {
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = 'Stripe Test' LIMIT 1];

try {
// Get the last payment method
ChargentBase__Payment_Method__c lastPaymentMethod = [SELECT Id FROM ChargentBase__Payment_Method__c WHERE ChargentBase__Name_on_Account__c = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

try {
ChargentOrders__ChargentOrder__c lastChargentOrder = [SELECT Id, ChargentOrders__Account__c, ChargentOrders__Payment_Method_Default__c FROM ChargentOrders__ChargentOrder__c WHERE ChargentOrders__Payment_Descriptor__c LIKE 'Chargent Test%' ORDER BY CreatedDate DESC LIMIT 1];

try {
Map<String, Object> paymentAuthorizationMap = new Map<String, Object>();
paymentAuthorizationMap.put('accountId', lastChargentOrder.ChargentOrders__Account__c);
paymentAuthorizationMap.put('paymentGatewayId', paymentGateway.Id);
paymentAuthorizationMap.put('amount', 700.00);
paymentAuthorizationMap.put('currencyIsoCode', 'USD');
paymentAuthorizationMap.put('comments', 'Chargent Test Payment Authorization accountId paymentMethodId gatewayId');

Map<String, Object> paymentMethodMap = new Map<String, Object>();
paymentMethodMap.put('id', lastPaymentMethod.Id);
paymentAuthorizationMap.put('paymentMethod', paymentMethodMap);

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentAuthorizationMap);
actionsMap.put('action', 'Authorization');
actionsMap.put('feature', 'APEX');
String actionResponse = ChargentBase.ActionService.getService().performAction(JSON.serialize(actionsMap));
Map<String, Object> actionResponseMap = (Map<String, Object>) JSON.deserializeUntyped(actionResponse);

// process response
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
try {
System.debug('Payment Authorization Token create error.');
// unpack the message
List<Object> operationResponsesList = (List<Object>) actionResponseMap.get('operationResponsesList');
Map<String, Object> operationResponseItem = (Map<String, Object>) operationResponsesList.get(0);
// debug chargent error
Map<String, Object> errorItem = (Map<String, Object>) operationResponseItem.get('errorItem');
String chargentErrorType = (String) errorItem.get('errorType');
System.debug('Chargent Error Type: ' + chargentErrorType);
String chargentErrorMessage = (String) errorItem.get('message');
System.debug('Chargent Error Message: ' + chargentErrorMessage);
// debug gateway error
Map<String, Object> gatewayResponseMap = (Map<String, Object>) operationResponseItem.get('gatewayResponseMap');
Map<String, Object> gateway = (Map<String, Object>) gatewayResponseMap.get('unique');
Map<String, Object> calloutResponse = (Map<String, Object>) gateway.get('webOutPut');
String gatewayStatus = (String) calloutResponse.get('Status');
System.debug('Gateway Status: ' + gatewayStatus);
String gatewayMessage = (String) calloutResponse.get('Message');
System.debug('Gateway Message: ' + gatewayMessage);
String gatewayReasonCode = (String) calloutResponse.get('ReasonCode');
System.debug('Gateway Code: ' + gatewayReasonCode);
} catch (Exception e) {
System.debug('Error unpacking Action Service response: ' + e.getMessage());
}
} else {
// Success
System.debug('Payment Authorization created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Method: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Payment Gateways: ' + e.getMessage());
}

Learn More

Learn more about Payment Authorizations.