Skip to main content

Chargent Order Credit

Overview

A credit transaction may be used to apply a credit to a bank account without a prior transaction.

Prequisites

Conditions

  1. The payment gateway must support bank account credits without a prior transaction.
  2. The Gateway Setup Wizard advanced settings must be used to configure the payment gateway.
  3. A Chargent Order must be created with the Credit Amount field set to the amount to credit the bank account.
  4. A Payment Method with bank account type must be assigned to the Chargent Order.

Resources

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

           Object           Definition
Chargent OrderChargent Orders are central objects to payments lifecycle management.
Payment MethodPayment Methods are instruments that may be used to make or take payment.

Workflow

StepResult
Create Credit Chargent OrderA Chargent Order is created with a credit amount.
Create Payment Method Tokenization A Payment Method Tokenization is created with a bank account type.
Assign Payment Method to Chargent Order A Payment Method with a bank account type is assigned to a Chargent Order with a credit amount.

Create Chargent Order Credit

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 {
Map<String, Object> paymentRefundMap = new Map<String, Object>();
paymentRefundMap.put('objectId', lastChargentOrderId);

Map<String, Object> actionsMap = new Map<String, Object>();
actionsMap.put('data', paymentRefundMap);
actionsMap.put('action', 'Credit');
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('Chargent Order Credit create error.');
} else {
// Success
System.debug('Chargent Order Credit created successfully.');
}
} catch (Exception e) {
System.debug('Error creating Chargent Order Credit: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}

Learn More

Learn more about Sending Credits.