SFCC Cartridge
...
PayPal Transactions
PayPal SFRA
9 min
paypal sfra overview the forter sfra cartridge has contains built in functionality for saving your paypal api responses these responses include the paypal transaction details capture response void response authorization response express checkout response the paypal data is stored as a json string in a custom attribute of the paymentinstrument object of your forterorder ds file and each response is saved to a dedicated custom attribute fort recommends that you save these attributes as a text type as the responses can contain up to 4,000 characters mapping the paypal response to the payment instrument in accordance with salesforce commerce cloud sfra/mfra guidelines, the paypal data should be stored on the payment instrument and existing code in the cartridge should be overwritten accordingly in cases where the storefront application has the same controllers or templates extended or replaced, all affected code modifications must be added to the top level cartridge of the storefront application 1\ designate the paypal payment object similar to the credit card, the paypal method should be a designated payment instrument in the forterorder(args) function of the forterorder ds file example function forterorder(args) { var log = new forterlogger("forterorder ds"), order = args order, site = dw\ system site getcurrent(), paymentinstruments = order getpaymentinstruments(), a = null, authresponse = null, shipment = null; for each (var paymentinstrument in paymentinstruments) { if (paymentinstrument paymentmethod == 'credit card') { a = paymentinstrument; authresponse = args creditcardauthresponse; } else if (paymentinstrument paymentmethod == 'paypal' || paymentinstrument paymentmethod == 'bml') { a = paymentinstrument; authresponse = {}; // not necessary as this info can be retreived from a instrument } else if (paymentinstrument paymentmethod == 'gift certificate') { // optional if this is an accepted a method in your store a = paymentinstrument; authresponse = args gcredemptiontransaction; } } 2\ map the paypal authorization response to a dedicated function such as paypal or gift cards should be mapped to their associated functions in the forterorder ds and include the required fields listed in the validation api reference https //portal forter com/api/data objects/paypal in the below example, the paypal datapoints are stringified and mapped to the dedicated paypal (order, a) function function forterpaypal(order, a ) { //var transactiondetails = {}; this payerid = a custom paypalpayerid this payeremail = order customeremail; //required this payerstatus = ""; this payeraddressstatus = ""; //"confirmed" this paymentmethod = order custom paypalpaymentmethod; // ex instant transfer this paymentstatus = a custom paypalpaymentstatus touppercase(); //"pending" this payeraccountcountry = "us"; // do not hardcode if accepted from multiple countries this protectioneligibility = a custom paypalprotectioneligibility touppercase(); //"eligible"; this correlationid = a custom paypalcorrelationid correlationid; // ex "fdshkj2390sdf"; this paymentid = ""; this authorizationid = a custom paypalauthid; // ex "2wc75407lv7300439"; this fullpaypalresponsepayload = {}; } paypal express when integrating with paypal, we suggest you modify your papal cartridge settings (in the site preferences > customer site preference groups ) this will allow forter's cartridge to receive the relevant payment information and also allow you to automate whether a paypal transaction is captured or cancelled and voided based on the forter decision please note forter's cartridge does not handle the billing agreement checkout flow in the below example step 1 authorize before calling forter update the express checkout to include authorization before forter is called this can be done by setting the payment action setting to "authorization" or by setting run authorization in case of order to yes step 2 review billing information settings make sure the paypal cartridge is set to send customer billing information to salesforce commerce cloud please note this configuration may need external permissions added by paypal support to your paypal account in order to handle the customized error massage configured in forter business manager extension, particularly for cases when the paypal payment processor is called via hooks (if your main site is built on controllers or sfra), the int paypal/cartridge/scripts/payment/processor/paypal express js must check if any error exists in pdict for example in the if statement if(!empty(pdict forterresponse placeordererror)){ return {error true, fortererrorcode pdict forterresponse placeordererror}; } else if ( (!empty(pdict forterresponse jsonresponseoutput actionenum) && pdict forterresponse jsonresponseoutput actionenum == 'declined') && (!empty(pdict forterresponse jsonresponseoutput processoraction) && pdict forterresponse jsonresponseoutput processoraction != 'skipcapture') ) { return {error true}; } ) step 3 handle custom error message in order to handle the customized error message configured in your forter business manager extension, the coplaceorder js file must be adjusted to check if any error exists in the authorizationresult inside the handlepayments(order) function // 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}; } } inside the start() function // inside the start() function return { error true, placeordererror new status(status error, handlepaymentsresult fortererrorcode ? handlepaymentsresult fortererrorcode code 'confirm error technical') }; ``