Skip to main content

Chargent Order

Overview​

Chargent Orders contain information related to the order such as billing information, total amount, due balance, and charge amount. They are central objects to payments lifecycle management.

Order Types​

There are multiple types of Chargent Orders.

TypeDefinition
Recurring BillingRecurring Billing takes payment according to a schedule. Learn more about Recurring Billing
One-time PaymentThis order configuration may be used for processing payment on an order one of more times.
CreditFor Payment Methods with bank account type, and a Chargent Order with a Credit Amount, credits may be sent to the bank account. Note: Must be supported by the Payment Gateway.

Order Fields​

Learn more about Chargent Order Fields.

Create Recurring Chargent Order​

Apex Example
try {
// Get payment gateway to use
String paymentGatewayName = 'Stripe Test';
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = :paymentGatewayName ORDER BY CreatedDate DESC LIMIT 1];

try {
// get the last account
Account lastCreatedAccount = [SELECT Id FROM Account WHERE Name = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

ChargentOrders__ChargentOrder__c newOrder = new ChargentOrders__ChargentOrder__c();
newOrder.ChargentOrders__Gateway__c = paymentGateway.Id;
newOrder.ChargentOrders__Account__c = lastCreatedAccount.Id; // Set the account Id
newOrder.ChargentOrders__Charge_Amount__c = 1000; // Set the recurring order amount
newOrder.ChargentOrders__Currency__c = 'USD'; // Set the currency
newOrder.ChargentOrders__Payment_Status__c = 'Recurring'; // This is a recurring charge
newOrder.ChargentOrders__Payment_Frequency__c = 'Weekly';
newOrder.ChargentOrders__Payment_Stop__c = 'Count';
newOrder.ChargentOrders__Payment_Count__c = 12;
newOrder.ChargentOrders__Charge_Date__c = '01';
newOrder.ChargentOrders__Payment_Start_Date__c = Date.newInstance(2023, 06, 15);
newOrder.ChargentOrders__Payment_Descriptor__c = 'Chargent Test Recurring Order';

// Set other fields as needed

// Create the order
try {
insert newOrder;
System.debug('Chargent Order created successfully.');
} catch (Exception e) {
System.debug('Error creating Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving last created Account: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving the Payment Gateway: ' + e.getMessage());
}

Create One-Time Chargent Order​

Apex Example
try {
// Get payment gateway to use
String paymentGatewayName = 'Stripe Test';
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = :paymentGatewayName ORDER BY CreatedDate DESC LIMIT 1];

try {
// Get the last account
Account lastCreatedAccount = [SELECT Id FROM Account WHERE Name = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

ChargentOrders__ChargentOrder__c newOrder = new ChargentOrders__ChargentOrder__c();
newOrder.ChargentOrders__Gateway__c = paymentGateway.Id;
newOrder.ChargentOrders__Account__c = lastCreatedAccount.Id; // Set the account Id
newOrder.ChargentOrders__Charge_Amount__c = 1000; // Set the order amount
newOrder.ChargentOrders__Currency__c = 'USD'; // Set the currency
newOrder.ChargentOrders__Manual_Charge__c = true; // This is a one-time charge
newOrder.ChargentOrders__Payment_Descriptor__c = 'Chargent Test One Time Order';

// Set other fields as needed

// Create the order
try {
insert newOrder;
System.debug('Chargent Order created successfully.');
} catch (Exception e) {
System.debug('Error creating Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving last created Account: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving Payment Gateway: ' + e.getMessage());
}

Create Credit Chargent Order​

Apex Example
try {
// Get payment gateway to use
String paymentGatewayName = 'Stripe Test';
ChargentBase__Gateway__c paymentGateway = [SELECT Id FROM ChargentBase__Gateway__c WHERE Name = :paymentGatewayName ORDER BY CreatedDate DESC LIMIT 1];

try {
// Get the last account
Account lastCreatedAccount = [SELECT Id FROM Account WHERE Name = 'Chargent Test' ORDER BY CreatedDate DESC LIMIT 1];

ChargentOrders__ChargentOrder__c newOrder = new ChargentOrders__ChargentOrder__c();
newOrder.ChargentOrders__Gateway__c = paymentGateway.Id;
newOrder.ChargentOrders__Account__c = lastCreatedAccount.Id;
newOrder.ChargentOrders__Credit_Amount__c = 25; // Set the credit amount
newOrder.ChargentOrders__Currency__c = 'USD'; // Set the currency
newOrder.ChargentOrders__Manual_Charge__c = true; // This is a one-time charge
newOrder.ChargentOrders__Payment_Descriptor__c = 'Chargent Test Credit Order';

// Set other fields as needed

// Create the order
try {
insert newOrder;
System.debug('Chargent Order created successfully.');
} catch (Exception e) {
System.debug('Error creating Chargent Order: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving last created Account: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error retrieving Payment Gateway: ' + e.getMessage());
}

Learn More​

Learn more about Chargent Orders.