Skip to main content

Custom Checkout Operations

All chargent operations must be executed by using the handleCustomCheckoutOperation method exposed by the scaComponent. The procedure for using this method is as follows:

force-app/main/default/lwc/customCheckoutExample/customCheckoutExample.js
import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import customCheckout from "@salesforce/resourceUrl/ChargentCustomCheckout";

export default class CustomCheckoutExample extends LightningElement {
recordId = "orderId";
orderSource = "ecommerce";

handleCharge() {
const operation = "Charge";
// Retrieve and validate input values
var payload = chargentFields.buildPayForm(this.recordId, 'Credit Card');

if (payload.status === 200) {
payload.formValues.companyName = 'Appfrontier';
payload.formValues.orderSorce = this.orderSource; // Only for Bank Accounts
payload.formValues.chargentOrderId = this.recordId;
setTimeout(() => {
this.template.querySelector("chargentbase-sca-component").handleCustomCheckoutOperation(payload, operation);
}, 2000);
} else {
// Missing and invalid fields error handling
}
}

handleScaComponentResponse(event){
let eventResponse = JSON.parse(event.detail)
let message = eventResponse.message;
let title = (eventResponse.status === 200) ? "Success" : "Error";
let variant = (eventResponse.status === 200) ? "success": "error";
this.showToast(title, message, variant);
}

showToast(title, message, variant) {
this.showSpinner = false;
const event = new ShowToastEvent({ title: title, message: message, variant: variant, mode: 'sticky' });
this.dispatchEvent(event);
}
}

Note: all pre-requisites in Getting Started section need to be met in order to perform any operation with the scaComponent.

handleCustomCheckoutOperation(payload, operation)

It is recommended to add a 2-second delay when calling handleCustomCheckoutOperation. This delay is to wait for the SCA Iframe to load. Time may vary 1-2 seconds. This method is used to perform all payment operation within the checkout form and it is invoked with two parameters:

payload

This parameter is an object containing the necessary data to complete the payment operation. The payload object is generated using the chargentFields.buildPayForm(orderRecordId, selectedPaymentMethod) method. The following key properties must also be included in the payload object before executing any Chargent operation:

PropertyDescription
companyNameThe name of the company or entity for which the payment operation is being performed.
orderSourceIt should contain information about the order source. Accepted values may include 'ecommerce' and 'recurringtel'. (Only applicable when using a bank account)
chargentOrderIdThe unique identifier of the Chargent order record related to the operation.

operation

This parameter is a text string specifying the type of operation to be carried out. These are the available operations type:

  • Charge
  • Authorize
  • RegisterToken
  • CreatePM

All operations, except for 'CreatePM', perform an update on the Chargent Order.

Handling scaComponent reponse

The scaComponent uses a single custom event called response to communicate with the outside world. Whenever the scaComponent completes an operation, such as Charge, it dispatches a response event. The handleSCAResponse method in the code example above is responsible for handling response events. The response event contains the following information:

Success response

'reponse' custom event detail
{
responseData: 'Success', // Chargent response message
responseStatus: 200
}

Error response

'reponse' custom event detail
{
responseData: 'Error updating the Chargent Order record.', // Chargent response message
responseStatus: 400 // could be 400, 403 or 422
}

403 responseStatus is for when the API Feature Parameter is inactive. The 422 responseStatus is set for when there is missing or wrong data in the checkout form. For all other cases the responseStatus will be 400.

Considerations

Charge

  • This operation updates the Chargent Order record with the user's input.
  • When Payment Method gets activated in your org, new permission sets need to be assigned to users (see Create Payment Method)
  • If the Payment Method feature is enabled in your salesforce organization, performing a Charge transaction will create a Payment Method record as side effect.
  • A Strong Customer Authentication (SCA) iframe may prompt when making a charge if the payment gateway has SCA configured and the credit card being used is marked with SCA.

Authorize

  • This operation updates the Chargent Order record with the user's input.
  • If when making an Authorization operation the amount is equal or less than 0 dollars, CCC automatically sets the authorization amount to 1 dollar.
  • When Payment Method gets activated in your org, new permission sets need to be assigned to users (see Create Payment Method)
  • If the Payment Method feature is enabled in your salesforce organization, performing an Authorization transaction will create a Payment Method record as side effect.
  • A Strong Customer Authentication (SCA) iframe may prompt when making an authorization if the payment gateway has SCA configured and the credit card being used is marked with SCA.

Register Token

  • This operation updates the Chargent Order record with the user's input.
  • When Payment Method gets activated in your org, new permission sets need to be assigned to users (see Create Payment Method)
  • If the Payment Method feature is enabled in your salesforce organization, performing a RegisterToken transaction will create a Payment Method record as side effect.
  • Strong Customer Authentication logic will not trigger for RegisterToken operations.

Create Payment Method

  • This operation will work only if Payment Methods feature is active in your salesforce organization.

  • This operation will not update the Chargent Order.

  • A new permission set with the following characteristics needs to created and assigned to users:

    Community User:
    • Apex Class Access: ChargentBase.ActionService.
    • Object permissions: Read, Create and Edit permissions on ChargentBase__Log__c, ChargentBase__Payment_Method__c and ChargentBase__Token__c objects
    • Field permissions:
      • Read and Edit permissions on the ChargentOrders__ChargentOrder__c.ChargentOrders__Payment_Method_Default__c and ChargentOrders__ChargentOrder__c.ChargentOrders__Payment_Method_UUID__c fields
      • Read and Edit permissions on the ChargentOrders__Payment_Method_Applied__c.ChargentOrders__Transaction__c field
      • Read and Edit permissions on all the ChargentBase__Log__c, ChargentBase__Payment_Method__c and ChargentBase__Token__c fields.
    Guest User:
    • Apex Class Access: ChargentBase.ActionService.
    • Object permissions: Read and Create permissions on ChargentBase__Log__c, ChargentBase__Payment_Method__c and ChargentBase__Token__c objects
    • Field permissions:
      • Read and Edit permissions on the ChargentOrders__ChargentOrder__c.ChargentOrders__Payment_Method_Default__c and ChargentOrders__ChargentOrder__c.ChargentOrders__Payment_Method_UUID__c fields
      • Read and Edit permissions on the ChargentOrders__Payment_Method_Applied__c.ChargentOrders__Transaction__c field
      • Read and Edit permissions on all the ChargentBase__Log__c, ChargentBase__Payment_Method__c and ChargentBase__Token__c fields.