SFCC Cartridge
...
PayPal Transactions
PayPal Controller
5 min
overview the forter cartridge has built in functionality for saving the paypal api responses including the following responses transaction details capture void authorization expresscheckout the data is stored as a json string in a custom attribute called the order payment instrument object each response is saved to a dedicated custom attribute the recommended type for these custom attributes is text since in some cases the response is over 4k characters in order to save the paypal response, a script node must be added to anywhere the required data exists for example paypal transaction details may be saved right after a call to payppal gettransactiondetails and passed into the int forter\ pipelets/forter/fortercallstoreresponse ds script in the script, dictionary input , the “paypal transaction details response” is actually the custom attribute response from the, paypaltransactiondetails this data point is an object that contains information about the current transaction and paymentinstrument is your current payment instrument error handling error on extension called via hooks (main site built on controllers) to handle the customized error message in your forter business manager for scenarios where the paypal payment processor is called via hooks (specically for storefronts built on controllers) update the following script int paypal/cartridge/scripts/payment/processor/paypal express js this should check if any error exists in pdict for example, the if statement below checks for this type of error if (!empty(pdict forterresponse placeordererror)){} ex 2 1 error on extension called on authorizationresult to handle the error message configured in your forter business manager extension, adjust the `coplaceorder js` to check if an error exists in the `authorizationresult` variable within the `handlepayments(order)` function if (authorizationresult not supported || authorizationresult error) { if (!empty(authorizationresult fortererrorcode)) { return { error true, fortererrorcode authorizationresult fortererrorcode }; } else { return {error true}; } } ex 2 2 next, add the following line inside the start() function inside the start() function return { error true, placeordererror new status(status error, handlepaymentsresult fortererrorcode ? handlepaymentsresult fortererrorcode code 'confirm error technical') }; ex 2 3 adjusting cartridge controllers for your paypal processor response the forterorder ds file should be edited to use the response from your payment processor overview the script is used to generate the request object for forter validation in the example below, we store the response from authorize net on the payment instrument itself in a custom attribute to be used in this script 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 (located in the fortervalidate js controller) as an input, which will be sent as a parameter to the forterorder ds file to generate the request object the script examples below ( 2 4 and 2 5 ) has commented code as an example to illustrate the optional and required values that need to be sent example 2 4 / forterorder class is the dto object for request to include this script use var forterorder = require("int forter/cartridge/scripts/lib/forter/dto/forterorder ds"); / function forterorder(args) { var log = new forterlogger("forterorder ds"), order = args order, site = dw\ system site getcurrent(), paymentinstruments = order getpaymentinstruments(), payment = null, authresponse = null, shipment = null; for each (var paymentinstrument in paymentinstruments) { if (paymentinstrument paymentmethod == 'credit card') { //todo adjust to the existing payment instruments payment = paymentinstrument; authresponse = new xml(paymentinstrument custom authorize net authorization); } else if (paymentinstrument paymentmethod == 'paypal' || paymentinstrument paymentmethod == 'bml') { //todo adjust to the existing payment instruments payment = paymentinstrument; authresponse = paymentinstrument custom paypal transaction details response; } } example 2 5 function forterpaypal(authresponse, countrycode) { this payerid = authresponse payerid; //"fd000a45p"; this payeremail = authresponse paypalemail; this payerstatus = "verified"; //"verified"; this payeraddressstatus = "confirmed";//"confirmed"; this paymentmethod = "paypal"; this paymentstatus = authresponse paypalpaymentstatus touppercase(); //"pending" this payeraccountcountry = countrycode; //"us"; this protectioneligibility = "eligible"; //"eligible"; this correlationid = authresponse paypalcorrelationid; //"fdshkj2390sdf"; this paymentid = ""; this authorizationid = authresponse transactionid; //"2wc75407lv7300439"; this fullpaypalresponsepayload = authresponse; this paymentgatewaydata = {}; this paymentgatewaydata gatewayname = "paypal"; //todo must be adjusted according to the payment gateway used this paymentgatewaydata gatewaytransactionid = authresponse transactionid; }