---
title: Controllers
slug: extensions/jGtYdd7JerjEr6fGsLbw5
docTags: 
createdAt: 2025-12-14T14:23:41.918Z
---

# Controllers Post-Auth Integration

## Overview

The **ForterValidate** controller is implemented with your payment gateway. In the sample implementations, you can see the mapping for CyberSource and Authorize.net.

***You will need to customize the logic to fit your specific payment processor and gateway***.

## Controllers Code

Below is code from the Authorize.net controller which is triggered as part of the generic Site Genesis authorization flow. You will need to map the authorization response within your payment gateway's controller to the **ForterOrder.ds** which can be found via the path:

`Cartridges`*>*`int_forter`*>*`cartridge`*>*`scripts`*>*`lib`*>*`forter`*>*`dto`*>*`ForterOrder.ds`

Note that the below code references the **Authorize.net** controller within the Site Genesis authorization flow and additional customizations should be made to your gateway controller based on the data you receive from your payment gateway (i.e. CyberSource, Adyen, Braintree, PaymentTech etc.)

**Sample Controllers Code** (Authorize.net)

```javascript
function Authorize(args) {
    if (empty(session.forms.billing.paymentMethods.selectedPaymentMethodID.value)) {
        return {error: true};
    }

    var orderNo           = args.OrderNo,
        paymentInstrument = args.PaymentInstrument,
        paymentProcessor  = PaymentMgr.getPaymentMethod(paymentInstrument.getPaymentMethod()).getPaymentProcessor();

    Transaction.wrap(function () {
        paymentInstrument.paymentTransaction.transactionID    = orderNo;
        paymentInstrument.paymentTransaction.paymentProcessor = paymentProcessor;
    });

    var argCCAuth = {
            Order             : args.Order,
            PaymentInstrument : paymentInstrument
        },
        authResponse = doAuth(argCCAuth);

    if (authResponse.result == false) {
                var argOrderValidate = {
                Order: args.Order,
                orderValidateAttemptInput: 1
            },
            forterController = require('int_forter/cartridge/controllers/ForterValidate'),
            forterDecision   = forterController.ValidateOrder(argOrderValidate);
        // in case if no response from Forter, try to call one more time
        if (forterDecision.result === false && forterDecision.orderValidateAttemptInput == 2) {
     	var argOrderValidate = {
                    Order: args.Order,
                    orderValidateAttemptInput: 2
                },
                forterController = require('int_forter/cartridge/controllers/ForterValidate'),
                forterDecision   = forterController.ValidateOrder(argOrderValidate);
        }

        if (!empty(forterDecision.PlaceOrderError)) {
            return {error : true, forterErrorCode : forterDecision.PlaceOrderError};
        } else {
            return {error : true};
        }
        return {error: true};
    }

    if (authResponse.result == true) {
        var argOrderValidate = {
                Order: args.Order,
                orderValidateAttemptInput: 1
            },
            forterController = require('int_forter/cartridge/controllers/ForterValidate'),
            forterDecision   = forterController.ValidateOrder(argOrderValidate);
        // in case if no response from Forter, try to call one more time
        if (forterDecision.result === false && forterDecision.orderValidateAttemptInput == 2) {
        	var argOrderValidate = {
                    Order: args.Order,
                    orderValidateAttemptInput: 2
                },
                forterController = require('int_forter/cartridge/controllers/ForterValidate'),
                forterDecision   = forterController.ValidateOrder(argOrderValidate);
        }
        
        if (forterDecision.JsonResponseOutput.processorAction === 'skipCapture' || forterDecision.JsonResponseOutput.processorAction === 'notReviewed') {
            return {authorized: true};
        } else if (forterDecision.JsonResponseOutput.processorAction === 'disabled' || forterDecision.JsonResponseOutput.processorAction === 'internalError' || forterDecision.JsonResponseOutput.processorAction === 'capture') {
            var argCCCapture = {
                    AuthorizeNetResponse : authResponse.AuthorizeNetResponse,
                    Order                : args.Order,
                    PaymentInstrument    : paymentInstrument
                },
                captureResponse = doCapture(argCCCapture);

            if (captureResponse.result == true) {
                return {authorized: true};
            }

            if (captureResponse.result == false) {
                var argVoid = {
                        AuthorizeNetResponse : authResponse.AuthorizeNetResponse,
                        Order                : args.Order,
                        PaymentInstrument    : paymentInstrument
                    },
                    voidResponse = doVoid(argVoid);

                if (!empty(forterDecision.PlaceOrderError)) {
                    return {error : true, forterErrorCode : forterDecision.PlaceOrderError};
                } else {
                    return {error : true};
                }
            }
        } else {
            var argVoid      = {
                    AuthorizeNetResponse : authResponse.AuthorizeNetResponse,
                    Order                : args.Order,
                    PaymentInstrument    : paymentInstrument
                },
                voidResponse = doVoid(argVoid);

            if (!empty(forterDecision.PlaceOrderError)) {
                return {error : true, forterErrorCode : forterDecision.PlaceOrderError};
            } else {
                return {error : true};
            }
        }
    }
}

function doAuth(argCCAuth) {
    var authorizenetCCAuthRequest = require('~/cartridge/scripts/pipelets/AuthorizenetCCAuthRequest'),
        authResponse              = authorizenetCCAuthRequest.execute(argCCAuth);
    return authResponse;
}

function doCapture(argCCCapture) {
    var authorizenetCCCaptureRequest = require('~/cartridge/scripts/pipelets/AuthorizenetCCCaptureRequest'),
        captureResponse              = authorizenetCCCaptureRequest.execute(argCCCapture);
    return captureResponse;
}

function doVoid(argVoid) {
    var authorizenetVoidRequest = require('~/cartridge/scripts/pipelets/AuthorizenetVoidRequest'),
        voidResponse            = authorizenetVoidRequest.execute(argVoid);
    return voidResponse;
}

//this is within the ForterOrder.ds file
```

**Response Not stored on Payment Instrument**

If your implementation does **NOT** store the response on the payment instrument, you can pass the response object from your payment processor to the validateOrder() function by using the ForterValidate.js controller.

The path to the ForterValidate.js controller is: `Cartridges > int_forter > cartridge > controllers > ForterValidate.js`

When the `ForterValidate.js` controller is used as an input, it is sent as a parameter to the `ForterOrder.ds` file to generate the request object.
