public ThreeDSAuthorization0Response ThreeDSAuthorize0(ThreeDSAuthorization0Request request)
        {
            // Validate request
            RequestValidator.ValidateThreeDSAuthorize0Request(request);
            // Map input request in the XML Request
            var requestXML = RequestMapper.MapThreeDSAuthorization0Request(request, _shopId, _apiResultKey);

            // Calculate and set MAC
            requestXML.Request.MAC = _encoder.GetMac(RequestHandler.GetMacDictionary(requestXML), _apiResultKey);
            // Url Encode ThreeDSData to correctly send it
            requestXML.Data.RequestTag.ThreeDSData = HttpUtility.UrlEncode(requestXML.Data.RequestTag.ThreeDSData);
            var xmlBody = XmlTool.Serialize(requestXML);
            // Do call
            var xmlResponse = _restClient.CallApi(_urlAPI, xmlBody);
            // Map response
            var objectResponse = XmlTool.Deserialize <BPWXmlResponse <Data3DSResponse> >(xmlResponse);

            // Verify Response MAC
            VerifyMacResponse(objectResponse);
            VerifyAuthorization(objectResponse.Data.Authorization);
            VerifyPanAliasData(objectResponse.Data.PanAliasData);
            VerifyThreeDSChallenge(objectResponse.Data.ThreeDSChallenge);
            VerifyThreeDSMethod(objectResponse.Data.ThreeDSMethod);
            return(ResponseMapper.MapThreeDSAuthorization0(objectResponse));
        }
        static ThreeDSAuthorization0Request BuildThreeDSAuthorize0()
        {
            var test = new ThreeDSAuthorization0Request();

            test.Amount         = "6600";
            test.AccountingMode = "D";
            test.Pan            = "4118830900940017";
            test.ExpDate        = "2112";
            test.CVV2           = "111";
            test.Currency       = "978";

            test.Network = "01";
            test.EmailCh = "*****@*****.**";
            Random rand = new Random();

            test.OrderId             = "12345676912345649" + rand.Next(1000);
            test.OperatorID          = "OPERATOR";
            test.Exponent            = "2";
            test.NameCh              = "Mario";
            test.NotifyUrl           = "https://atpostest.ssb.it/atpos/apibo/en/3ds-notification.html";
            test.ThreeDSMtdNotifyUrl = "https://atpostest.ssb.it/atpos/apibo/en/3ds-notification.html";
            test.ThreeDSData         = build3DSData3DS2();
            return(test);
        }
        public static void ValidateThreeDSAuthorize0Request(ThreeDSAuthorization0Request request)
        {
            List <string> fields = new List <string>();

            if (request.OperatorID == null || !Regex.IsMatch(request.OperatorID, PARAMETERS.OPERATORID.PATTERN))
            {
                fields.Add(PARAMETERS.OPERATORID.NAME);
            }
            if (request.OrderId == null || !Regex.IsMatch(request.OrderId, PARAMETERS.ORDERID.PATTERN))
            {
                fields.Add(PARAMETERS.ORDERID.NAME);
            }
            if (request.Pan == null || !Regex.IsMatch(request.Pan, PARAMETERS.PAN.PATTERNGENERIC))
            {
                fields.Add(PARAMETERS.PAN.NAME);
            }
            if (request.CVV2 != null && !Regex.IsMatch(request.CVV2, PARAMETERS.CVV2.PATTERN))
            {
                fields.Add(PARAMETERS.CVV2.NAME);
            }
            if (request.ExpDate == null || !Regex.IsMatch(request.ExpDate, PARAMETERS.EXPDATE.PATTERN))
            {
                fields.Add(PARAMETERS.EXPDATE.NAME);
            }
            if (request.Amount == null || !Regex.IsMatch(request.Amount, PARAMETERS.AMOUNT.PATTERN))
            {
                fields.Add(PARAMETERS.AMOUNT.NAME);
            }
            if (request.Currency == null || !Regex.IsMatch(request.Currency, PARAMETERS.CURRENCY.PATTERN))
            {
                fields.Add(PARAMETERS.CURRENCY.NAME);
            }
            if (request.Exponent == null && request.Currency != PARAMETERS.CURRENCY.EURO)
            {
                fields.Add(PARAMETERS.EXPONENT.NAME);
            }
            if (request.AccountingMode == null || !Regex.IsMatch(request.AccountingMode, PARAMETERS.ACCOUNTINGMODE.PATTERN))
            {
                fields.Add(PARAMETERS.ACCOUNTINGMODE.NAME);
            }
            if (request.Network == null || !Regex.IsMatch(request.Network, PARAMETERS.NETWORK.PATTERN))
            {
                fields.Add(PARAMETERS.NETWORK.NAME);
            }
            if (request.EmailCh != null && !Regex.IsMatch(request.EmailCh, PARAMETERS.EMAIL.PATTERN))
            {
                fields.Add(PARAMETERS.EMAIL.NAMECH);
            }
            if (request.UserId != null && !Regex.IsMatch(request.UserId, PARAMETERS.USERID.PATTERN))
            {
                fields.Add(PARAMETERS.USERID.NAME);
            }
            if (request.Acquirer != null && !Regex.IsMatch(request.Acquirer, PARAMETERS.ACQUIRER.PATTERN))
            {
                fields.Add(PARAMETERS.ACQUIRER.NAME);
            }
            if (request.IpAddress != null && !Regex.IsMatch(request.IpAddress, PARAMETERS.IPADDRESS.PATTERN))
            {
                fields.Add(PARAMETERS.IPADDRESS.NAME);
            }
            if (request.UsrAuthFlag != null && !Regex.IsMatch(request.UsrAuthFlag, PARAMETERS.USRAUTHFLAG.PATTERN))
            {
                fields.Add(PARAMETERS.USRAUTHFLAG.NAME);
            }
            if (request.OpDescr != null && !Regex.IsMatch(request.OpDescr, PARAMETERS.OPDESCR.PATTERN))
            {
                fields.Add(PARAMETERS.OPDESCR.NAME);
            }
            if (request.AntiFraud != null && !Regex.IsMatch(request.AntiFraud, PARAMETERS.ANTIFRAUD.PATTERN))
            {
                fields.Add(PARAMETERS.ANTIFRAUD.NAME);
            }
            if (request.ProductRef != null && !Regex.IsMatch(request.ProductRef, PARAMETERS.PRODUCTREF.PATTERN))
            {
                fields.Add(PARAMETERS.PRODUCTREF.NAME);
            }
            if (request.Name != null && !Regex.IsMatch(request.Name, PARAMETERS.NAME_.PATTERN))
            {
                fields.Add(PARAMETERS.NAME_.NAME);
            }
            if (request.Surname != null && !Regex.IsMatch(request.AntiFraud, PARAMETERS.SURNAME.PATTERN))
            {
                fields.Add(PARAMETERS.SURNAME.NAME);
            }
            if (request.TaxId != null && !Regex.IsMatch(request.TaxId, PARAMETERS.TAXID.PATTERN))
            {
                fields.Add(PARAMETERS.TAXID.NAME);
            }
            if (request.CreatePanAlias != null && !Regex.IsMatch(request.CreatePanAlias, PARAMETERS.CREATEPANALIAS.PATTERN))
            {
                fields.Add(PARAMETERS.CREATEPANALIAS.NAME);
            }
            if (request.ThreeDSData == null)
            {
                fields.Add(PARAMETERS.THREEDSDATA.NAME);
            }
            if (request.NotifyUrl == null)
            {
                fields.Add(PARAMETERS.NOTIFURL.NAME);
            }
            if (fields.Count > 0)
            {
                string message = "";
                foreach (string field in fields)
                {
                    message = message + " " + field;
                }
                throw new VPOSClientException("Invalid Request! The following field/s are not valid or missing:" + message);
            }
        }
        public static BPWXmlRequest <ThreeDSAuthorization0RequestXML> MapThreeDSAuthorization0Request(ThreeDSAuthorization0Request request, string shopId, string apiKey)
        {
            var requestData = new ThreeDSAuthorization0RequestXML
            {
                AccountingMode   = request.AccountingMode,
                Acquirer         = request.Acquirer,
                Amount           = request.Amount,
                Antifraud        = request.AntiFraud,
                ChallengeWinSize = request.ChallengeWinSize,
                CProf            = request.CProf,
                CreatePanAlias   = request.CreatePanAlias,
                Currency         = request.Currency,
                CVV2             = request.CVV2,

                ThreeDSData        = AESEncoder.Encode3DSData(apiKey, request.ThreeDSData.ToJSONString()),
                EmailCH            = request.EmailCh,
                ExpDate            = request.ExpDate,
                Exponent           = request.Exponent,
                IpAddress          = request.IpAddress,
                Name               = request.NameCh,
                NameCH             = request.NameCh,
                Network            = request.Network,
                NotifUrl           = request.NotifyUrl,
                OpDescr            = request.OpDescr,
                OrderID            = request.OrderId,
                Options            = request.Options,
                PAN                = request.Pan,
                ProductRef         = request.ProductRef,
                Surname            = request.Surname,
                TaxID              = request.TaxId,
                ThreeDSMtdNotifUrl = request.ThreeDSMtdNotifyUrl,
                Userid             = request.UserId,
                UsrAuthFlag        = request.UsrAuthFlag
            };
            var requestXML = new BPWXmlRequest <ThreeDSAuthorization0RequestXML>(requestData);

            requestXML.SetHeaderInfo(shopId, request.OperatorID);
            return(requestXML);
        }