Skip to main content

Payment Authorization Reversal

Overview

Prerequisites

There is one prerequisite resource that must be created before requesting a payment refund.

           Object           Definition
Chargent TransactionTransactions record the results of the requests made to the payment gateway on the Chargent Order. Transactions are also used to make additional requests in the payments lifecycle.

Create Payment Authorization Reversal

Apex Example
try {
// Get the last Chargent Order to use
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];
Id lastChargentOrderId = lastChargentOrder.Id;

try {
// Get the last authorization transaction
ChargentOrders__Transaction__c lastAuthorizationTransaction = [SELECT Id FROM ChargentOrders__Transaction__c WHERE ChargentOrders__Order__c = :lastChargentOrderId ORDER BY CreatedDate DESC LIMIT 1];

try {
Map<String, Object> paymentCaptureMap = new Map<String, Object>();
paymentCaptureMap.put('authorizationId', lastAuthorizationTransaction.Id);

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

// process request
if (actionResponseMap.get('operationSuccess') == false) {
// Failure
System.debug('Payment Authorization Reversal create error.');
} else {
// Success
System.debug('Payment Authorization Reversal created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Payment Authorization Reversal: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Transaction: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}

Learn More

Learn more about Payment Reversals.