SFCC Cartridge
...
Mapping Samples
Authorize.net
2 min
1\ full forterorder ds file using authorize net below is the full forterorder ds file including the mapped authorization response for a merchant using the authorize net gateway note that the majority of the mapping takes place in the fortercreditcard(auth, cc) function this specific function can be found in the next section, fortercreditcard(auth, cc) forterorder ds file / forterorder ds var forterlogger = require("int forter/cartridge/scripts/lib/forter/forterlogger ds"); / 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; } } // general parameters this orderid = order originalorderno; // required this ordertype = "web"; // required this timesenttoforter = (new date()) gettime(); // required this checkouttime = new number((order creationdate gettime()/1000) tofixed()); // required //must be seconds, not milliseconds this connectioninformation = new forterconnectioninformation(order); // required // calculate totals this totalamount = {}; // required this totalamount amountlocalcurrency = order totalgrossprice value tofixed(2); this totalamount currency = order totalgrossprice currencycode; //calculate totals for discounts var ordertotal = order getmerchandizetotalprice(), adjordertotal = order getadjustedmerchandizetotalprice(), shiptotal = order getshippingtotalprice(), adjshiptotal = order getadjustedshippingtotalprice(), total = ordertotal add(shiptotal), adjtotal = adjordertotal add(adjshiptotal); // discounts var discountprice = 0; var couponname = ''; var coupontype = ''; if (!order getcouponlineitems() isempty()) { var coupons = order getcouponlineitems(); var couponnames = \[]; for each (let coup in coupons) { couponnames push(coup getcouponcode()); if (!coup getpriceadjustments() isempty()) { var coupadjustments = coup getpriceadjustments(); for each (let coupadj in coupadjustments) { discountprice += coupadj pricevalue; } } } couponname = couponnames join(","); discountprice = discountprice ( 1); if (discountprice > 0) { this totaldiscount = {}; // optional this totaldiscount couponcodeused = couponname substring(0,20); // required this totaldiscount coupondiscountamount = {}; // required this totaldiscount coupondiscountamount amountlocalcurrency = discountprice tofixed(2); this totaldiscount coupondiscountamount currency = order currencycode; this totaldiscount discounttype = "coupon"; // required } } // customer's details this accountowner = new fortercustomer(order); // cart items (regular product) this cartitems = \[]; // required for each (var pli in order productlineitems) { this cartitems push(new fortercartitem(pli)); } // cart items (gift certificate) for each (var gcli in order giftcertificatelineitems) { this cartitems push(new fortercartitem(gcli)); } // payments this payment = \[]; // required this payment push(new forterpayment(order, authresponse, payment, log)); // delivery and recipient (shipping information) if (order shipments length > 0) { shipment = order shipments\[0]; this primarydeliverydetails = {}; this primarydeliverydetails deliveryprice = {}; this primarydeliverydetails deliverymethod = (!empty(shipment getshippingmethod()) && !empty(shipment getshippingmethod() getdisplayname())) ? shipment getshippingmethod() getdisplayname() ""; //"by air"; var deliverytype = "physical"; //default value if (order productlineitems size() > 0 && order giftcertificatelineitems size() == 0) { deliverytype = "physical"; //if real products only } else if (order productlineitems size() == 0 && order giftcertificatelineitems size() > 0) { deliverytype = "digital"; //if gift certificates only this primarydeliverydetails deliverymethod = "email"; } else if (order productlineitems size() > 0 && order giftcertificatelineitems size() > 0) { deliverytype = "hybrid"; //if gift certificates and real products } this primarydeliverydetails deliverytype = deliverytype; this primarydeliverydetails deliveryprice amountlocalcurrency = shipment adjustedshippingtotalprice value tofixed(2); this primarydeliverydetails deliveryprice currency = shipment adjustedshippingtotalprice currencycode tostring(); if (shipment productlineitems size() > 0) { this primaryrecipient = {}; // optional this primaryrecipient personaldetails = {}; this primaryrecipient personaldetails firstname = shipment shippingaddress firstname; //from the shipping address this primaryrecipient personaldetails lastname = shipment shippingaddress lastname; //from the shipping address this primaryrecipient address = {}; this primaryrecipient address address1 = shipment shippingaddress address1; this primaryrecipient address address2 = !empty(shipment shippingaddress address2) ? shipment shippingaddress address2 ""; this primaryrecipient address zip = shipment shippingaddress postalcode; this primaryrecipient address city = shipment shippingaddress city; this primaryrecipient address region = shipment shippingaddress statecode; this primaryrecipient address country = shipment shippingaddress countrycode displayvalue touppercase(); this primaryrecipient phone = \[]; if (!empty(shipment shippingaddress phone)){ this primaryrecipient phone push(new forterphone(shipment shippingaddress phone)); } } else if (shipment giftcertificatelineitems size() > 0) { this primaryrecipient = {}; // optional this primaryrecipient personaldetails = {}; this primaryrecipient personaldetails fullname = shipment giftcertificatelineitems\[0] recipientname; //from the gift form this primaryrecipient personaldetails email = shipment giftcertificatelineitems\[0] recipientemail; //from the gift form } if (shipment gift == true) { this primaryrecipient comments = {}; this primaryrecipient comments messagetobeneficiary = shipment giftmessage ? shipment giftmessage ""; } } function forterconnectioninformation(order) { this customerip = request httpremoteaddress; // required this useragent = request httpuseragent; for (var i = 0; i < request httpcookies cookiecount; i++) { if (request httpcookies\[i] name == "fortertoken") { this fortertokencookie = request httpcookies\[i] value; // required } } this useragent = request httpuseragent; // required this fortertokencookie = ""; // conditional for (var i = 0; i < request httpcookies cookiecount; i++) { if (request httpcookies\[i] name == "fortertoken") { this fortertokencookie = request httpcookies\[i] value; } } } } function fortercustomer(order) { if (order customer profile != null) { this firstname = order customer profile firstname; this lastname = order customer profile lastname; this email = order customer profile email; this accountid = order customer id; this created = new number((order customer profile getcreationdate() gettime()/1000) tofixed()); var query = "customerno = {0} and paymentstatus = {1}"; var allorders seekableiterator = dw\ order ordermgr searchorders(query, "creationdate desc", order customer profile customerno, 2); this pastorderscount = new number(allorders count); } else { this firstname = order billingaddress firstname; this lastname = order billingaddress lastname; this email = order customeremail; } } function forterpayment(order, authresponse, payment, log) { var billingaddress = order billingaddress; this billingdetails = {}; this billingdetails personaldetails = {}; this billingdetails personaldetails firstname = billingaddress firstname; this billingdetails personaldetails lastname = billingaddress lastname; this billingdetails personaldetails email = order customeremail; this billingdetails address = {}; this billingdetails address address1 = billingaddress address1; this billingdetails address address2 = !empty(billingaddress address2) ? billingaddress address2 ""; this billingdetails address zip = billingaddress postalcode; this billingdetails address city = billingaddress city; this billingdetails address region = billingaddress statecode; this billingdetails address country = billingaddress countrycode displayvalue touppercase(); if (!empty(billingaddress phone)) { this billingdetails phone = \[]; this billingdetails phone push(new forterphone(billingaddress phone)); } this amount = {}; this amount amountlocalcurrency = order totalgrossprice value tofixed(2); this amount currency = order totalgrossprice currencycode; if (!empty(payment)) { if (payment paymentmethod == 'paypal' || payment paymentmethod == 'bml') { this paypal = new forterpaypal(authresponse); } else if (payment paymentmethod == 'credit card') { this creditcard = new fortercreditcard(authresponse, payment); } } else { log error('no payment method information for order ' + order originalorderno); } } function forterphone(phone) { this phone = phone; } function forterpaypal(authresponse) { var transactiondetails = json parse(authresponse); this payerid = transactiondetails payerid; //"fd000a45p"; this payeremail = transactiondetails email; this payerstatus = transactiondetails payerstatus touppercase(); //"verified"; this payeraddressstatus = transactiondetails addressstatus touppercase();//"confirmed"; this paymentmethod = ""; this paymentstatus = transactiondetails paymentstatus touppercase(); //"pending" this payeraccountcountry = transactiondetails countrycode touppercase(); //"us"; this protectioneligibility = transactiondetails protectioneligibility touppercase(); //"eligible"; this correlationid = transactiondetails correlationid; //"fdshkj2390sdf"; this paymentid = ""; this authorizationid = transactiondetails transactionid; //"2wc75407lv7300439"; this fullpaypalresponsepayload = {}; this fullpaypalresponsepayload = transactiondetails; } function fortercreditcard(auth, cc) { var processorresponsecode = '', processorresponsetext = ''; // format the expiration month from 1 to 01, etc if (cc creditcardexpirationmonth tostring() length == 1) { var creditcardexpmonth = "0" + cc creditcardexpirationmonth tostring(); } else { var creditcardexpmonth = cc creditcardexpirationmonth tostring(); } this nameoncard = cc creditcardholder; this cardbrand = cc creditcardtype; if (cc creditcardnumber substring(0,6) indexof(' ') > 1) { this bin = session forms billing paymentmethods creditcard number value substring(0,6); } else { this bin = cc creditcardnumber substring(0,6); } this lastfourdigits = cc creditcardnumberlastdigits; this expirationmonth = creditcardexpmonth; this expirationyear = cc creditcardexpirationyear tostring(); this verificationresults = {}; this verificationresults avsstreetresult = ""; //todo must be adjusted according to the payment gateway used this verificationresults avszipresult = ""; //todo must be adjusted according to the payment gateway used this verificationresults avsfullresult = auth avsresultcode tostring(); //todo must be adjusted according to the payment gateway used this verificationresults cvvresult = auth cvvresultcode tostring(); //todo must be adjusted according to the payment gateway used this verificationresults authorizationcode = auth authcode tostring(); //todo must be adjusted according to the payment gateway used this paymentgatewaydata = {}; this paymentgatewaydata gatewayname = "authorize net"; //todo must be adjusted according to the payment gateway used this paymentgatewaydata gatewaytransactionid = auth transid tostring(); //todo must be adjusted according to the payment gateway used if (auth descendants('errors') length() > 0) { //todo must be adjusted according to the payment gateway used processorresponsecode = auth descendants('errors') descendants('errorcode') tostring(); //todo must be adjusted according to the payment gateway used processorresponsetext = auth descendants('errors') descendants('errortext') tostring(); //todo must be adjusted according to the payment gateway used } else if (auth descendants('messages') length() > 0) { //todo must be adjusted according to the payment gateway used processorresponsecode = auth descendants('messages') descendants('code') tostring(); //todo must be adjusted according to the payment gateway used processorresponsetext = auth descendants('messages') descendants('description') tostring(); //todo must be adjusted according to the payment gateway used } this verificationresults processorresponsecode = processorresponsecode; this verificationresults processorresponsetext = processorresponsetext; } function fortercartitem(item) { this basicitemdata = {}; if (item instanceof dw\ order productlineitem) { this basicitemdata productid = item productid; //optional this basicitemdata name = item productname; //required this basicitemdata quantity = item quantityvalue; //required var product = item getproduct(); if (product getcategories() isempty() && !empty(product getvariationmodel())) { product = product getvariationmodel() getmaster(); } this basicitemdata category = empty(product) ? "" product getcategories()\[0] getdisplayname(); this basicitemdata type = "tangible"; // add if type is available change according to the actual item type //if any adjustements this basicitemdata price = {}; this basicitemdata price amountlocalcurrency = item adjustedprice value tofixed(2); this basicitemdata price currency = item adjustedprice currencycode tostring(); } if (item instanceof dw\ order giftcertificatelineitem) { this basicitemdata name = item lineitemtext; //required this basicitemdata quantity = 1; //required (set 1 by default for a gift cert?) this basicitemdata type = "non tangible"; // add if type is available change according to the actual item type this deliverydetails = {}; this deliverydetails deliverytype = "digital"; this deliverydetails deliverymethod = "email"; this basicitemdata price = {}; this basicitemdata price amountlocalcurrency = item price value tofixed(2); this basicitemdata price currency = item price currencycode tostring(); this beneficiaries = \[]; this beneficiaries push(new forterbeneficiarydetailsfromgiftcard(item)); } } function forterbeneficiarydetailsfromgiftcard(item) { this personaldetails = {}; this comments = {}; this personaldetails fullname = item recipientname; this personaldetails email = item recipientemail; this comments messagetobeneficiary = item message ? item message ""; } module exports = forterorder; 2\ fortercreditcard(auth, cc) function the code featured below features the mapped authorize net authorization response payment details (bin, last 4, expiration) for a credit card transaction in the salesforce commercecloud cartridge the same file can be found in the full forter cartridge zip file by going to cartridges > int forter > cartridge > scripts > lib > forter > dto > forterorder ds please note the verificationresults object which should contain the authorization results from authorize net non credit card transactions such as paypal or gift cards should be mapped to their associated functions in the code, forterpaypal (order, a ) , and fortergiftcard (auth, gc) respectively fortercreditcard(auth, cc) function function fortercreditcard(auth, cc) { 	var processorresponsecode = "", 	 processorresponsetext = ""; 	// format the expiration month from 1 to 01, etc 	if (cc creditcardexpirationmonth tostring() length == 1) { 	 var creditcardexpmonth = "0" + cc creditcardexpirationmonth tostring(); 	} else { 	 var creditcardexpmonth = cc creditcardexpirationmonth tostring(); 	} 	this nameoncard = cc creditcardholder; 	this cardbrand = cc creditcardtype; 	if (cc creditcardnumber substring(0, 6) indexof(" ") > 1) { 	 this bin = session forms billing paymentmethods creditcard number value substring( 	 0, 	 6 	 ); 	} else { 	 this bin = cc creditcardnumber substring(0, 6); 	} 	this lastfourdigits = cc creditcardnumberlastdigits; 	this expirationmonth = creditcardexpmonth; 	this expirationyear = cc creditcardexpirationyear tostring(); 	this verificationresults = {}; 	this verificationresults avsstreetresult = ""; //todo must be adjusted according to the payment gateway used 	this verificationresults avszipresult = ""; //todo must be adjusted according to the payment gateway used 	this verificationresults avsfullresult = auth avsresultcode tostring(); //todo must be adjusted according to the payment gateway used 	this verificationresults cvvresult = auth cvvresultcode tostring(); //todo must be adjusted according to the payment gateway used 	this verificationresults authorizationcode = auth authcode tostring(); //todo must be adjusted according to the payment gateway used 	this paymentgatewaydata = {}; 	this paymentgatewaydata gatewayname = "authorize net"; //todo must be adjusted according to the payment gateway used 	this paymentgatewaydata gatewaytransactionid = auth transid tostring(); //todo must be adjusted according to the payment gateway used 	if (auth descendants("errors") length() > 0) { 	 //todo must be adjusted according to the payment gateway used 	 processorresponsecode = auth 	 descendants("errors") 	 descendants("errorcode") 	 tostring(); //todo must be adjusted according to the payment gateway used 	 processorresponsetext = auth 	 descendants("errors") 	 descendants("errortext") 	 tostring(); //todo must be adjusted according to the payment gateway used 	} else if (auth descendants("messages") length() > 0) { 	 //todo must be adjusted according to the payment gateway used 	 processorresponsecode = auth 	 descendants("messages") 	 descendants("code") 	 tostring(); //todo must be adjusted according to the payment gateway used 	 processorresponsetext = auth 	 descendants("messages") 	 descendants("description") 	 tostring(); //todo must be adjusted according to the payment gateway used 	} 	this verificationresults processorresponsecode = processorresponsecode; 	this verificationresults processorresponsetext = processorresponsetext; }