public string Execute(string theMessage) { bool usePrimeHSM = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UsePrimeHSM"]); string response = string.Empty; string encryptionIndicator = string.Empty; try { new PANE.ERRORLOG.Error().LogInfo("PinController Web service entered..."); if (theMessage == null) { throw new ApplicationException("Invalid request data. The request data is null"); } if (!(theMessage.ToUpper().StartsWith("C:") || theMessage.ToUpper().StartsWith("E:"))) { throw new ApplicationException("Invalid request data. The request data is expected to start with C: or E:"); } encryptionIndicator = theMessage.Substring(0, 2); theMessage = theMessage.Substring(2); if (encryptionIndicator == "E:") { theMessage = KeyManager.Rijndael(PrimeUtility.Configuration.ConfigurationManager.UssdConfig.UssdEncryptionKey, theMessage, CryptoMode.DECRYPTION); new PANE.ERRORLOG.Error().LogInfo("Request Data: " + theMessage); if (theMessage == null) { throw new ApplicationException("Invalid request data. Unable to decrypt the data, the expected encryption is Rijndael"); } } // formulate the actual request data USSDPinIssuanceRequest theRequest = PosMessageParser.ParseRequestMessage <USSDPinIssuanceRequest>(theMessage); IRequest pinRequest = theRequest as USSDPinIssuanceRequest; pinRequest.TerminalId = string.Format("USSD{0}", theRequest.CardPAN.Substring(theRequest.CardPAN.Length - 4)); pinRequest.Function = "pinselection"; // make the call Card theCard = CardUtilities.RetrieveCard(pinRequest.CardPAN, pinRequest.ExpiryDate); if (theCard == null) { throw new ApplicationException("Invalid card data"); } if (theCard.expiry_date != pinRequest.ExpiryDate) { throw new ApplicationException("Invalid expiry date"); } response = new PosMessageProcessor().DoPinSelection( new PinIssuanceRequest() { CardPAN = pinRequest.CardPAN, ExpiryDate = pinRequest.ExpiryDate, Pin = pinRequest.Pin, ConfirmPin = pinRequest.Pin, TerminalId = pinRequest.TerminalId }, theCard); // pinRequest as PinIssuanceRequest, } catch (Exception ex) { response = string.Format(PinConstants.DECLINED_RESPONSE_FORMAT, ex.Message); new PANE.ERRORLOG.Error().LogToFile(ex); } // encrypt the response before responding if (encryptionIndicator == "E:") { try { response = KeyManager.Rijndael(PrimeUtility.Configuration.ConfigurationManager.UssdConfig.UssdEncryptionKey, response, CryptoMode.ENCRYPTION); } catch (Exception ex) { new PANE.ERRORLOG.Error().LogToFile(ex); } } response = encryptionIndicator + response; return(response); }
public string ActivateCard(string card, string phoneNumber) { bool usePrimeHSM = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UsePrimeHSM"]); string theMessage = ""; string response = string.Empty; string encryptionIndicator = string.Empty; try { new PANE.ERRORLOG.Error().LogInfo("PinController Web service entered..."); if (string.IsNullOrWhiteSpace(card)) { return("1:Card value cannot be null"); } if (string.IsNullOrWhiteSpace(phoneNumber)) { return("1:Phone cannot be null"); } if (Convert.ToBoolean("false")) { theMessage = "C:cardpan=5334771222311096,expiryDate=2204,pin=1234,terminalId=12345678,PinOffset=1234|5399232123033091"; // -Sterling //theMessage = "C:cardpan=5399233021500835,expiryDate=1907,pin=1234,terminalId=12345678,PinOffset=1234|5399232123033091"; // -FBN } else { string expiry = ""; string pan = getCardDetails(card, phoneNumber, out expiry); if (string.IsNullOrWhiteSpace(pan) || string.IsNullOrWhiteSpace(expiry)) { return("1:No such card tied to customer"); } theMessage = String.Format("C:cardpan={0},expiryDate={1},pin=1234,terminalId=12345678,PinOffset=1234|5399232123033091", pan, expiry); new PANE.ERRORLOG.Error().LogInfo(theMessage); //call prime method to get Pin Issuance Request } // formulate the actual request data USSDPinIssuanceRequest theRequest = PosMessageParser.ParseRequestMessage <USSDPinIssuanceRequest>(theMessage.Split('|')[0]); string oldPan = theMessage.Split('|')[1]; IRequest pinRequest = theRequest as USSDPinIssuanceRequest; pinRequest.TerminalId = string.Format("USSD{0}", theRequest.CardPAN.Substring(theRequest.CardPAN.Length - 4)); pinRequest.Function = "pinselection"; Card theCard = null; string pinoffset = string.Empty; if (usePrimeHSM) { theCard = CardUtilities.RetrieveCard(pinRequest.CardPAN, pinRequest.ExpiryDate, "pc_cards_1_A"); pinoffset = CardUtilities.GetCardPinOffset(oldPan, "pc_cards_1_A"); } else { theCard = CardUtilities.RetrieveCard(pinRequest.CardPAN, pinRequest.ExpiryDate, "pc_cards_1_A"); pinoffset = CardUtilities.GetCardPinOffset(oldPan, "pc_cards_1_A"); } if (theCard == null) { return("1:Invalid card data"); } if (pinoffset == null) { return("1:Pinoffset of existing card is null"); } if (theCard.expiry_date != pinRequest.ExpiryDate) { return("1:Invalid expiry date"); } response = new PosMessageProcessor().DoCardActivation( new PinIssuanceRequest() { CardPAN = pinRequest.CardPAN, ExpiryDate = pinRequest.ExpiryDate, Pin = pinRequest.Pin, ConfirmPin = pinRequest.Pin, TerminalId = pinRequest.TerminalId, // Track2 = "5399233021500835D1907221011408619F", // IccData = "<IccRequest><AmountAuthorized>000000000000</AmountAuthorized><AmountOther>000000000000</AmountOther><ApplicationInterchangeProfile>3800</ApplicationInterchangeProfile><ApplicationTransactionCounter>006C</ApplicationTransactionCounter><Cryptogram>E7ADCDEFBDE1A846</Cryptogram><CryptogramInformationData>80</CryptogramInformationData><CvmResults>420300</CvmResults><IssuerApplicationData>0110A0800322000062E300000000000000FF</IssuerApplicationData><TerminalCapabilities>E040E0</TerminalCapabilities><TerminalCountryCode>566</TerminalCountryCode><TerminalType>12</TerminalType><TerminalVerificationResult>0080048000</TerminalVerificationResult><TransactionCurrencyCode>566</TransactionCurrencyCode><TransactionDate>170707</TransactionDate><TransactionType>92</TransactionType><UnpredictableNumber>B4072947</UnpredictableNumber></IccRequest>" }, theCard, pinoffset, oldPan); // pinRequest as PinIssuanceRequest, } catch (Exception ex) { response = string.Format("1:{0}", ex.Message); new PANE.ERRORLOG.Error().LogToFile(ex); } return(response); }
public string IssuePin(string card, string phoneNumber) { bool usePrimeHSM = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UsePrimeHSM"]); string theMessage = ""; string response = string.Empty; string encryptionIndicator = string.Empty; IRequest pinRequest = new USSDPinIssuanceRequest(); try { new PANE.ERRORLOG.Error().LogInfo("PinController Web service entered..."); new PANE.ERRORLOG.Error().LogInfo(string.Format("{0} - {1}", card, phoneNumber)); if (string.IsNullOrWhiteSpace(card)) { return("1:Card value cannot be null"); } if (string.IsNullOrWhiteSpace(phoneNumber)) { return("1:Phone cannot be null"); } if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseDefaultUSSDCardData"])) { // theMessage = "C:cardpan=5334771222311096,expiryDate=2204"; //- Sterling // theMessage = "C:cardpan=5399232123065994,expiryDate=1802"; //-FBN //theMessage = "C:cardpan=6280515555555555,expiryDate=2008"; //Keystone theMessage = "C:cardpan=5334775926989586,expiryDate=2009"; } else { string expiry = ""; string pan = getCardDetails(card, phoneNumber, out expiry); if (string.IsNullOrWhiteSpace(pan) || string.IsNullOrWhiteSpace(expiry)) { return("1:An error occurred."); } theMessage = String.Format("C:cardpan={0},expiryDate={1},pin=1234,terminalId=12345678,PinOffset=1234|5399232123033091", pan, expiry); new PANE.ERRORLOG.Error().LogInfo(theMessage); //call prime method to get Pin Issuance Request } // formulate the actual request data USSDPinIssuanceRequest theRequest = PosMessageParser.ParseRequestMessage <USSDPinIssuanceRequest>(theMessage); pinRequest = theRequest as USSDPinIssuanceRequest; pinRequest.Pin = new Random().Next(1111, 9999).ToString(); pinRequest.TerminalId = string.Format("USSD{0}", theRequest.CardPAN.Substring(theRequest.CardPAN.Length - 4)); pinRequest.Function = "pinselection"; Card theCard = null; if (usePrimeHSM) { string staticKeyName = System.Configuration.ConfigurationManager.AppSettings["StaticKeyName"]; string panEncryptionKey = LiteDAO.GetLocalKey(staticKeyName); string encryptedPan = ThalesSim.Core.Cryptography.TripleDES.TripleDESDecrypt(new ThalesSim.Core.Cryptography.HexKey(panEncryptionKey.Substring(0, 32)), pinRequest.CardPAN); theCard = GetCardDetailsFromService(encryptedPan, pinRequest.ExpiryDate); } else { theCard = CardUtilities.RetrieveCard(pinRequest.CardPAN, pinRequest.ExpiryDate, "pc_cards_1_A"); } if (theCard == null) { return("1:Invalid card data"); } if (theCard.expiry_date != pinRequest.ExpiryDate) { return("1:Invalid expiry date"); } response = new PosMessageProcessor().DoPinOffsetUpdate( new PinIssuanceRequest() { CardPAN = pinRequest.CardPAN, ExpiryDate = pinRequest.ExpiryDate, Pin = pinRequest.Pin, ConfirmPin = pinRequest.Pin, TerminalId = pinRequest.TerminalId }, theCard); // pinRequest as PinIssuanceRequest, } catch (Exception ex) { response = string.Format("1:{0}", ex.Message); new PANE.ERRORLOG.Error().LogToFile(ex); } return(response); }