Skip to main content

Payment Request

Overview

Payment Request creates a payment link that may be emailed to your customers for taking a payment on a Chargent Order.

Prerequisites

There are multiple prerequisite resources that must be created before creating a Payment Request.

           Object           Definition
ContactSalesforce standard Contact object.
Chargent OrderChargent Orders are central objects to payments lifecycle management.

Create Payment Request

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 Contact to use
Contact lastContact = [SELECT Id, AccountId, FirstName, LastName, Email FROM Contact WHERE FirstName = 'Chargent' AND LastName = 'Test' ORDER BY CreatedDate DESC LIMIT 1];
Id lastContactId = lastContact.Id;

// Populate the payment request
ChargentOrders__Payment_Request__c newPaymentRequest = new ChargentOrders__Payment_Request__c();
newPaymentRequest.ChargentOrders__ChargentOrder__c = lastChargentOrderId;
newPaymentRequest.ChargentOrders__Billing_Contact__c = lastContactId;
newPaymentRequest.ChargentOrders__Send_Payment_Request_Email__c = True;
newPaymentRequest.ChargentOrders__Payment_Request_Transaction_Type__c = 'Charge Full Amount';

// Set other fields as needed

// Create the Payment Request
try {
insert newPaymentRequest;
System.debug('Payment Request created successfully.');
} catch (Exception e) {
System.debug('Error creating Payment Request: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Contact: ' + e.getMessage());
}
} catch (Exception e) {
System.debug('Error getting Chargent Order: ' + e.getMessage());
}

Learn More

Learn more about Payment Request Setup.