internal static Response ConvertTo(VoidResponse voidResponse)
        {
            var response = new Response();

            voidResponse.WriteBaseProperties(response);

            var properties = new List <PaymentProperty>();

            if (response.Properties != null)
            {
                properties.AddRange(response.Properties);
            }

            var voidRespnseProperties = new List <PaymentProperty>();

            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.CardType, voidResponse.CardType);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.Last4Digits, voidResponse.Last4Digit);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.UniqueCardId, voidResponse.UniqueCardId);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.ProviderTransactionId, voidResponse.ProviderTransactionId);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.ResponseCode, voidResponse.ResponseCode);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.CurrencyCode, voidResponse.CurrencyCode);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.VoidResult, voidResponse.VoidResult);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.ProviderMessage, voidResponse.ProviderMessage);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.TransactionType, voidResponse.TransactionType);
            PaymentUtilities.AddPropertyIfPresent(voidRespnseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.TransactionDateTime, voidResponse.TransactionDateTime);
            properties.Add(new PaymentProperty(GenericNamespace.VoidResponse, VoidResponseProperties.Properties, voidRespnseProperties.ToArray()));

            response.Properties = properties.ToArray();
            return(response);
        }
        internal static Response ConvertTo(GenerateCardTokenResponse tokenizeResponse)
        {
            var response = new Response();

            tokenizeResponse.WriteBaseProperties(response);

            var properties = new List <PaymentProperty>();

            if (response.Properties != null)
            {
                properties.AddRange(response.Properties);
            }

            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.CardType, tokenizeResponse.CardType);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.Last4Digits, tokenizeResponse.Last4Digit);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.CardToken, tokenizeResponse.CardToken);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.UniqueCardId, tokenizeResponse.UniqueCardId);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.ExpirationYear, tokenizeResponse.ExpirationYear);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.ExpirationMonth, tokenizeResponse.ExpirationMonth);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.Name, tokenizeResponse.Name);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.StreetAddress, tokenizeResponse.StreetAddress);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.StreetAddress2, tokenizeResponse.StreetAddress2);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.City, tokenizeResponse.City);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.State, tokenizeResponse.State);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.PostalCode, tokenizeResponse.PostalCode);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.Country, tokenizeResponse.Country);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.Phone, tokenizeResponse.Phone);
            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.PaymentCard, PaymentCardProperties.AccountType, tokenizeResponse.AccountType);
            properties.AddRange(tokenizeResponse.OtherCardProperties);

            response.Properties = properties.ToArray();
            return(response);
        }
Пример #3
0
        internal static Response ConvertTo(GetPaymentAcceptPointResponse acceptPointResponse)
        {
            var response = new Response();

            acceptPointResponse.WriteBaseProperties(response);

            var properties = new List <PaymentProperty>();

            if (response.Properties != null)
            {
                properties.AddRange(response.Properties);
            }

            PaymentUtilities.AddPropertyIfPresent(properties, GenericNamespace.TransactionData, TransactionDataProperties.PaymentAcceptUrl, acceptPointResponse.PaymentAcceptUrl);

            response.Properties = properties.ToArray();
            return(response);
        }
        internal static Response ConvertTo(AuthorizeResponse authorizeResponse)
        {
            var response = new Response();

            authorizeResponse.WriteBaseProperties(response);

            var properties = new List <PaymentProperty>();

            if (response.Properties != null)
            {
                properties.AddRange(response.Properties);
            }

            var authorizationRespnseProperties = new List <PaymentProperty>();

            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CardType, authorizeResponse.CardType);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.IsSwiped, authorizeResponse.IsSwipe.ToString());
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Last4Digits, authorizeResponse.Last4Digit);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CardToken, authorizeResponse.CardToken);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.UniqueCardId, authorizeResponse.UniqueCardId);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.VoiceAuthorizationCode, authorizeResponse.VoiceAuthorizationCode);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CashBackAmount, authorizeResponse.CashBackAmount);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AccountType, authorizeResponse.AccountType);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ProviderTransactionId, authorizeResponse.ProviderTransactionId);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ApprovalCode, authorizeResponse.ApprovalCode);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ResponseCode, authorizeResponse.ResponseCode);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ApprovedAmount, authorizeResponse.ApprovedAmount);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CurrencyCode, authorizeResponse.CurrencyCode);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AuthorizationResult, authorizeResponse.AuthorizationResult);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ProviderMessage, authorizeResponse.ProviderMessage);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AVSResult, authorizeResponse.AVSResult);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AVSDetail, authorizeResponse.AVSDetail);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CVV2Result, authorizeResponse.CVV2Result);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AvailableBalance, authorizeResponse.AvailableBalance);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.TransactionType, authorizeResponse.TransactionType);
            PaymentUtilities.AddPropertyIfPresent(authorizationRespnseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.TransactionDateTime, authorizeResponse.TransactionDateTime);
            properties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Properties, authorizationRespnseProperties.ToArray()));

            response.Properties = properties.ToArray();
            return(response);
        }
        internal static VoidRequest ConvertFrom(Request request)
        {
            var voidRequest = new VoidRequest();
            var errors      = new List <PaymentError>();

            voidRequest.ReadBaseProperties(request, errors);

            // Check authorization response
            var                         hashtable = PaymentProperty.ConvertToHashtable(request.Properties);
            PaymentProperty             authorizationResponsePropertyList = PaymentProperty.GetPropertyFromHashtable(hashtable, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Properties);
            Dictionary <string, object> authorizationHashtable            = null;

            if (authorizationResponsePropertyList == null)
            {
                errors.Add(new PaymentError(ErrorCode.InvalidRequest, "Authorization response is missing."));
                throw new SampleException(errors);
            }
            else
            {
                authorizationHashtable = PaymentProperty.ConvertToHashtable(authorizationResponsePropertyList.PropertyList);
            }

            // Read card data
            voidRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CardType,
                errors,
                ErrorCode.InvalidRequest);
            voidRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.IsSwiped,
                false);
            voidRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CardToken);
            voidRequest.Last4Digit = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.Last4Digits);
            voidRequest.AccountType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.AccountType);
            voidRequest.UniqueCardId = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.UniqueCardId);
            voidRequest.VoiceAuthorizationCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.VoiceAuthorizationCode);

            // Read authorization data
            voidRequest.AuthorizationTransactionType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.TransactionType,
                errors,
                ErrorCode.InvalidRequest);
            if (voidRequest.AuthorizationTransactionType != null &&
                !TransactionType.Authorize.ToString().Equals(voidRequest.AuthorizationTransactionType, StringComparison.OrdinalIgnoreCase))
            {
                errors.Add(new PaymentError(ErrorCode.InvalidTransaction, "Void does not support this type of transaction"));
            }

            voidRequest.AuthorizationApprovalCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ApprovalCode);
            voidRequest.AuthorizationApprovedAmount = PaymentUtilities.GetPropertyDecimalValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ApprovedAmount,
                errors,
                ErrorCode.InvalidRequest);
            voidRequest.CurrencyCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CurrencyCode,
                errors,
                ErrorCode.InvalidRequest);
            voidRequest.AuthorizationCashbackAmount = PaymentUtilities.GetPropertyDecimalValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CashBackAmount);
            voidRequest.AuthorizationProviderMessage = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ProviderMessage);
            voidRequest.AuthorizationProviderTransactionId = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ProviderTransactionId,
                errors,
                ErrorCode.InvalidRequest);
            voidRequest.AuthorizationResponseCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ResponseCode);
            voidRequest.AuthorizationResult = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.AuthorizationResult,
                errors,
                ErrorCode.InvalidRequest);
            voidRequest.AuthorizationTransactionDateTime = PaymentUtilities.GetPropertyDateTimeValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.TransactionDateTime);

            if (errors.Count > 0)
            {
                throw new SampleException(errors);
            }

            return(voidRequest);
        }
Пример #6
0
        internal static RefundRequest ConvertFrom(Request request)
        {
            var refundRequest = new RefundRequest();
            var errors        = new List <PaymentError>();

            refundRequest.ReadBaseProperties(request, errors);

            // Check capture response
            var             hashtable = PaymentProperty.ConvertToHashtable(request.Properties);
            PaymentProperty captureResponsePropertyList = PaymentProperty.GetPropertyFromHashtable(hashtable, GenericNamespace.CaptureResponse, CaptureResponseProperties.Properties);

            // Read card data
            if (captureResponsePropertyList != null)
            {
                refundRequest.IsLinkedRefund = true;

                // Linked refund, get card data from CaptureResponse
                var captureHashtable = PaymentProperty.ConvertToHashtable(captureResponsePropertyList.PropertyList);
                refundRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.CardType,
                    errors,
                    ErrorCode.InvalidRequest);
                refundRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.CardToken);
                refundRequest.Last4Digit = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.Last4Digits);
                refundRequest.UniqueCardId = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.UniqueCardId);

                // Get other capture transaction data
                refundRequest.CaptureTransactionType = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.TransactionType,
                    errors,
                    ErrorCode.InvalidRequest);
                if (refundRequest.CaptureTransactionType != null &&
                    !TransactionType.Capture.ToString().Equals(refundRequest.CaptureTransactionType, StringComparison.OrdinalIgnoreCase))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidTransaction, "Refund does not support this type of transaction"));
                }

                refundRequest.CaptureApprovalCode = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.ApprovalCode);
                refundRequest.CaptureProviderMessage = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.ProviderMessage);
                refundRequest.CaptureProviderTransactionId = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.ProviderTransactionId,
                    errors,
                    ErrorCode.InvalidRequest);
                refundRequest.CaptureResponseCode = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.ResponseCode);
                refundRequest.CaptureResult = PaymentUtilities.GetPropertyStringValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.CaptureResult,
                    errors,
                    ErrorCode.InvalidRequest);
                refundRequest.CaptureTransactionDateTime = PaymentUtilities.GetPropertyDateTimeValue(
                    captureHashtable,
                    GenericNamespace.CaptureResponse,
                    CaptureResponseProperties.TransactionDateTime);
            }
            else
            {
                // Not a linked refund, get card data from PaymentCard
                refundRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardType,
                    errors,
                    ErrorCode.InvalidRequest);
                if (refundRequest.CardType != null &&
                    !PaymentUtilities.ValidateCardType(refundRequest.SupportedTenderTypes, refundRequest.CardType))
                {
                    errors.Add(new PaymentError(ErrorCode.CardTypeNotSupported, string.Format(CultureInfo.InvariantCulture, "Card type is not supported: {0}.", refundRequest.CardType)));
                }

                refundRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.IsSwipe,
                    false);
                if (refundRequest.IsSwipe)
                {
                    refundRequest.Track1 = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.Track1);
                    refundRequest.Track2 = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.Track2);

                    refundRequest.CardNumber = PaymentUtilities.ParseTrack1ForCardNumber(refundRequest.Track1);
                    if (refundRequest.CardNumber == null)
                    {
                        refundRequest.CardNumber = PaymentUtilities.ParseTrack2ForCardNumber(refundRequest.Track2);
                    }

                    if (refundRequest.CardNumber == null)
                    {
                        errors.Add(new PaymentError(ErrorCode.InvalidCardTrackData, "Invalid card track data."));
                    }

                    decimal expirationYear, expirationMonth;
                    HelperUtilities.ParseTrackDataForExpirationDate(refundRequest.Track1 ?? string.Empty, refundRequest.Track2 ?? string.Empty, out expirationYear, out expirationMonth);
                    refundRequest.ExpirationYear  = expirationYear;
                    refundRequest.ExpirationMonth = expirationMonth;
                }
                else
                {
                    refundRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.CardToken);

                    if (refundRequest.CardToken == null)
                    {
                        refundRequest.CardNumber = PaymentUtilities.GetPropertyStringValue(
                            hashtable,
                            GenericNamespace.PaymentCard,
                            PaymentCardProperties.CardNumber,
                            errors,
                            ErrorCode.InvalidCardNumber);
                    }
                    else
                    {
                        refundRequest.Last4Digit = PaymentUtilities.GetPropertyStringValue(
                            hashtable,
                            GenericNamespace.PaymentCard,
                            PaymentCardProperties.Last4Digits);
                    }

                    refundRequest.ExpirationYear = PaymentUtilities.GetPropertyDecimalValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.ExpirationYear,
                        errors,
                        ErrorCode.InvalidExpirationDate);
                    refundRequest.ExpirationMonth = PaymentUtilities.GetPropertyDecimalValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.ExpirationMonth,
                        errors,
                        ErrorCode.InvalidExpirationDate);
                }

                if (refundRequest.CardNumber != null &&
                    !HelperUtilities.ValidateBankCardNumber(refundRequest.CardNumber))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidCardNumber, "Invalid card number."));
                }

                if (refundRequest.ExpirationYear >= 0M &&
                    refundRequest.ExpirationMonth >= 0M &&
                    !PaymentUtilities.ValidateExpirationDate(refundRequest.ExpirationYear, refundRequest.ExpirationMonth))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidExpirationDate, "Invalid expiration date."));
                }

                if (Sitecore.Commerce.PaymentService.Connector.CardType.Debit.ToString().Equals(refundRequest.CardType, StringComparison.OrdinalIgnoreCase))
                {
                    refundRequest.EncryptedPin = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.EncryptedPin,
                        errors,
                        ErrorCode.CannotVerifyPin);
                    refundRequest.AdditionalSecurityData = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.AdditionalSecurityData);
                }

                refundRequest.CardVerificationValue = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardVerificationValue);
                refundRequest.Name = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Name);
                refundRequest.StreetAddress = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress);
                refundRequest.StreetAddress2 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress2);
                refundRequest.City = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.City);
                refundRequest.State = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.State);
                refundRequest.PostalCode = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.PostalCode);
                refundRequest.Country = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Country);
                refundRequest.Phone = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Phone);
                refundRequest.AccountType = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.AccountType);
                refundRequest.UniqueCardId = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.UniqueCardId);
            }

            // Read transaction data
            refundRequest.Amount = PaymentUtilities.GetPropertyDecimalValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.Amount,
                errors,
                ErrorCode.InvalidAmount);
            refundRequest.CurrencyCode = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.CurrencyCode,
                errors,
                ErrorCode.InvalidRequest);
            if (refundRequest.CurrencyCode != null &&
                !PaymentUtilities.ValidateCurrencyCode(refundRequest.SupportedCurrencies, refundRequest.CurrencyCode))
            {
                errors.Add(new PaymentError(ErrorCode.UnsupportedCurrency, string.Format(CultureInfo.InvariantCulture, "Currency code is not supported: {0}.", refundRequest.CurrencyCode)));
            }

            refundRequest.SupportCardTokenization = PaymentUtilities.GetPropertyBooleanValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.SupportCardTokenization,
                false);

            refundRequest.PurchaseLevel = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.PurchaseLevel);

            if (errors.Count > 0)
            {
                throw new SampleException(errors);
            }

            return(refundRequest);
        }
        protected void ReadBaseProperties(Request request, List <PaymentError> errors)
        {
            if (request == null)
            {
                throw new SampleException(ErrorCode.InvalidRequest, "Request is null.");
            }

            if (string.IsNullOrWhiteSpace(request.Locale))
            {
                throw new SampleException(ErrorCode.InvalidRequest, "Locale is null or whitespaces.");
            }
            else
            {
                this.Locale = request.Locale;
            }

            if (request.Properties == null || request.Properties.Length == 0)
            {
                throw new SampleException(ErrorCode.InvalidRequest, "Request properties is null or empty.");
            }

            var properties = PaymentProperty.ConvertToHashtable(request.Properties);

            this.ServiceAccountId = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                MerchantAccountProperties.ServiceAccountId,
                errors,
                ErrorCode.InvalidMerchantProperty);
            this.MerchantId = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                MerchantAccountProperties.MerchantId,
                errors,
                ErrorCode.InvalidMerchantProperty);
            this.ProviderId = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                SampleMerchantAccountProperty.ProviderId,
                errors,
                ErrorCode.InvalidMerchantProperty);
            this.Environment = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                SampleMerchantAccountProperty.Environment);
            this.SupportedCurrencies = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                MerchantAccountProperties.SupportedCurrencies,
                errors,
                ErrorCode.InvalidMerchantProperty);
            this.SupportedTenderTypes = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.MerchantAccount,
                MerchantAccountProperties.SupportedTenderTypes,
                errors,
                ErrorCode.InvalidMerchantProperty);
            this.IndustryType = PaymentUtilities.GetPropertyStringValue(
                properties,
                GenericNamespace.TransactionData,
                TransactionDataProperties.IndustryType);
            this.IsTestMode = PaymentUtilities.GetPropertyBooleanValue(
                properties,
                GenericNamespace.TransactionData,
                TransactionDataProperties.IsTestMode,
                false);
        }
Пример #8
0
        internal static CaptureRequest ConvertFrom(Request request)
        {
            var captureRequest = new CaptureRequest();
            var errors         = new List <PaymentError>();

            captureRequest.ReadBaseProperties(request, errors);

            // Check authorization response
            var                         hashtable = PaymentProperty.ConvertToHashtable(request.Properties);
            PaymentProperty             authorizationResponsePropertyList = PaymentProperty.GetPropertyFromHashtable(hashtable, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Properties);
            Dictionary <string, object> authorizationHashtable            = null;

            if (authorizationResponsePropertyList == null)
            {
                errors.Add(new PaymentError(ErrorCode.InvalidRequest, "Authorization response is missing."));
                throw new SampleException(errors);
            }
            else
            {
                authorizationHashtable = PaymentProperty.ConvertToHashtable(authorizationResponsePropertyList.PropertyList);
            }

            // Read card data
            captureRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CardType,
                errors,
                ErrorCode.InvalidRequest);

            captureRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.IsSwiped,
                false);
            if (captureRequest.IsSwipe)
            {
                captureRequest.Track1 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Track1);
                captureRequest.Track2 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Track2);
                captureRequest.CardNumber = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardNumber);

                if (string.IsNullOrEmpty(captureRequest.CardNumber))
                {
                    captureRequest.CardNumber = PaymentUtilities.ParseTrack1ForCardNumber(captureRequest.Track1);
                    if (captureRequest.CardNumber == null)
                    {
                        captureRequest.CardNumber = PaymentUtilities.ParseTrack2ForCardNumber(captureRequest.Track2);
                    }
                }

                if (string.IsNullOrEmpty(captureRequest.CardNumber))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidCardTrackData, "Invalid card track data."));
                }
            }
            else
            {
                captureRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                    authorizationHashtable,
                    GenericNamespace.AuthorizationResponse,
                    AuthorizationResponseProperties.CardToken);
                if (captureRequest.CardToken == null)
                {
                    captureRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.CardToken);
                    if (captureRequest.CardToken == null)
                    {
                        captureRequest.CardNumber = PaymentUtilities.GetPropertyStringValue(
                            hashtable,
                            GenericNamespace.PaymentCard,
                            PaymentCardProperties.CardNumber,
                            errors,
                            ErrorCode.InvalidCardNumber);
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(captureRequest.CardNumber) &&
                string.IsNullOrWhiteSpace(captureRequest.CardToken))
            {
                errors.Add(new PaymentError(ErrorCode.InvalidRequest, string.Format(CultureInfo.InvariantCulture, "Neither card number nor card token is provided.")));
            }

            captureRequest.Last4Digit = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.Last4Digits);
            captureRequest.AccountType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.AccountType);
            captureRequest.UniqueCardId = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.UniqueCardId);
            captureRequest.VoiceAuthorizationCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.VoiceAuthorizationCode);

            // Read transaction data
            captureRequest.Amount = PaymentUtilities.GetPropertyDecimalValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.Amount,
                errors,
                ErrorCode.InvalidAmount);
            captureRequest.CurrencyCode = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.CurrencyCode,
                errors,
                ErrorCode.InvalidRequest);
            captureRequest.PurchaseLevel = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.PurchaseLevel);

            // Read authorization data
            captureRequest.AuthorizationTransactionType = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.TransactionType,
                errors,
                ErrorCode.InvalidRequest);
            if (captureRequest.AuthorizationTransactionType != null &&
                !TransactionType.Authorize.ToString().Equals(captureRequest.AuthorizationTransactionType, StringComparison.OrdinalIgnoreCase))
            {
                errors.Add(new PaymentError(ErrorCode.InvalidTransaction, "Capture does not support this type of transaction"));
            }

            captureRequest.AuthorizationApprovalCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ApprovalCode);
            captureRequest.AuthorizationApprovedAmount = PaymentUtilities.GetPropertyDecimalValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ApprovedAmount,
                errors,
                ErrorCode.InvalidRequest);
            captureRequest.AuthorizationCashbackAmount = PaymentUtilities.GetPropertyDecimalValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.CashBackAmount);
            captureRequest.AuthorizationProviderMessage = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ProviderMessage);
            captureRequest.AuthorizationProviderTransactionId = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ProviderTransactionId,
                errors,
                ErrorCode.InvalidRequest);
            captureRequest.AuthorizationResponseCode = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.ResponseCode);
            captureRequest.AuthorizationResult = PaymentUtilities.GetPropertyStringValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.AuthorizationResult,
                errors,
                ErrorCode.InvalidRequest);
            captureRequest.AuthorizationTransactionDateTime = PaymentUtilities.GetPropertyDateTimeValue(
                authorizationHashtable,
                GenericNamespace.AuthorizationResponse,
                AuthorizationResponseProperties.TransactionDateTime);

            if (errors.Count > 0)
            {
                throw new SampleException(errors);
            }

            return(captureRequest);
        }
Пример #9
0
        internal static GenerateCardTokenRequest ConvertFrom(Request request, PaymentProperty[] requiredInteractionProperties)
        {
            var tokenizeRequest = new GenerateCardTokenRequest();
            var errors          = new List <PaymentError>();

            tokenizeRequest.ReadBaseProperties(request, errors);

            // Get card data from request.
            var cardProperties = request.Properties;

            // Read card data
            tokenizeRequest.OtherCardProperties = new List <PaymentProperty>();
            if (cardProperties != null)
            {
                var hashtable = PaymentProperty.ConvertToHashtable(cardProperties);
                tokenizeRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardType,
                    errors,
                    ErrorCode.InvalidRequest);
                if (tokenizeRequest.CardType != null &&
                    (!PaymentUtilities.ValidateCardType(tokenizeRequest.SupportedTenderTypes, tokenizeRequest.CardType) ||
                     tokenizeRequest.CardType.Equals(Sitecore.Commerce.PaymentService.Connector.CardType.Debit.ToString(), StringComparison.OrdinalIgnoreCase)))
                {
                    errors.Add(new PaymentError(ErrorCode.CardTypeNotSupported, string.Format(CultureInfo.InvariantCulture, "Card type is not supported: {0}.", tokenizeRequest.CardType)));
                }

                tokenizeRequest.CardNumber = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardNumber,
                    errors,
                    ErrorCode.InvalidCardNumber);
                if (tokenizeRequest.CardNumber != null &&
                    !HelperUtilities.ValidateBankCardNumber(tokenizeRequest.CardNumber))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidCardNumber, "Invalid card number."));
                }

                tokenizeRequest.ExpirationYear = PaymentUtilities.GetPropertyDecimalValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ExpirationYear,
                    errors,
                    ErrorCode.InvalidExpirationDate);
                tokenizeRequest.ExpirationMonth = PaymentUtilities.GetPropertyDecimalValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ExpirationMonth,
                    errors,
                    ErrorCode.InvalidExpirationDate);
                if (tokenizeRequest.ExpirationYear >= 0M &&
                    tokenizeRequest.ExpirationMonth >= 0M &&
                    !PaymentUtilities.ValidateExpirationDate(tokenizeRequest.ExpirationYear, tokenizeRequest.ExpirationMonth))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidExpirationDate, "Invalid expiration date."));
                }

                tokenizeRequest.Name = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Name);
                tokenizeRequest.StreetAddress = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress);
                tokenizeRequest.StreetAddress2 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress2);
                tokenizeRequest.City = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.City);
                tokenizeRequest.State = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.State);
                tokenizeRequest.PostalCode = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.PostalCode);
                tokenizeRequest.Country = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Country);
                tokenizeRequest.Phone = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Phone);
                tokenizeRequest.AccountType = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.AccountType);

                // Add other custom card properties from interaction properties
                foreach (var cardProperty in cardProperties)
                {
                    if (GenericNamespace.PaymentCard.Equals(cardProperty.Namespace) && IsCustomCardProperty(cardProperty.Name))
                    {
                        tokenizeRequest.OtherCardProperties.Add(cardProperty);
                    }
                }
            }

            // Add other custom card properties from request properties
            foreach (var requestProperty in request.Properties)
            {
                if (GenericNamespace.PaymentCard.Equals(requestProperty.Namespace) &&
                    !tokenizeRequest.OtherCardProperties.Any(p => p.Name.Equals(requestProperty.Name, StringComparison.OrdinalIgnoreCase)) &&
                    IsCustomCardProperty(requestProperty.Name))
                {
                    tokenizeRequest.OtherCardProperties.Add(requestProperty);
                }
            }

            if (errors.Count > 0)
            {
                throw new SampleException(errors);
            }

            return(tokenizeRequest);
        }
Пример #10
0
        internal static AuthorizeRequest ConvertFrom(Request request)
        {
            var authorizeRequest = new AuthorizeRequest();
            var errors           = new List <PaymentError>();

            authorizeRequest.ReadBaseProperties(request, errors);

            // Read card data
            Dictionary <string, object> hashtable = PaymentProperty.ConvertToHashtable(request.Properties);

            authorizeRequest.CardType = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.CardType,
                errors,
                ErrorCode.InvalidRequest);
            if (authorizeRequest.CardType != null &&
                !PaymentUtilities.ValidateCardType(authorizeRequest.SupportedTenderTypes, authorizeRequest.CardType))
            {
                errors.Add(new PaymentError(ErrorCode.CardTypeNotSupported, string.Format(CultureInfo.InvariantCulture, "Card type is not supported: {0}.", authorizeRequest.CardType)));
            }

            authorizeRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.IsSwipe,
                false);
            if (authorizeRequest.IsSwipe)
            {
                authorizeRequest.Track1 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Track1);
                authorizeRequest.Track2 = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Track2);

                authorizeRequest.CardNumber = PaymentUtilities.ParseTrack1ForCardNumber(authorizeRequest.Track1);
                if (authorizeRequest.CardNumber == null)
                {
                    authorizeRequest.CardNumber = PaymentUtilities.ParseTrack2ForCardNumber(authorizeRequest.Track2);
                }

                if (authorizeRequest.CardNumber == null)
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidCardTrackData, "Invalid card track data."));
                }

                decimal expirationYear, expirationMonth;
                HelperUtilities.ParseTrackDataForExpirationDate(authorizeRequest.Track1 ?? string.Empty, authorizeRequest.Track2 ?? string.Empty, out expirationYear, out expirationMonth);
                authorizeRequest.ExpirationYear  = expirationYear;
                authorizeRequest.ExpirationMonth = expirationMonth;
            }
            else
            {
                authorizeRequest.CardToken = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardToken);

                if (authorizeRequest.CardToken == null)
                {
                    authorizeRequest.CardNumber = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.CardNumber,
                        errors,
                        ErrorCode.InvalidCardNumber);
                }
                else
                {
                    authorizeRequest.Last4Digit = PaymentUtilities.GetPropertyStringValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.Last4Digits);
                }

                authorizeRequest.ExpirationYear = PaymentUtilities.GetPropertyDecimalValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ExpirationYear,
                    errors,
                    ErrorCode.InvalidExpirationDate);
                authorizeRequest.ExpirationMonth = PaymentUtilities.GetPropertyDecimalValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ExpirationMonth,
                    errors,
                    ErrorCode.InvalidExpirationDate);
            }

            if (authorizeRequest.CardNumber != null &&
                !HelperUtilities.ValidateBankCardNumber(authorizeRequest.CardNumber))
            {
                errors.Add(new PaymentError(ErrorCode.InvalidCardNumber, "Invalid card number."));
            }

            if (authorizeRequest.ExpirationYear >= 0M &&
                authorizeRequest.ExpirationMonth >= 0M &&
                !PaymentUtilities.ValidateExpirationDate(authorizeRequest.ExpirationYear, authorizeRequest.ExpirationMonth))
            {
                errors.Add(new PaymentError(ErrorCode.InvalidExpirationDate, "Invalid expiration date."));
            }

            if (Sitecore.Commerce.PaymentService.Connector.CardType.Debit.ToString().Equals(authorizeRequest.CardType, StringComparison.OrdinalIgnoreCase))
            {
                authorizeRequest.EncryptedPin = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.EncryptedPin,
                    errors,
                    ErrorCode.CannotVerifyPin);
                authorizeRequest.AdditionalSecurityData = PaymentUtilities.GetPropertyStringValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.AdditionalSecurityData);
            }

            authorizeRequest.CashBackAmount = PaymentUtilities.GetPropertyDecimalValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.CashBackAmount);
            if (authorizeRequest.CashBackAmount > 0M &&
                !Sitecore.Commerce.PaymentService.Connector.CardType.Debit.ToString().Equals(authorizeRequest.CardType, StringComparison.OrdinalIgnoreCase))
            {
                errors.Add(new PaymentError(ErrorCode.CashBackNotAvailable, "Cashback is not available."));
            }

            authorizeRequest.CardVerificationValue = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.CardVerificationValue);
            authorizeRequest.VoiceAuthorizationCode = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.VoiceAuthorizationCode);
            authorizeRequest.Name = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.Name);
            authorizeRequest.StreetAddress = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.StreetAddress);
            authorizeRequest.StreetAddress2 = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.StreetAddress2);
            authorizeRequest.City = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.City);
            authorizeRequest.State = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.State);
            authorizeRequest.PostalCode = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.PostalCode);
            authorizeRequest.Country = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.Country);
            authorizeRequest.Phone = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.Phone);
            authorizeRequest.AccountType = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.AccountType);
            authorizeRequest.UniqueCardId = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.PaymentCard,
                PaymentCardProperties.UniqueCardId);

            // Read transaction data
            authorizeRequest.Amount = PaymentUtilities.GetPropertyDecimalValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.Amount,
                errors,
                ErrorCode.InvalidAmount);
            authorizeRequest.CurrencyCode = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.CurrencyCode,
                errors,
                ErrorCode.InvalidRequest);
            if (authorizeRequest.CurrencyCode != null &&
                !PaymentUtilities.ValidateCurrencyCode(authorizeRequest.SupportedCurrencies, authorizeRequest.CurrencyCode))
            {
                errors.Add(new PaymentError(ErrorCode.UnsupportedCurrency, string.Format(CultureInfo.InvariantCulture, "Currency code is not supported: {0}.", authorizeRequest.CurrencyCode)));
            }

            authorizeRequest.SupportCardTokenization = PaymentUtilities.GetPropertyBooleanValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.SupportCardTokenization,
                false);

            authorizeRequest.AuthorizationProviderTransactionId = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.AuthorizationProviderTransactionId);

            authorizeRequest.PurchaseLevel = PaymentUtilities.GetPropertyStringValue(
                hashtable,
                GenericNamespace.TransactionData,
                TransactionDataProperties.PurchaseLevel);

            if (errors.Count > 0)
            {
                throw new SampleException(errors);
            }

            return(authorizeRequest);
        }