コントローラー
コントローラーの認証後統合
概要
この ForterValidate コントローラーは、あなたの決済ゲートウェイと統合されています。サンプル実装では、CyberSourceとAuthorize.netのマッピングを見ることができます。
特定の決済プロセッサとゲートウェイに合わせてロジックをカスタマイズする必要があります。
コントローラーコード
以下は、一般的なSite Genesis認証フローの一部としてトリガーされるAuthorize.netコントローラーのコードです。あなたの決済ゲートウェイのコントローラー内で認証応答を ForterOrder.ds にマッピングする必要があります。これは次のパスで見つけることができます:
カートリッジ>int_forter>カートリッジ>スクリプト>lib>forter>dto>ForterOrder.ds
以下のコードは、Authorize.netコントローラーをSite Genesisの認証フロー内で参照しており、受け取ったデータに基づいてゲートウェイコントローラーに追加のカスタマイズを行う必要があります(例:CyberSource、Adyen、Braintree、PaymentTechなど)
サンプルコントローラーコード(Authorize.net)
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支払い手段に応じた応答は保存されていません
実装が NOT 支払い手段に応答を保存しない場合、支払い処理業者からの応答オブジェクトを ForterValidate.js コントローラーを使用して validateOrder() 関数に渡すことができます。
ForterValidate.js コントローラーへのパスは: Cartridges > int_forter > cartridge > controllers > ForterValidate.js
ForterValidate.js コントローラーが入力として使用されると、それは ForterOrder.ds ファイルにパラメーターとして送信され、リクエストオブジェクトが生成されます。