PageRenderTime 6ms CodeModel.GetById 10ms app.highlight 37ms RepoModel.GetById 1ms app.codeStats 4ms

/MTData.WebAPI/Controllers/Bad/TransactionRequestController.cs

https://bitbucket.org/stuarthealey/canada
C# | 7067 lines | 5030 code | 1082 blank | 955 comment | 885 complexity | f03191693f6236c5927ffc6e1bdd840f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1
  2using System;
  3using System.Configuration;
  4using System.Collections.ObjectModel;
  5using System.Collections.Generic;
  6using System.Xml.Linq;
  7using System.Globalization;
  8using System.IO;
  9using System.Reflection;
 10using System.Text;
 11using System.Linq;
 12using System.Xml.Linq;
 13using System.Threading;
 14using System.Web.Http;
 15using System.Xml;
 16using System.Xml.Serialization;
 17using MTD.Core.DataTransferObjects;
 18using MTD.Core.Service.Interface;
 19using MTData.WebAPI.Models;
 20using MTData.WebAPI.Resources;
 21using Ninject;
 22using System.Net;
 23using MTData.Utility;
 24using MTData.WebAPI.schema;
 25using System.Web.Configuration;
 26using MTData.WebAPI.Common;
 27using MTData.WebAPI.CanadaCert;
 28using MTData.WebAPI.CanadaCommon;
 29using MTData.WebAPI.schema;
 30namespace MTData.WebAPI.Controllers
 31{
 32    public class TransactionRequestController : BaseController
 33    {
 34        #region Load Constructor
 35        private static int _count = 0;
 36        private const string Ecommerce = "Ecommerce";
 37        private const string Retail = "Retail";
 38        private const string Credit = "Credit";
 39        private const string Debit = "Debit";
 40        private const string TokenOnly = "TokenOnly";
 41        private const string TAKey = "TAKey";
 42        private const string Void = "Void";
 43        private const string Timeout = "Timeout";
 44        private const string Completion = "Completion";
 45        private const string Refund = "Refund";
 46        private const string Authorization = "Authorization";
 47        private const string Visa = "Visa";
 48        private const string Amex = "Amex";
 49        private const string Diners = "Diners";
 50        private const string MasterCard = "MasterCard";
 51        private const string Discover = "Discover";
 52        private const string Sale = "Sale";
 53        private const string EMV2KEY = "EMV2KEY";
 54        private const string FileCRCValue = "3E30";
 55        private const string FileSizeValue = "15593";
 56        private const string ReqFBMaxSizeValue = "999";
 57        private const string CAPKUpdate = "CAPKUpdate";
 58        private const string CAPKDownload = "CAPKDownload";
 59        private const string BookerAppPayment = "BookerAppPayment";
 60        protected string IndustryType;
 61        protected string PaymentType;
 62        private string unreachableUrlResponse;
 63        private int retryCount;
 64        protected string TransactionType;
 65        private static ITerminalService _terminalService;
 66        private StringBuilder _logMessage;
 67        readonly ILogger _logger = new Logger();
 68        public TransactionRequestController([Named("TerminalService")] ITerminalService terminalService, StringBuilder logMessage)
 69            : base(terminalService, logMessage)
 70        {
 71            _terminalService = terminalService;
 72            _logMessage = logMessage;
 73        }
 74
 75        private readonly GMFMessageVariants _gmfMsgVar = new GMFMessageVariants();
 76        private readonly CreditRequestDetails _creditReq = new CreditRequestDetails();                      // Credit request for Ecomm/retail transaction
 77        private readonly PinlessDebitRequestDetails _pinlessDebit = new PinlessDebitRequestDetails();       // Debit request for Ecomm transaction
 78        private readonly DebitRequestDetails _debitReq = new DebitRequestDetails();                         // Debit request for Retail transaction
 79        private readonly AdminRequestDetails _adminReq = new AdminRequestDetails();
 80        private readonly VoidTOReversalRequestDetails _revDetails = new VoidTOReversalRequestDetails();     // Void TO Reversal Request
 81        private readonly TARequestDetails _taRequest = new TARequestDetails();
 82        private readonly MessageProcessor _objMessageProcessor = new MessageProcessor();
 83        public static readonly string StrAppPath = Assembly.GetCallingAssembly().Location;
 84
 85
 86
 87
 88        #endregion
 89
 90        /// <summary>
 91        /// Purpose             :   Finding credit and debit card request of Retail and ecommerce domain for First Data. Transaction Implemented Authorization, Completion, Sale, Refund, Void.
 92        /// Function Name       :   CreateTransactionRequest
 93        /// Created By          :   Salil Gupta
 94        /// Created On          :   03/10/2015
 95        /// Modificatios Made   :   Madhuri Tanwar
 96        /// Modidified On       :   07/27/2015
 97        /// </summary>
 98        /// <param name="transactionRequest"></param>
 99        /// <returns></returns>
100        public IHttpActionResult CreateTransactionRequest(TransactionRequest transactionRequest)
101        {
102            try
103            {
104                _logMessage.Append("Controller Name:-" + GetType().Name + "; Method Name :- " +
105                              MethodBase.GetCurrentMethod().Name + ";");
106                _logMessage.Append(String.Format(CultureInfo.InvariantCulture,
107                    " Date:-" + DateTime.Now.ToShortDateString() + "; Time:- " + DateTime.Now.ToShortTimeString()));
108                string industryType = transactionRequest.IndustryType;
109                string paymentType = transactionRequest.PaymentType.ToString();
110                string transactionType = (transactionRequest.TransactionType == Void || transactionRequest.TransactionType == Timeout)
111                    ? Void
112                    : transactionRequest.TransType.ToString();
113                switch (industryType)
114                {
115                    #region Ecommerce
116                    case Ecommerce:
117
118                        if (paymentType == Credit)
119                        {
120                            switch (transactionType)
121                            {
122                                case Void:
123                                    VoidTOReversalRequestDetails creditRequestVoid = ReversalRequest(transactionRequest);
124                                    return Ok(creditRequestVoid);
125                                default:
126                                    CreditRequestDetails creditRequest = CreateEcommerceRequest(transactionRequest);
127                                    return Ok(creditRequest);
128                            }
129                        }
130                        if (paymentType == Debit)
131                        {
132                            PinlessDebitRequestDetails debitSale = CreatePinlessDebitRequest(transactionRequest);
133                            return Ok(debitSale);
134                        }
135                        break;
136                    #endregion
137
138                    #region Retail
139                    case Retail:
140                        var entryMode = (PaymentEntryMode)Enum.Parse(typeof(PaymentEntryMode), transactionRequest.EntryMode, true);
141                        var txnType = (PaymentTransactionType)Enum.Parse(typeof(PaymentTransactionType), transactionType, true);
142                        switch (entryMode)
143                        {
144                            #region Swiped
145                            case PaymentEntryMode.Swiped:
146                                if (paymentType == PaymentCardType.Credit.ToString())
147                                {
148                                    switch (txnType)
149                                    {
150                                        case PaymentTransactionType.Void:
151                                            VoidTOReversalRequestDetails creditRequestVerification =
152                                                ReversalRequestMsr(transactionRequest);
153                                            return Ok(creditRequestVerification);
154                                        default:
155                                            CreditRequestDetails creditRequest = CreateRetailRequest(transactionRequest);
156                                            return Ok(creditRequest);
157                                    }
158                                }
159                                else if (paymentType == PaymentCardType.Debit.ToString())
160                                {
161                                    DebitRequestDetails debitCard = CreatePinDebitRequest(transactionRequest);
162                                    return Ok(debitCard);
163                                }
164                                break;
165                            #endregion
166
167                            #region FSwiped
168                            case PaymentEntryMode.FSwiped:
169
170                                if (paymentType == PaymentCardType.Credit.ToString())
171                                {
172                                    switch (txnType)
173                                    {
174                                        case PaymentTransactionType.Void:
175                                            VoidTOReversalRequestDetails creditRequestVerification = ReversalRequestEmv(transactionRequest);
176                                            return Ok(creditRequestVerification);
177                                        default: //Full EMV Transaction
178                                            CreditRequestDetails creditRequest = CreateFallbackMsrRequest(transactionRequest);
179                                            return Ok(creditRequest);
180                                    }
181                                }
182
183                                else if (paymentType == PaymentCardType.Debit.ToString())
184                                {
185                                    DebitRequestDetails debitCard = CreateFallbackMsrDebitRequest(transactionRequest);
186                                    return Ok(debitCard);
187                                }
188
189                                break;
190                            #endregion
191
192                            #region EmvContact
193                            case PaymentEntryMode.EmvContact:
194
195                                if (paymentType == PaymentCardType.Credit.ToString())
196                                {
197                                    switch (txnType)
198                                    {
199                                        case PaymentTransactionType.Void:
200                                            VoidTOReversalRequestDetails creditRequestVerification = ReversalRequestEmv(transactionRequest);
201                                            return Ok(creditRequestVerification);
202                                        default: //Full EMV Transaction
203                                            CreditRequestDetails creditRequest = CreateEmvContactRequest(transactionRequest);
204                                            return Ok(creditRequest);
205                                    }
206                                }
207
208                                else if (paymentType == PaymentCardType.Debit.ToString())
209                                {
210                                    DebitRequestDetails debitCard = CreateEmvContactPinDebitRequest(transactionRequest);
211                                    return Ok(debitCard);
212                                }
213
214                                break;
215                            #endregion
216
217                            #region EmvContactless
218                            case PaymentEntryMode.EmvContactless:
219
220                                if (paymentType == PaymentCardType.Credit.ToString())
221                                {
222                                    switch (txnType)
223                                    {
224                                        case PaymentTransactionType.Void:
225                                            VoidTOReversalRequestDetails creditRequestVerification = ReversalRequestEmvContactless(transactionRequest);
226                                            return Ok(creditRequestVerification);
227                                        default: //Full EMV Transaction
228                                            CreditRequestDetails creditRequest = CreateEmvContactlessRequest(transactionRequest);
229                                            return Ok(creditRequest);
230                                    }
231                                }
232
233                                else if (paymentType == PaymentCardType.Debit.ToString())
234                                {
235
236                                    switch (txnType)
237                                    {
238                                        case PaymentTransactionType.Void:
239                                            VoidTOReversalRequestDetails DebitRequestVerification = ReversalRequestDebitEmvContactless(transactionRequest);
240                                            return Ok(DebitRequestVerification);
241                                        default: //Full EMV Transaction
242                                            DebitRequestDetails debitCard = CreateEmvContactlessPinDebitRequest(transactionRequest);
243                                            return Ok(debitCard);
244                                    }
245
246                                }
247
248                                break;
249                            #endregion
250
251                            #region MSRContactless
252                            case PaymentEntryMode.MSRContactless:
253
254                                if (paymentType == PaymentCardType.Credit.ToString())
255                                {
256                                    switch (txnType)
257                                    {
258                                        case PaymentTransactionType.Void:
259                                            VoidTOReversalRequestDetails creditRequestVerification = ReversalRequestMsrContactless(transactionRequest);
260                                            return Ok(creditRequestVerification);
261                                        default:
262                                            CreditRequestDetails creditRequest = CreateMSRContactlessRequest(transactionRequest);
263                                            return Ok(creditRequest);
264                                    }
265                                }
266
267                                else if (paymentType == PaymentCardType.Debit.ToString())
268                                {
269
270                                    switch (txnType)
271                                    {
272                                        case PaymentTransactionType.Void:
273                                            VoidTOReversalRequestDetails DebitRequestVerification = ReversalRequestDebitMsrContactless(transactionRequest);
274                                            return Ok(DebitRequestVerification);
275                                        default: //Full EMV Transaction
276                                            DebitRequestDetails debitCard = CreateCOntactlessMSRPinDebitRequest(transactionRequest);
277                                            return Ok(debitCard);
278                                    }
279
280
281
282                                }
283
284                                break;
285                            #endregion
286
287                        }
288                        break;
289                    #endregion
290
291                    #region Token
292                    case TokenOnly:
293                        TARequestDetails creditTaRequest = TaRequest(transactionRequest);
294                        return Ok(creditTaRequest);
295                        break;
296                    case TAKey:
297                        TARequestDetails creditTaKeyRequest = TaKeyRequest(transactionRequest);
298                        return Ok(creditTaKeyRequest);
299                        break;
300                    #endregion
301
302                    #region CAPK
303                    case CAPKUpdate:
304                        AdminRequestDetails updateAdminRequestDetails = CreateEmvContactUpdateCapkRequest(transactionRequest);
305                        return Ok(updateAdminRequestDetails);
306                        break;
307
308                    case CAPKDownload:
309                        AdminRequestDetails downloadAdminRequestDetails = CreateEmvContactDownloadCapkRequest(transactionRequest);
310                        return Ok(downloadAdminRequestDetails);
311                        break;
312                    #endregion
313
314                    #region bookerApp
315                    case BookerAppPayment:
316                        CreditRequestDetails bookerAppCreditRequest = BookerAppRequest(transactionRequest);
317                        return Ok(bookerAppCreditRequest);
318                        break;
319
320                    #endregion
321
322                }
323            }
324            catch (Exception ex)
325            {
326                _logger.LogInfoFatel(_logMessage.ToString(), ex);
327            }
328            return Ok();
329        }
330
331        /// <summary>
332        /// Purpose             :   Creating credit card request
333        /// Function Name       :   CreateRequest
334        /// Created By          :   Salil Gupta
335        /// Created On          :   03/16/2015
336        /// Modificatios Made   :   ****************************
337        /// Modidified On       :   04/017/2015 "MM/DD/YYYY" 
338        /// </summary>
339        /// <param name="transactionRequest"></param>
340        /// <returns></returns>
341        private CreditRequestDetails CreateEcommerceRequest(TransactionRequest transactionRequest)
342        {
343
344            try
345            {
346                if (!transactionRequest.IsNull())
347                {
348                    _logMessage.Append("Controller Name:-" + GetType().Name + "; Method Name :- " +
349                                          MethodBase.GetCurrentMethod().Name + ";");
350                    _logMessage.Append(String.Format(CultureInfo.InvariantCulture,
351                        " Date:-" + DateTime.Now.ToShortDateString() + "; Time:- " + DateTime.Now.ToShortTimeString()));
352                    MTDTransactionDto mtdTransaction = new MTDTransactionDto();
353                    if (!string.IsNullOrEmpty(transactionRequest.RapidConnectAuthId))
354                    {
355                        mtdTransaction = _terminalService.Completion(
356                           transactionRequest.RapidConnectAuthId,
357                      transactionRequest.SerialNumber, transactionRequest.MtdMerchantId);
358                        if (mtdTransaction.IsNull())
359                            return null;
360                    }
361
362                    #region Common Group
363
364                    CommonGrp cmnGrp = new CommonGrp();
365
366                    /* The payment type of the transaction. */
367                    PymtTypeType typePayment = transactionRequest.PaymentType;
368                    cmnGrp.PymtType = typePayment;
369                    cmnGrp.PymtTypeSpecified = true;
370                    /* merchant category code. */
371                    cmnGrp.MerchCatCode = transactionRequest.MCCode;
372                    /* The type of transaction being performed. */
373                    cmnGrp.TxnType = transactionRequest.TransType;
374                    cmnGrp.TxnTypeSpecified = true;
375                    /* The local date and time in which the transaction was performed. */
376                    cmnGrp.LocalDateTime = transactionRequest.LocalDateTime;//DateTime.Now.ToString("yyyyMMddHHmmss");
377                    /* The transmission date and time of the transaction (in GMT/UCT). */
378                    cmnGrp.TrnmsnDateTime = transactionRequest.TrnmsnDateTime;//DateTime.UtcNow.ToString("yyyyMMddHHmmss");
379                    /* A number assigned by the merchant to uniquely reference the transaction. 
380                     * This number must be unique within a day per Merchant ID per Terminal ID. */
381                    cmnGrp.STAN = GetSystemTraceNumber(transactionRequest.MtdMerchantId, transactionRequest.TerminalId);
382
383                    if (string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
384                    {
385                        cmnGrp.RefNum = mtdTransaction.TransRefNo;
386                        cmnGrp.OrderNum = mtdTransaction.TransOrderNo;
387                    }
388                    else
389                    {
390                        cmnGrp.RefNum = GetReferenceNumber(transactionRequest.MtdMerchantId, transactionRequest.TerminalId);
391                        cmnGrp.OrderNum = cmnGrp.RefNum;
392                    }
393                    /* An ID assigned by First Data, for the Third Party Processor or 
394                     * Software Vendor that generated the transaction. */
395                    cmnGrp.TPPID = transactionRequest.TppId;
396
397                    /* A unique ID assigned to a terminal. */
398                    cmnGrp.TermID = transactionRequest.TerminalId;
399                    /* A unique ID assigned by First Data, to identify the Merchant. */
400                    cmnGrp.MerchID = transactionRequest.FdMerchantId;
401
402                    cmnGrp.GroupID = transactionRequest.GroupId;
403                    //Group ID value will be assigned by First Data. 
404                    //get terminal id from transaction request
405                    cmnGrp.POSEntryMode = PaymentAPIResources.EcomPosEntryMode;
406                    cmnGrp.POSCondCode = POSCondCodeType.Item59;
407                    cmnGrp.POSCondCodeSpecified = true;
408                    cmnGrp.TermCatCode = TermCatCodeType.Item00;
409                    cmnGrp.TermCatCodeSpecified = true;
410                    cmnGrp.TermEntryCapablt = TermEntryCapabltType.Item10;
411                    cmnGrp.TermEntryCapabltSpecified = true;
412                    cmnGrp.TermLocInd = TermLocIndType.Item1;
413                    cmnGrp.TermLocIndSpecified = true;
414                    cmnGrp.CardCaptCap = CardCaptCapType.Item0;
415                    cmnGrp.CardCaptCapSpecified = true;
416
417                    EcommGrp ecomgrp = new EcommGrp();
418                    ecomgrp.EcommTxnInd = EcommTxnIndType.Item03;
419                    ecomgrp.EcommTxnIndSpecified = true;
420                    if (!string.Equals(cmnGrp.TxnType.ToString(), Authorization, StringComparison.CurrentCultureIgnoreCase))
421                        ecomgrp.EcommURL = PaymentAPIResources.EcomUrl;
422                    _creditReq.EcommGrp = ecomgrp;
423
424                    /* The amount of the transaction. This may be an authorization amount, 
425                     * adjustment amount or a reversal    based on the type of transaction. 
426                     * It is inclusive of all additional amounts. 
427                     * It is submitted in the currency represented by the Transaction Currency field.  
428                     * The field is overwritten in the response for a partial authorization. */
429                    double num = Convert.ToDouble(transactionRequest.TransactionAmount);
430                    string amt = num.ToString("0.00").Replace(".", string.Empty);
431                    cmnGrp.TxnAmt = Convert.ToString(amt);
432                    cmnGrp.TxnAmt = cmnGrp.TxnAmt.PadLeft(12, '0');
433
434                    cmnGrp.TxnCrncy = PaymentAPIResources.Cur_USA;
435                    /* An indicator that describes the location of the terminal. */
436                    /* Indicates Group ID. */
437                    _creditReq.CommonGrp = cmnGrp;
438                    #endregion
439
440                    CardGrp cardGrp = new CardGrp();
441
442
443                    #region Transarmor group
444                    if (string.Equals(cmnGrp.TxnType.ToString(), Authorization, StringComparison.CurrentCultureIgnoreCase) || string.Equals(cmnGrp.TxnType.ToString(), Sale, StringComparison.CurrentCultureIgnoreCase))
445                    {
446
447                        cardGrp.AcctNum = transactionRequest.CardNumber;
448                        cardGrp.CardExpiryDate = transactionRequest.ExpiryDate;
449                        cardGrp.CardType = transactionRequest.CardType;
450                        cardGrp.CardTypeSpecified = true;
451                        cardGrp.CCVInd = CCVIndType.Prvded;
452                        cardGrp.CCVIndSpecified = true;
453                        cardGrp.CCVData = transactionRequest.CardCvv;
454                        _creditReq.CardGrp = cardGrp;
455
456                        TAGrp taGrp = new TAGrp();
457                        taGrp.SctyLvl = SctyLvlType.Tknizatn;
458                        taGrp.SctyLvlSpecified = true;
459                        taGrp.TknType = transactionRequest.TokenType;
460                        _creditReq.TAGrp = taGrp;
461                    }
462                    if (string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.CurrentCultureIgnoreCase))
463                    {
464                        if (mtdTransaction != null)
465                        {
466                            XmlDocument xmlDoc = new XmlDocument();
467                            xmlDoc.LoadXml(mtdTransaction.ResponseXml);
468                            string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
469                            var response = CommonFunctions.GetMCResponse(xmlString);
470                            xmlDoc.LoadXml(response);
471                            var aVSResultCode = xmlDoc.SelectSingleNode("CreditResponse/CardGrp/AVSResultCode");
472                            var cCVResultCode = xmlDoc.SelectSingleNode("CreditResponse/CardGrp/CCVResultCode");
473                            cardGrp.CardType = transactionRequest.CardType;
474                            cardGrp.CardTypeSpecified = true;
475                            if (aVSResultCode != null)
476                            {
477                                cardGrp.AVSResultCode = (AVSResultCodeType)Enum.Parse(typeof(AVSResultCodeType), aVSResultCode.InnerText);
478                                cardGrp.AVSResultCodeSpecified = true;
479                            }
480                            if (cCVResultCode != null)
481                            {
482                                cardGrp.CCVResultCode = (CCVResultCodeType)Enum.Parse(typeof(CCVResultCodeType), cCVResultCode.InnerText);
483                                cardGrp.CCVResultCodeSpecified = true;
484                            }
485                        }
486                        _creditReq.CardGrp = cardGrp;
487
488                        TAGrp taGrp = new TAGrp();
489                        taGrp.SctyLvl = SctyLvlType.Tknizatn;
490                        taGrp.SctyLvlSpecified = true;
491                        taGrp.Tkn = mtdTransaction.CardToken.Decrypt();
492                        taGrp.TknType = transactionRequest.TokenType;
493                        _creditReq.TAGrp = taGrp;
494
495                    }
496                    if (string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.CurrentCultureIgnoreCase))
497                    {
498                        cardGrp.CardType = transactionRequest.CardType;
499                        cardGrp.CardTypeSpecified = true;
500                        _creditReq.CardGrp = cardGrp;
501
502                        TAGrp taGrp = new TAGrp();
503                        taGrp.SctyLvl = SctyLvlType.Tknizatn;
504                        taGrp.SctyLvlSpecified = true;
505                        taGrp.Tkn = mtdTransaction.CardToken.Decrypt();
506                        taGrp.TknType = transactionRequest.TokenType;
507                        _creditReq.TAGrp = taGrp;
508                    }
509                    #endregion
510                    if (!string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase) && !string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.OrdinalIgnoreCase))
511                    {
512                        #region Additional Amount Group
513                        AddtlAmtGrp addAmtGrp = new AddtlAmtGrp();
514                        addAmtGrp.PartAuthrztnApprvlCapablt = PartAuthrztnApprvlCapabltType.Item1;
515                        addAmtGrp.PartAuthrztnApprvlCapabltSpecified = true;
516                        AddtlAmtGrp[] addAmtGrpArr = new AddtlAmtGrp[1];
517                        addAmtGrpArr[0] = addAmtGrp;
518                        _creditReq.AddtlAmtGrp = addAmtGrpArr;
519                        #endregion
520                    }
521                    #region Visa Group
522                    if (string.Equals(cardGrp.CardType.ToString(), Visa, StringComparison.OrdinalIgnoreCase) && !string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.OrdinalIgnoreCase))
523                    {
524                        VisaGrp visaGrp = new VisaGrp();
525                        visaGrp.VisaBID = PaymentAPIResources.VisaBID;
526                        visaGrp.VisaAUAR = PaymentAPIResources.VisaAUAR;
527                        if (!string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
528                        {
529                            visaGrp.ACI = ACIType.Y;
530                            visaGrp.ACISpecified = true;
531                            visaGrp.TaxAmtCapablt = TaxAmtCapabltType.Item1;
532                            visaGrp.TaxAmtCapabltSpecified = true;
533                        }
534                        else
535                        {
536                            visaGrp.ACI = ACIType.T;
537                            visaGrp.ACISpecified = true;
538                        }
539                        _creditReq.Item = visaGrp;
540                    }
541                    if (((string.Equals(cardGrp.CardType.ToString(), MasterCard, StringComparison.OrdinalIgnoreCase)) && (string.Equals(cmnGrp.TxnType.ToString(), "completion", StringComparison.OrdinalIgnoreCase))))
542                    {
543                        MCGrp mcGrp = new MCGrp();
544                        XmlDocument xmlDoc = new XmlDocument();
545                        xmlDoc.LoadXml(mtdTransaction.ResponseXml);
546                        string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
547                        var response = CommonFunctions.GetMCResponse(xmlString);
548                        xmlDoc.LoadXml(response);
549                        var banknetData = xmlDoc.SelectSingleNode("CreditResponse/MCGrp/BanknetData");
550                        if (banknetData != null) { mcGrp.BanknetData = banknetData.InnerText; }
551                        _creditReq.Item = mcGrp;
552                    }
553                    #endregion
554
555                    #region AmexGrp Group
556                    if (string.Equals(cardGrp.CardType.ToString(), Amex, StringComparison.OrdinalIgnoreCase) && string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
557                    {
558                        AmexGrp amexgrp = new AmexGrp();
559                        if (mtdTransaction != null)
560                        {
561                            amexgrp.AmExTranID = mtdTransaction.GatewayTxnId;
562                            XmlDocument xmlDoc = new XmlDocument();
563                            xmlDoc.LoadXml(mtdTransaction.ResponseXml);
564                            string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
565                            var response = CommonFunctions.GetMCResponse(xmlString);
566                            xmlDoc.LoadXml(response);
567                            var amExPOSData = xmlDoc.SelectSingleNode("CreditResponse/AmexGrp/AmExPOSData");
568                            if (amExPOSData != null)
569                            { amexgrp.AmExPOSData = amExPOSData.InnerText; }
570                        }
571                        _creditReq.Item = amexgrp;
572
573                    }
574                    #endregion
575
576                    #region Discover Group
577                    if ((string.Equals(cardGrp.CardType.ToString(), Diners, StringComparison.OrdinalIgnoreCase) || string.Equals(cardGrp.CardType.ToString(), Discover, StringComparison.OrdinalIgnoreCase) || string.Equals(cardGrp.CardType.ToString(), "JCB", StringComparison.OrdinalIgnoreCase)) && string.Equals(cmnGrp.TxnType.ToString(), "completion", StringComparison.OrdinalIgnoreCase))
578                    {
579                        DSGrp dsGrp = new DSGrp();
580                        if (mtdTransaction != null)
581                        {
582                            XmlDocument xmlDoc = new XmlDocument();
583                            xmlDoc.LoadXml(mtdTransaction.ResponseXml);
584                            string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
585                            var response = CommonFunctions.GetMCResponse(xmlString);
586                            xmlDoc.LoadXml(response);
587                            var discProcCode = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscProcCode");
588                            if (discProcCode != null)
589                            {
590                                dsGrp.DiscProcCode = discProcCode.InnerText;
591
592                            }
593
594                            var discPOSEntry = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscPOSEntry");
595                            if (discPOSEntry != null)
596                            {
597                                dsGrp.DiscPOSEntry = discPOSEntry.InnerText;
598
599                            }
600
601                            var discRespCode = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscRespCode");
602                            if (discRespCode != null)
603                            {
604                                dsGrp.DiscRespCode = discRespCode.InnerText;
605
606                            }
607
608                            var discPOSData = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscPOSData");
609                            if (discPOSData != null)
610                            {
611                                dsGrp.DiscPOSData = discPOSData.InnerText;
612
613                            }
614
615                            var discTransQualifier = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscTransQualifier");
616                            if (discTransQualifier != null)
617                            {
618                                dsGrp.DiscTransQualifier = discTransQualifier.InnerText;
619
620                            }
621
622                            var discNRID = xmlDoc.SelectSingleNode("CreditResponse/DSGrp/DiscNRID");
623                            if (discNRID != null)
624                            {
625                                dsGrp.DiscNRID = discNRID.InnerText;
626
627                            }
628
629                            dsGrp.DiscNRID = mtdTransaction.GatewayTxnId;
630                        }
631
632
633                        _creditReq.Item = dsGrp;
634                    }
635                    #endregion
636
637                    #region Customer info Group
638                    if (!string.IsNullOrEmpty(transactionRequest.StreetAddress) || !string.IsNullOrEmpty(transactionRequest.ZipCode))
639                    {
640                        if (!string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.OrdinalIgnoreCase) && !string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
641                        {
642                            CustInfoGrp custinfo = new CustInfoGrp();
643                            if (!string.IsNullOrEmpty(transactionRequest.StreetAddress))
644                            {
645                                custinfo.AVSBillingAddr = transactionRequest.StreetAddress;
646                            }
647                            if (!string.IsNullOrEmpty(transactionRequest.ZipCode))
648                            {
649                                custinfo.AVSBillingPostalCode = transactionRequest.ZipCode;
650                            }
651                            _creditReq.CustInfoGrp = custinfo;
652                        }
653                    }
654                    #endregion
655
656                    #region addAm Group
657
658                    if (string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
659                    {
660                        AddtlAmtGrp addAmtGrp = new AddtlAmtGrp();
661
662                        if (mtdTransaction != null)
663                        {
664                            XmlDocument xmlDoc = new XmlDocument();
665                            xmlDoc.LoadXml(mtdTransaction.ResponseXml);
666                            string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
667                            var response = CommonFunctions.GetMCResponse(xmlString);
668                            xmlDoc.LoadXml(response);
669                            var originalamt = xmlDoc.SelectSingleNode("CreditResponse/CommonGrp/TxnAmt");
670                            if (originalamt != null)
671                            {
672                                var amountP = originalamt.InnerText;
673                                addAmtGrp.AddAmt = amountP.PadLeft(12, '0');
674
675
676                            }
677
678                            addAmtGrp.AddAmtCrncy = PaymentAPIResources.Cur_USA;
679                            addAmtGrp.AddAmtType = AddAmtTypeType.FirstAuthAmt;
680                            addAmtGrp.AddAmtTypeSpecified = true;
681
682                            AddtlAmtGrp addAmtGrp1 = new AddtlAmtGrp();
683
684                            var originalamt1 = xmlDoc.SelectSingleNode("CreditResponse/CommonGrp/TxnAmt");
685                            if (originalamt1 != null)
686                            {
687                                var amtP = originalamt1.InnerText;
688                                addAmtGrp1.AddAmt = amtP.PadLeft(12, '0');
689
690                            }
691
692                            addAmtGrp1.AddAmtCrncy = PaymentAPIResources.Cur_USA;
693                            addAmtGrp1.AddAmtType = AddAmtTypeType.TotalAuthAmt;
694                            addAmtGrp1.AddAmtTypeSpecified = true;
695
696                            AddtlAmtGrp[] addAmtGrpArr = new AddtlAmtGrp[2];
697                            addAmtGrpArr[0] = addAmtGrp;
698                            addAmtGrpArr[1] = addAmtGrp1;
699                            _creditReq.AddtlAmtGrp = addAmtGrpArr;
700                        }
701
702                        OrigAuthGrp orgAuthgrp = new OrigAuthGrp();
703                        if (mtdTransaction != null)
704                        {
705                            orgAuthgrp.OrigAuthID = mtdTransaction.AuthId;
706
707                            orgAuthgrp.OrigLocalDateTime = mtdTransaction.LocalDateTime;
708                            XmlDocument xmlDoc = new XmlDocument();
709                            xmlDoc.LoadXml(mtdTransaction.RequestXml);
710                            var trnmsnDateTime = xmlDoc.SelectSingleNode("TransactionRequest/TrnmsnDateTime");
711                            if (trnmsnDateTime != null)
712                            {
713                                orgAuthgrp.OrigTranDateTime = trnmsnDateTime.InnerText;
714
715                            }
716
717                            orgAuthgrp.OrigSTAN = Convert.ToString(mtdTransaction.Stan);
718                            orgAuthgrp.OrigRespCode = Convert.ToString(mtdTransaction.ResponseCode);
719                        }
720                        _creditReq.OrigAuthGrp = orgAuthgrp;
721
722                    }
723                    #endregion
724
725
726
727                    _gmfMsgVar.Item = _creditReq;
728                    transactionRequest.Stan = cmnGrp.STAN;
729                    transactionRequest.TransRefNo = cmnGrp.RefNum;
730                    transactionRequest.TransOrderNo = cmnGrp.OrderNum;
731                    return _creditReq;
732                }
733            }
734            catch (Exception ex)
735            {
736                _logger.LogInfoFatel(_logMessage.ToString(), ex);
737            }
738            return null;
739        }
740
741        /// <summary>
742        /// Purpose             :   Creating credit card request
743        /// Function Name       :   CreateRequest
744        /// Created By          :   Salil Gupta
745        /// Created On          :   03/16/2015
746        /// Modificatios Made   :   Madhuri Tanwar
747        /// Modidified On       :   06/012/2015 "MM/DD/YYYY" 
748        /// </summary>
749        /// <param name="transactionRequest"></param>
750        /// <returns></returns>
751        private CreditRequestDetails CreateRetailRequest(TransactionRequest transactionRequest)
752        {
753
754            try
755            {
756                if (!transactionRequest.IsNull())
757                {
758                    _logMessage.Append("Controller Name:-" + GetType().Name + "; Method Name :- " +
759                                          MethodBase.GetCurrentMethod().Name + ";");
760                    _logMessage.Append(String.Format(CultureInfo.InvariantCulture,
761                        " Date:-" + DateTime.Now.ToShortDateString() + "; Time:- " + DateTime.Now.ToShortTimeString()));
762                    MTDTransactionDto mtdTransaction = new MTDTransactionDto();
763                    if (!string.IsNullOrEmpty(transactionRequest.RapidConnectAuthId))
764                    {
765                        mtdTransaction = _terminalService.Completion(
766                           transactionRequest.RapidConnectAuthId,
767                      transactionRequest.SerialNumber, transactionRequest.MtdMerchantId);
768                        if (mtdTransaction.IsNull())
769                            return null;
770                    }
771
772                    #region Common Group
773
774                    CommonGrp cmnGrp = new CommonGrp();
775
776                    /* The payment type of the transaction. */
777                    PymtTypeType typePayment = transactionRequest.PaymentType;
778                    cmnGrp.PymtType = typePayment;
779                    cmnGrp.PymtTypeSpecified = true;
780                    /* merchant category code. */
781                    cmnGrp.MerchCatCode = transactionRequest.MCCode;
782                    /* The type of transaction being performed. */
783                    cmnGrp.TxnType = transactionRequest.TransType;
784                    cmnGrp.TxnTypeSpecified = true;
785                    /* The local date and time in which the transaction was performed. */
786                    cmnGrp.LocalDateTime = transactionRequest.LocalDateTime;//DateTime.Now.ToString("yyyyMMddHHmmss");
787                    /* The transmission date and time of the transaction (in GMT/UCT). */
788                    cmnGrp.TrnmsnDateTime = transactionRequest.TrnmsnDateTime;//DateTime.UtcNow.ToString("yyyyMMddHHmmss");
789                    /* A number assigned by the merchant to uniquely reference the transaction. 
790                     * This number must be unique within a day per Merchant ID per Terminal ID. */
791                    cmnGrp.STAN = GetSystemTraceNumber(transactionRequest.MtdMerchantId, transactionRequest.TerminalId);
792                    /* A number assigned by the merchant to uniquely reference a set of transactions. */
793                    //cmnGrp.RefNum = GetReferenceNumber(transactionRequest.MerchantID, transactionRequest.TerminalID);//"480061115979";
794                    if (string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
795                    {
796                        cmnGrp.RefNum = mtdTransaction.TransRefNo;
797                        cmnGrp.OrderNum = mtdTransaction.TransOrderNo;
798                    }
799                    else
800                    {
801                        cmnGrp.RefNum = GetReferenceNumber(transactionRequest.MtdMerchantId, transactionRequest.TerminalId);
802                        cmnGrp.OrderNum = cmnGrp.RefNum;
803                    }
804                    /* An ID assigned by First Data, for the Third Party Processor or 
805                     * Software Vendor that generated the transaction. */
806                    cmnGrp.TPPID = transactionRequest.TppId;
807
808                    /* A unique ID assigned to a terminal. */
809                    cmnGrp.TermID = transactionRequest.TerminalId;
810
811                    //get terminal id from transaction request
812
813                    /* A unique ID assigned by First Data, to identify the Merchant. */
814                    cmnGrp.MerchID = transactionRequest.FdMerchantId;
815
816                    cmnGrp.GroupID = transactionRequest.GroupId;
817                    //Group ID value will be assigned by First Data. 
818                    //get terminal id from transaction request
819                    cmnGrp.POSEntryMode = PaymentAPIResources.RetailPosEntryMode;
820                    cmnGrp.POSCondCode = POSCondCodeType.Item00;
821                    cmnGrp.POSCondCodeSpecified = true;
822                    cmnGrp.TermCatCode = TermCatCodeType.Item01;
823                    cmnGrp.TermCatCodeSpecified = true;
824                    cmnGrp.TermEntryCapablt = TermEntryCapabltType.Item04;
825                    cmnGrp.TermEntryCapabltSpecified = true;
826                    cmnGrp.TermLocInd = TermLocIndType.Item0;
827                    cmnGrp.TermLocIndSpecified = true;
828                    cmnGrp.CardCaptCap = CardCaptCapType.Item1;
829                    cmnGrp.CardCaptCapSpecified = true;
830
831                    /* The amount of the transaction. This may be an authorization amount, 
832                     * adjustment amount or a reversal amount based on the type of transaction. 
833                     * It is inclusive of all additional amounts. 
834                     * It is submitted in the currency represented by the Transaction Currency field.  
835                     * The field is overwritten in the response for a partial authorization. */
836
837                    double num = Convert.ToDouble(transactionRequest.TransactionAmount);
838                    string amt = num.ToString("0.00").Replace(".", string.Empty);
839                    cmnGrp.TxnAmt = Convert.ToString(amt);
840                    cmnGrp.TxnAmt = cmnGrp.TxnAmt.PadLeft(12, '0');
841
842                    /* The numeric currency of the Transaction Amount. */
843                    cmnGrp.TxnCrncy = PaymentAPIResources.Cur_USA;
844
845                    _creditReq.CommonGrp = cmnGrp;
846                    #endregion
847
848                    #region Transarmor group
849                    CardGrp cardGrp = new CardGrp();
850                    if (string.Equals(cmnGrp.TxnType.ToString(), Authorization, StringComparison.CurrentCultureIgnoreCase) || string.Equals(cmnGrp.TxnType.ToString(), Sale, StringComparison.CurrentCultureIgnoreCase))
851                    {
852
853                        cardGrp.CardType = transactionRequest.CardType;
854                        cardGrp.CardTypeSpecified = true;
855                        _creditReq.CardGrp = cardGrp;
856
857                        TAGrp taGrp = new TAGrp();
858                        taGrp.SctyLvl = SctyLvlType.EncrptTknizatn;
859                        taGrp.SctyLvlSpecified = true;
860                        taGrp.EncrptType = EncrptTypeType.RSA;
861                        taGrp.EncrptTypeSpecified = true;
862                        taGrp.EncrptTrgt = EncrptTrgtType.Track2;
863                        taGrp.EncrptTrgtSpecified = true;
864                        taGrp.KeyID = transactionRequest.KeyId;
865                        taGrp.EncrptBlock = transactionRequest.Track3Data;
866                        taGrp.TknType = transactionRequest.TokenType;
867                        _creditReq.TAGrp = taGrp;
868
869                    }
870                    if (string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.CurrentCultureIgnoreCase) || string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.CurrentCultureIgnoreCase))
871                    {
872                        if (mtdTransaction != null) cardGrp.CardType = (CardTypeType)Enum.Parse(typeof(CardTypeType), mtdTransaction.CardType);
873                        transactionRequest.CardType = cardGrp.CardType;
874                        cardGrp.CardTypeSpecified = true;
875                        _creditReq.CardGrp = cardGrp;
876
877                        TAGrp taGrp = new TAGrp();
878                        taGrp.SctyLvl = SctyLvlType.EncrptTknizatn;
879                        taGrp.SctyLvlSpecified = true;
880                        taGrp.Tkn = mtdTransaction.CardToken.Decrypt();
881                        taGrp.TknType = transactionRequest.TokenType;
882                        _creditReq.TAGrp = taGrp;
883                    }
884                    #endregion
885                    if (!string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase) && !string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.OrdinalIgnoreCase))
886                    {
887                        #region Additional Amount Group
888                        AddtlAmtGrp addAmtGrp = new AddtlAmtGrp();
889                        addAmtGrp.PartAuthrztnApprvlCapablt = PartAuthrztnApprvlCapabltType.Item1;
890                        addAmtGrp.PartAuthrztnApprvlCapabltSpecified = true;
891                        AddtlAmtGrp[] addAmtGrpArr = new AddtlAmtGrp[1];
892                        addAmtGrpArr[0] = addAmtGrp;
893                        _creditReq.AddtlAmtGrp = addAmtGrpArr;
894                        #endregion
895                    }
896
897                    #region Visa Group
898                    if (string.Equals(cardGrp.CardType.ToString(), Visa, StringComparison.OrdinalIgnoreCase) && !string.Equals(cmnGrp.TxnType.ToString(), Refund, StringComparison.OrdinalIgnoreCase))
899                    {
900                        VisaGrp visaGrp = new VisaGrp();
901                        visaGrp.VisaBID = PaymentAPIResources.VisaBID;
902                        visaGrp.VisaAUAR = PaymentAPIResources.VisaAUAR;
903                        if (!string.Equals(cmnGrp.TxnType.ToString(), Completion, StringComparison.OrdinalIgnoreCase))
904                        {
905                            visaGrp.ACI = ACIType.Y;
906                            visaGrp.ACISpecified = true;
907                            visaGrp.TaxAmtCapablt = TaxAmtCapabltType.Item1;
908                            visaGrp.TaxAmtCapabltSpecified = true;
909                        }
910                        else
911
912                            if (mtdTransaction != null)
913                            {
914                                XmlDocument xmlDoc = new XmlDocument();
915                                xmlDoc.LoadXml(mtdTransaction.ResponseXml);
916                                string xmlString = CommonFunctions.GetXmlAsString(xmlDoc);
917                                var response = CommonFunctions.GetMCResponse(xmlString);
918                                xmlDoc.LoadXml(response);
919                                var aCI = xmlDoc.SelectSingleNode("CreditResponse/VisaGrp/ACI");
920                                if (aCI != null)
921                                {
922                                    visaGrp.ACI = (ACIType)Enum.Parse(typeof(ACIType), aCI.InnerText);
923                                    visaGrp.ACISpecified = true;
924
925                                }
926
927                                var cardLevelResult = xmlDoc.SelectSingleNode("CreditResponse/VisaGrp/CardLevelResult");
928                                if (cardLevelResult != null)
929                                {
930         

Large files files are truncated, but you can click here to view the full file