private static IEnumerable <TaxDetail> GetTaxDetails(Hashtable properties, string propertyNamespace, string propertyName)
            {
                IEnumerable <TaxDetail> taxDetails = null;

                PaymentProperty[] taxDetailsPropertyArray;
                if (PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out taxDetailsPropertyArray))
                {
                    if (taxDetailsPropertyArray.Length > 0)
                    {
                        taxDetails = new List <TaxDetail>();
                        foreach (var taxDetailsProperty in taxDetailsPropertyArray)
                        {
                            PaymentProperty[] taxDetailPropertyArray = taxDetailsProperty.PropertyList;
                            if (taxDetailPropertyArray != null)
                            {
                                Hashtable taxDetailProperties = PaymentProperty.ConvertToHashtable(taxDetailPropertyArray);
                                var       taxDetail           = new TaxDetail();
                                taxDetail.TaxTypeIdentifier = PaymentUtilities.GetPropertyStringValue(taxDetailProperties, GenericNamespace.TaxDetail, TaxDetailProperties.TaxTypeIdentifier);
                                taxDetail.TaxRate           = PaymentUtilities.GetPropertyDecimalValue(taxDetailProperties, GenericNamespace.TaxDetail, TaxDetailProperties.TaxRate);
                                taxDetail.TaxDescription    = PaymentUtilities.GetPropertyStringValue(taxDetailProperties, GenericNamespace.TaxDetail, TaxDetailProperties.TaxDescription);
                                taxDetail.TaxAmount         = PaymentUtilities.GetPropertyDecimalValue(taxDetailProperties, GenericNamespace.TaxDetail, TaxDetailProperties.TaxAmount);
                                (taxDetails as List <TaxDetail>).Add(taxDetail);
                            }
                        }
                    }
                }

                return(taxDetails);
            }
            private static IEnumerable <MiscellaneousCharge> GetMiscellaneousCharges(Hashtable properties, string propertyNamespace, string propertyName)
            {
                IEnumerable <MiscellaneousCharge> miscellaneousCharges = null;

                PaymentProperty[] miscellaneousChargesPropertyArray;
                if (PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out miscellaneousChargesPropertyArray))
                {
                    if (miscellaneousChargesPropertyArray.Length > 0)
                    {
                        miscellaneousCharges = new List <MiscellaneousCharge>();
                        foreach (var miscellaneousChargesProperty in miscellaneousChargesPropertyArray)
                        {
                            PaymentProperty[] miscellaneousChargePropertyArray = miscellaneousChargesProperty.PropertyList;
                            if (miscellaneousChargePropertyArray != null)
                            {
                                Hashtable miscellaneousChargeProperties = PaymentProperty.ConvertToHashtable(miscellaneousChargePropertyArray);
                                var       miscellaneousCharge           = new MiscellaneousCharge();
                                miscellaneousCharge.ChargeType   = PaymentUtilities.GetPropertyStringValue(miscellaneousChargeProperties, GenericNamespace.MiscellaneousCharge, MiscellaneousChargeProperties.ChargeType);
                                miscellaneousCharge.ChargeAmount = PaymentUtilities.GetPropertyDecimalValue(miscellaneousChargeProperties, GenericNamespace.MiscellaneousCharge, MiscellaneousChargeProperties.ChargeAmount);
                                (miscellaneousCharges as List <MiscellaneousCharge>).Add(miscellaneousCharge);
                            }
                        }
                    }
                }

                return(miscellaneousCharges);
            }
        /// <summary>
        /// Processes the service pipeline arguments.
        /// </summary>
        /// <param name="args">The service pipeline arguments.</param>
        public override void Process(ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentCondition(args.Request is GetPaymentServiceActionResultRequest, "args.Request", "Request must be of type GetPaymentServiceActionResultRequest.");
            Assert.ArgumentCondition(args.Result is GetPaymentServiceActionResultResult, "args.Result", "Result must be of type GetPaymentServiceActionResultResult.");
            var request = (GetPaymentServiceActionResultRequest)args.Request;
            var result  = (GetPaymentServiceActionResultResult)args.Result;

            var serviceRequestProperties = new List <PaymentProperty>();

            serviceRequestProperties.AddRange(this.GetMerchantProperties() ?? Enumerable.Empty <PaymentProperty>());

            serviceRequestProperties.Add(new PaymentProperty(
                                             GenericNamespace.TransactionData,
                                             TransactionDataProperties.PaymentAcceptResultAccessCode,
                                             request.PaymentAcceptResultAccessCode));

            var serviceResponse = this.ExecutePaymentServiceRequest(
                serviceRequestProperties,
                RetrievePaymentAcceptResultRelativeUri,
                request.Locale,
                result.SystemMessages);

            if (serviceResponse != null)
            {
                var serviceResponseProperties = PaymentProperty.ConvertToHashtable(serviceResponse.Properties);

                string token;
                PaymentProperty.GetPropertyValue(
                    serviceResponseProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardToken,
                    out token);

                var innerAuthorizeResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                    serviceResponseProperties,
                    GenericNamespace.AuthorizationResponse,
                    AuthorizationResponseProperties.Properties);
                var innerAuthorizeResponseProperties = PaymentProperty.ConvertToHashtable(innerAuthorizeResponseProperty.PropertyList);

                string authorizationResult = null;
                PaymentProperty.GetPropertyValue(
                    innerAuthorizeResponseProperties,
                    GenericNamespace.AuthorizationResponse,
                    AuthorizationResponseProperties.AuthorizationResult,
                    out authorizationResult);

                result.AuthorizationResult = authorizationResult;
                result.CardToken           = token;
                result.Success             = true;
            }
            else
            {
                result.Success = false;
            }
        }
            /// <summary>
            /// Gets the string value of a payment property.
            /// </summary>
            /// <param name="propertyHashtable">The property hashtable.</param>
            /// <param name="propertyNamespace">The namespace.</param>
            /// <param name="propertyName">The name.</param>
            /// <param name="required">The flag indicating whether the property is required.</param>
            /// <param name="errors">The error list in case the property is required but not found.</param>
            /// <returns>The string value.</returns>
            private static string GetPropertyStringValue(Hashtable propertyHashtable, string propertyNamespace, string propertyName, bool required, List <PaymentError> errors)
            {
                string propertyValue;
                bool   found = PaymentProperty.GetPropertyValue(
                    propertyHashtable,
                    propertyNamespace,
                    propertyName,
                    out propertyValue);

                if (!found && required)
                {
                    var error = new PaymentError(ErrorCode.InvalidRequest, string.Format("Property '{0}' is null or not set", propertyName));
                    errors.Add(error);
                }

                return(propertyValue);
            }
            internal static PaymentProperty AddPropertyIfPresent(IList <PaymentProperty> properties, string propertyNamespace, string propertyName, bool?value)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                if (value.HasValue)
                {
                    PaymentProperty property = new PaymentProperty(propertyNamespace, propertyName, value.Value.ToString());
                    properties.Add(property);
                    return(property);
                }
                else
                {
                    return(null);
                }
            }
示例#6
0
        internal static PaymentProperty AddPropertyIfPresent(IList <PaymentProperty> properties, string propertyNamespace, string propertyName, DateTime value)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            if (value != DateTimeValueNotPresent)
            {
                PaymentProperty property = new PaymentProperty(propertyNamespace, propertyName, value);
                properties.Add(property);
                return(property);
            }
            else
            {
                return(null);
            }
        }
示例#7
0
        internal static decimal GetPropertyDecimalValue(Dictionary <string, object> properties, string propertyNamespace, string propertyName, List <PaymentError> errors, ErrorCode errorCode)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            decimal value;

            if (!PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out value))
            {
                value = DecimalValueNotPresent;
                if (errors != null)
                {
                    errors.Add(new PaymentError(errorCode, MissingPropertyMessage(propertyNamespace, propertyName)));
                }
            }

            return(value);
        }
示例#8
0
        internal static bool GetPropertyBooleanValue(Dictionary <string, object> properties, string propertyNamespace, string propertyName, bool defaultValue, List <PaymentError> errors, ErrorCode errorCode)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            bool value;

            if (!PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out value))
            {
                value = defaultValue;
                if (errors != null)
                {
                    errors.Add(new PaymentError(errorCode, MissingPropertyMessage(propertyNamespace, propertyName)));
                }
            }

            return(value);
        }
            internal static string GetPropertyStringValue(Hashtable properties, string propertyNamespace, string propertyName, List <PaymentError> errors, ErrorCode errorCode)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                string value;

                if (!PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out value))
                {
                    value = null;
                    if (errors != null)
                    {
                        errors.Add(new PaymentError(errorCode, MissingPropertyMessage(propertyNamespace, propertyName)));
                    }
                }

                return(value);
            }
        public string BuildPaymentProperties(PaymentTransaction payment)
        {
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.Name", payment.CardHolderName));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.CardType", payment.CardType));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.Country", "US"));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.StreetAddress", payment.BillingStreet));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.PostalCode", payment.BillingZipcode));

            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.UniqueCardId", "c7352ec8-d6e8-4854-8b6f-349cfbcf80fd"));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.CardToken", payment.TransactionId));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.Last4Digits", payment.CardNumber));

            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.City", payment.BillingCity));
            defaultPropertyPairList.Add(new KeyValuePair <string, string>("PaymentCard.State", payment.BillingState));


            PaymentProperty[] properties = new PaymentProperty[36];

            var x = 0;

            foreach (var propertyPair in defaultPropertyPairList)
            {
                string[] propertyArray = propertyPair.Key.Split('.');
                if (x < (properties.Length - 1))
                {
                    properties[x] = new PaymentProperty(propertyArray[0], propertyArray[1], propertyPair.Value, Microsoft.Dynamics.Retail.PaymentSDK.SecurityLevel.None);
                    x++;
                }
                else
                {
                    x--;
                    break;
                }
            }
            properties[x++] = new PaymentProperty("PaymentCard", "ExpirationYear", payment.ExpireYear, Microsoft.Dynamics.Retail.PaymentSDK.SecurityLevel.None);
            properties[x++] = new PaymentProperty("PaymentCard", "ExpirationMonth", payment.ExpireMonth, Microsoft.Dynamics.Retail.PaymentSDK.SecurityLevel.None);

            var xml = PaymentProperty.ConvertPropertyArrayToXML(properties);

            return(xml != null ? xml : string.Empty);
        }
示例#11
0
        public Response GetMerchantAccountPropertyMetadata(Request request)
        {
            string methodName = "GetMerchantAccountPropertyMetadata";

            // Check null request
            List <PaymentError> errors = new List <PaymentError>();

            if (request == null)
            {
                errors.Add(new PaymentError(ErrorCode.InvalidRequest, "Request is null."));
                return(PaymentUtilities.CreateAndLogResponseForReturn(methodName, this.Name, Platform, locale: null, properties: null, errors: errors));
            }

            // Prepare response
            List <PaymentProperty> properties = new List <PaymentProperty>();
            PaymentProperty        property;

            property = new PaymentProperty(
                GenericNamespace.MerchantAccount,
                MerchantAccountProperties.AssemblyName,
                this.GetAssemblyName());
            property.SetMetadata("Assembly Name:", "The assembly name of the test provider", false, true, 0);
            properties.Add(property);

            Response response = new Response();

            response.Locale     = request.Locale;
            response.Properties = properties.ToArray();
            if (errors.Count > 0)
            {
                response.Errors = errors.ToArray();
            }

            PaymentUtilities.LogResponseBeforeReturn(methodName, this.Name, Platform, response);
            return(response);
        }
示例#12
0
            internal static decimal?GetPropertyDecimalValue(Hashtable properties, string propertyNamespace, string propertyName, List <PaymentError> errors, ErrorCode errorCode)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                decimal value;
                decimal?result = null;

                if (!PaymentProperty.GetPropertyValue(properties, propertyNamespace, propertyName, out value))
                {
                    if (errors != null)
                    {
                        errors.Add(new PaymentError(errorCode, MissingPropertyMessage(propertyNamespace, propertyName)));
                    }
                }
                else
                {
                    result = value;
                }

                return(result);
            }
示例#13
0
        private string GetBasePaymentServiceUrl(GetPaymentServiceUrlRequest request, GetPaymentServiceUrlResult result, List <PaymentProperty> serviceRequestProperties)
        {
            var getPaymentAcceptPointResponse = this.ExecutePaymentServiceRequest(
                serviceRequestProperties,
                GetPaymentAcceptPointRelativeUri,
                request.Locale,
                result.SystemMessages);

            if (getPaymentAcceptPointResponse != null)
            {
                var getPaymentAcceptPointResponseProperties = PaymentProperty.ConvertToHashtable(getPaymentAcceptPointResponse.Properties);

                var paymentAcceptUrl = string.Empty;
                PaymentProperty.GetPropertyValue(
                    getPaymentAcceptPointResponseProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.PaymentAcceptUrl,
                    out paymentAcceptUrl);

                return(paymentAcceptUrl);
            }

            return(string.Empty);
        }
        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);
        }
示例#15
0
            internal static GenerateCardTokenRequest ConvertFrom(Request request, PaymentProperty[] requiredInteractionProperties)
            {
                var tokenizeRequest = new GenerateCardTokenRequest();
                var errors          = new List <PaymentError>();

                tokenizeRequest.ReadBaseProperties(request, errors);

                PaymentProperty[] cardProperties = null;
                if (requiredInteractionProperties != null)
                {
                    // Get card data from interaction form
                    IExtensions handler = SDKExtensions.Extension;
                    if (handler != null)
                    {
                        // We have found the implementation for the form
                        Dictionary <string, PaymentProperty> interactionPropertyDictionary = null;
                        if (handler.GetCreditCardDetails(requiredInteractionProperties, out interactionPropertyDictionary))
                        {
                            cardProperties = interactionPropertyDictionary.Values.ToArray();
                        }
                    }
                    else
                    {
                        errors.Add(new PaymentError(ErrorCode.UserAborted, "User aborted data entry form."));
                    }
                }
                else
                {
                    // Get card data from request.
                    cardProperties = request.Properties;
                }

                // Read card data
                tokenizeRequest.OtherCardProperties = new List <PaymentProperty>();
                if (cardProperties != null)
                {
                    Hashtable 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(Microsoft.Dynamics.Retail.PaymentSDK.Portable.CardType.Debit.ToString(), StringComparison.OrdinalIgnoreCase)))
                    {
                        errors.Add(new PaymentError(ErrorCode.CardTypeNotSupported, string.Format("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.HasValue &&
                        tokenizeRequest.ExpirationMonth.HasValue &&
                        tokenizeRequest.ExpirationYear >= 0M &&
                        tokenizeRequest.ExpirationMonth >= 0M &&
                        !PaymentUtilities.ValidateExpirationDate(tokenizeRequest.ExpirationYear.Value, tokenizeRequest.ExpirationMonth.Value))
                    {
                        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);
            }
示例#16
0
            internal static CaptureRequest ConvertFrom(Request request)
            {
                var captureRequest = new CaptureRequest();
                var errors         = new List <PaymentError>();

                captureRequest.ReadBaseProperties(request, errors);

                // Check authorization response
                Hashtable       hashtable = PaymentProperty.ConvertToHashtable(request.Properties);
                PaymentProperty authorizationResponsePropertyList = PaymentProperty.GetPropertyFromHashtable(hashtable, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Properties);
                Hashtable       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);
                if (captureRequest.IsSwipe ?? false)
                {
                    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("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);

                captureRequest.Level2Data = PaymentUtilities.GetLevel2Data(hashtable);
                captureRequest.Level3Data = PaymentUtilities.GetLevel3Data(hashtable);

                // 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);
            }
示例#17
0
            internal static void LogOperationResult(string methodName, string connectorName, string platform, Request request, Response response)
            {
                /*
                 * IMPORTANT!!!
                 * THIS IS SAMPLE CODE ONLY!
                 * THE CODE MIGHT LOG TOO MUCH INFORMATION WHICH IS INAPPROPRIATE FOR PRODUCT ENVIRONMENT.
                 */
                if (request != null && request.Properties != null && response != null && response.Properties != null)
                {
                    var requestProperties  = PaymentProperty.ConvertToHashtable(request.Properties);
                    var responseProperties = PaymentProperty.ConvertToHashtable(response.Properties);

                    StringBuilder result            = new StringBuilder();
                    string        requestCardToken  = PaymentUtilities.GetPropertyStringValue(requestProperties, GenericNamespace.PaymentCard, PaymentCardProperties.CardToken);
                    string        responseCardToken = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.PaymentCard, PaymentCardProperties.CardToken);
                    if (string.IsNullOrWhiteSpace(requestCardToken) && !string.IsNullOrWhiteSpace(responseCardToken))
                    {
                        string last4Digit = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.PaymentCard, PaymentCardProperties.Last4Digits);
                        result.Append(string.Format("Card {0}, Tokenization Success. ", last4Digit));
                    }

                    string authResult = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AuthorizationResult);
                    if (!string.IsNullOrWhiteSpace(authResult))
                    {
                        string  last4Digit     = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Last4Digits);
                        decimal?approvedAmount = PaymentUtilities.GetPropertyDecimalValue(responseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ApprovedAmount);
                        string  currency       = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CurrencyCode);
                        result.Append(string.Format("Card {0}, Authorization {1}, Approved amount {2} {3}. ", last4Digit, authResult, approvedAmount, currency));
                    }

                    string captureResult = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.CaptureResponse, CaptureResponseProperties.CaptureResult);
                    if (!string.IsNullOrWhiteSpace(captureResult))
                    {
                        string  last4Digit      = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.CaptureResponse, CaptureResponseProperties.Last4Digits);
                        decimal?requestedAmount = PaymentUtilities.GetPropertyDecimalValue(requestProperties, GenericNamespace.TransactionData, TransactionDataProperties.Amount);
                        string  currency        = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.CaptureResponse, CaptureResponseProperties.CurrencyCode);
                        result.Append(string.Format("Card {0}, Capture {1}, Requested amount {2} {3}. ", last4Digit, captureResult, requestedAmount, currency));
                    }

                    string voidResult = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.VoidResult);
                    if (!string.IsNullOrWhiteSpace(voidResult))
                    {
                        string  last4Digit      = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.Last4Digits);
                        decimal?requestedAmount = PaymentUtilities.GetPropertyDecimalValue(requestProperties, GenericNamespace.TransactionData, TransactionDataProperties.Amount);
                        string  currency        = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.VoidResponse, VoidResponseProperties.CurrencyCode);
                        result.Append(string.Format("Card {0}, Void {1}, Requested amount {2} {3}. ", last4Digit, voidResult, requestedAmount, currency));
                    }

                    string refundResult = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.RefundResponse, RefundResponseProperties.RefundResult);
                    if (!string.IsNullOrWhiteSpace(refundResult))
                    {
                        string  last4Digit     = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.RefundResponse, RefundResponseProperties.Last4Digits);
                        decimal?approvedAmount = PaymentUtilities.GetPropertyDecimalValue(responseProperties, GenericNamespace.RefundResponse, RefundResponseProperties.ApprovedAmount);
                        string  currency       = PaymentUtilities.GetPropertyStringValue(responseProperties, GenericNamespace.RefundResponse, RefundResponseProperties.CurrencyCode);
                        result.Append(string.Format("Card {0}, Refund {1}, Approved amount {2} {3}. ", last4Digit, refundResult, approvedAmount, currency));
                    }

                    string step = "result: ";
                    if (result.Length > 0)
                    {
                        step += result.ToString();
                    }
                    else
                    {
                        step += "No result. ";
                    }

                    RetailLogger.Log.PaymentConnectorLogOperation(methodName, step, connectorName, platform);
                }
            }
示例#18
0
            private void RetrievePaymentAcceptResult()
            {
                // Get payment processor
                PaymentProcessorManager.Create(new string[] { ConnectorAssembly });
                IPaymentProcessor processor = PaymentProcessorManager.GetPaymentProcessor(ConnectorName);

                // Prepare payment request
                var request = new Request();

                request.Locale = this.requestLocale;

                var properties = new List <PaymentProperty>();

                this.AddMerchantProperties(properties);

                PaymentProperty property;

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.PaymentAcceptResultAccessCode,
                    this.ResultAccessCodeHiddenField.Value);
                properties.Add(property);

                request.Properties = properties.ToArray();

                // Call
                Response response = processor.RetrievePaymentAcceptResult(request);

                string cardTokenResult     = "N/A";
                string authorizationResult = "N/A";
                string captureResult       = "N/A";
                string voidResult          = "N/A";
                string errors = "None";

                if (response != null && response.Properties != null)
                {
                    Hashtable responseProperties = PaymentProperty.ConvertToHashtable(response.Properties);

                    // Read card token
                    string token;
                    PaymentProperty.GetPropertyValue(
                        responseProperties,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.CardToken,
                        out token);

                    if (!string.IsNullOrEmpty(token))
                    {
                        // Store token or use token.
                        // In this sample, we send the token to the next page to display. Do not do this in production.
                        cardTokenResult = token;
                    }

                    // Read authorize result
                    if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerAuthorizeResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.AuthorizationResponse,
                            AuthorizationResponseProperties.Properties);

                        if (innerAuthorizeResponseProperty != null)
                        {
                            var innerAuthorizeResponseProperties = PaymentProperty.ConvertToHashtable(innerAuthorizeResponseProperty.PropertyList);

                            string authorizationResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerAuthorizeResponseProperties,
                                GenericNamespace.AuthorizationResponse,
                                AuthorizationResponseProperties.AuthorizationResult,
                                out authorizationResultOut);

                            if (!string.IsNullOrEmpty(authorizationResultOut))
                            {
                                authorizationResult = authorizationResultOut;
                            }
                        }
                    }

                    // Read capture result
                    if (this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerCaptureResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.CaptureResponse,
                            CaptureResponseProperties.Properties);

                        if (innerCaptureResponseProperty != null)
                        {
                            var innerCaptureResponseProperties = PaymentProperty.ConvertToHashtable(innerCaptureResponseProperty.PropertyList);

                            string captureResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerCaptureResponseProperties,
                                GenericNamespace.CaptureResponse,
                                CaptureResponseProperties.CaptureResult,
                                out captureResultOut);

                            if (!string.IsNullOrEmpty(captureResultOut))
                            {
                                captureResult = captureResultOut;
                            }
                        }
                    }

                    // Read void result
                    if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerVoidResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.VoidResponse,
                            VoidResponseProperties.Properties);

                        if (innerVoidResponseProperty != null)
                        {
                            var innerVoidResponseProperties = PaymentProperty.ConvertToHashtable(innerVoidResponseProperty.PropertyList);

                            string voidResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerVoidResponseProperties,
                                GenericNamespace.VoidResponse,
                                VoidResponseProperties.VoidResult,
                                out voidResultOut);

                            if (!string.IsNullOrEmpty(voidResultOut))
                            {
                                voidResult = voidResultOut;
                            }
                        }
                    }
                }

                if (response.Errors != null && response.Errors.Length > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var error in response.Errors)
                    {
                        sb.AppendLine(string.Format("{0}: {1}", error.Code, error.Message));
                    }

                    errors = sb.ToString();
                }

                Server.Transfer(
                    string.Format(
                        "ResultPage.aspx?cardTokenResult={0}&authorizationResult={1}&captureResult={2}&voidResult={3}&errors={4}",
                        HttpUtility.UrlEncode(cardTokenResult),
                        HttpUtility.UrlEncode(authorizationResult),
                        HttpUtility.UrlEncode(captureResult),
                        HttpUtility.UrlEncode(voidResult),
                        HttpUtility.UrlEncode(errors)));
            }
            /// <summary>
            /// Converts a payment request to a card payment entry.
            /// </summary>
            /// <param name="request">The payment request.</param>
            /// <param name="errorList">The errors during conversion.</param>
            /// <returns>The card payment entry.</returns>
            private static CardPaymentEntry ConvertRequestToCardPaymentEntry(Request request, List <PaymentError> errorList)
            {
                string locale = request.Locale;

                if (string.IsNullOrWhiteSpace(locale))
                {
                    errorList.Add(new PaymentError(ErrorCode.LocaleNotSupported, "Locale is not specified."));
                }

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

                string serviceAccountId = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.ServiceAccountId,
                    required: true,
                    errors: errorList);

                string industryType = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.IndustryType,
                    required: false,
                    errors: errorList);
                IndustryType industryTypeEnum;

                if (string.IsNullOrEmpty(industryType) || !Enum.TryParse(industryType, true, out industryTypeEnum))
                {
                    industryTypeEnum = IndustryType.Ecommerce;
                }

                string transactionType = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.TransactionType,
                    required: true,
                    errors: errorList);
                TransactionType transactionTypeEnum = TransactionType.None;

                if (!Enum.TryParse(transactionType, true, out transactionTypeEnum) ||
                    (transactionTypeEnum != TransactionType.None && transactionTypeEnum != TransactionType.Authorize && transactionTypeEnum != TransactionType.Capture))
                {
                    errorList.Add(new PaymentError(ErrorCode.InvalidRequest, "The transaction type is not suppoted."));
                }

                string supportCardSwipeString = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardSwipe,
                    required: false,
                    errors: errorList);
                bool supportCardSwipe = false;

                if (!string.IsNullOrWhiteSpace(supportCardSwipeString))
                {
                    bool.TryParse(supportCardSwipeString, out supportCardSwipe);
                }

                string supportCardTokenizationString = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardTokenization,
                    required: false,
                    errors: errorList);
                bool supportCardTokenization = false;

                if (!string.IsNullOrWhiteSpace(supportCardTokenizationString))
                {
                    bool.TryParse(supportCardTokenizationString, out supportCardTokenization);
                }

                // When transaction type is None, support card tokenization must be enabled.
                if (transactionTypeEnum == TransactionType.None && !supportCardTokenization)
                {
                    errorList.Add(new PaymentError(ErrorCode.InvalidRequest, "When transaction type is None, support card tokenization must be enabled."));
                }

                string allowVoiceAuthorizationString = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.AllowVoiceAuthorization,
                    required: false,
                    errors: errorList);
                bool allowVoiceAuthorization = false;

                if (!string.IsNullOrWhiteSpace(allowVoiceAuthorizationString))
                {
                    bool.TryParse(allowVoiceAuthorizationString, out allowVoiceAuthorization);
                }

                string hostPageOrigin = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.HostPageOrigin,
                    required: true,
                    errors: errorList);

                if (string.IsNullOrWhiteSpace(hostPageOrigin))
                {
                    errorList.Add(new PaymentError(ErrorCode.InvalidRequest, "The host page origin is not specified."));
                }

                string cardTypes = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardType,
                    required: false,
                    errors: errorList);

                string defaultCardHolderName = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Name,
                    required: false,
                    errors: errorList);

                string defaultStreet1 = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress,
                    required: false,
                    errors: errorList);

                string defaultStreet2 = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress2,
                    required: false,
                    errors: errorList);

                string defaultCity = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.City,
                    required: false,
                    errors: errorList);

                string defaultStateOrProvince = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.State,
                    required: false,
                    errors: errorList);

                string defaultPostalCode = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.PostalCode,
                    required: false,
                    errors: errorList);

                string defaultCountryCode = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Country,
                    required: false,
                    errors: errorList);

                string showSameAsShippingAddressString = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ShowSameAsShippingAddress,
                    required: false,
                    errors: errorList);

                bool showSameAsShippingAddress = false;

                if (!string.IsNullOrWhiteSpace(showSameAsShippingAddressString))
                {
                    bool.TryParse(showSameAsShippingAddressString, out showSameAsShippingAddress);
                }

                string entryData = JsonConvert.SerializeObject(request);

                // Create the request in database with an unique entry ID
                var cardPaymentEntry = new CardPaymentEntry()
                {
                    AllowVoiceAuthorization = allowVoiceAuthorization,
                    CardTypes              = CardTypes.GetSupportedCardTypes(cardTypes),
                    DefaultCardHolderName  = defaultCardHolderName,
                    DefaultCity            = defaultCity,
                    DefaultCountryCode     = defaultCountryCode,
                    DefaultPostalCode      = defaultPostalCode,
                    DefaultStateOrProvince = defaultStateOrProvince,
                    DefaultStreet1         = defaultStreet1,
                    DefaultStreet2         = defaultStreet2,
                    EntryData              = entryData,
                    EntryId                   = CommonUtility.NewGuid().ToString(),
                    EntryLocale               = locale,
                    EntryUtcTime              = DateTime.UtcNow,
                    HostPageOrigin            = hostPageOrigin,
                    IndustryType              = industryTypeEnum.ToString(),
                    ServiceAccountId          = serviceAccountId,
                    ShowSameAsShippingAddress = showSameAsShippingAddress,
                    SupportCardSwipe          = supportCardSwipe,
                    SupportCardTokenization   = supportCardTokenization,
                    TransactionType           = transactionType,
                    Used = false,
                };

                return(cardPaymentEntry);
            }
        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);
        }
        public PaymentInfo MapPaymentResponse(string responseStr, string paymentConnectorName)
        {
            PaymentInfo paymentInfo = new PaymentInfo
            {
                IsApproved = false
            };

            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(responseStr);

                XmlNodeList cardServiceResponseNode = xmlDoc.GetElementsByTagName("CardServiceResponse");
                string      requestType             = cardServiceResponseNode[0].Attributes["RequestType"].Value;
                string      workstationID           = cardServiceResponseNode[0].Attributes["WorkstationID"].Value;
                string      requestID     = cardServiceResponseNode[0].Attributes["RequestID"].Value;
                string      overallResult = cardServiceResponseNode[0].Attributes["OverallResult"].Value;

                Logger.WriteLog($"OverallResult value is :{overallResult}");

                //If OverallResult is not Success , then read the error  node and return else proceed further
                if (overallResult.ToLower().Equals("success"))
                {
                    var    terminalNode  = xmlDoc.GetElementsByTagName("Terminal");
                    string terminalID    = terminalNode[0].Attributes["TerminalID"].Value;
                    string terminalBatch = terminalNode[0].Attributes["TerminalBatch"].Value;

                    var tenderNode = xmlDoc.GetElementsByTagName("Tender");

                    var    totalAmountNode = xmlDoc.GetElementsByTagName("TotalAmount");
                    string totalAmount     = totalAmountNode[0].InnerText;

                    var    authorisationNode = xmlDoc.GetElementsByTagName("Authorisation");
                    string acquirerID        = authorisationNode[0].Attributes["AcquirerID"].Value;
                    string startDate         = authorisationNode[0].Attributes["StartDate"].Value;
                    string expiryDate        = authorisationNode[0].Attributes["ExpiryDate"].Value;
                    string timeStamp         = authorisationNode[0].Attributes["TimeStamp"].Value;

                    #region Different Action codes as per EPS doc
                    // '004' is undefined by IFSF so should be treated as a decline.
                    //'000' Approved
                    //'001' Honour, with Identification Approved
                    //'002' Approved for partial amount Approved
                    //'003' Approved(VIP) Approved
                    //'005' Approved, account type specified by card issuer
                    //'006' Approved for partial amount, account Approved
                    //'007' Approved, update ICC Approved
                    #endregion

                    string actionCode        = authorisationNode[0].Attributes["ActionCode"].Value;
                    string approvalCode      = authorisationNode[0].Attributes["ApprovalCode"].Value;
                    string acquirerBatch     = authorisationNode[0].Attributes["AcquirerBatch"].Value;
                    string panprint          = authorisationNode[0].Attributes["PANprint"].Value;
                    string merchant          = authorisationNode[0].Attributes["Merchant"].Value;
                    string authorisationType = authorisationNode[0].Attributes["AuthorisationType"].Value;
                    string captureReference  = authorisationNode[0].Attributes["CaptureReference"].Value;

                    if (overallResult.Equals(OverallResult.Success.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        paymentInfo.IsApproved = true;
                    }

                    //Map all values to paymentinfo object
                    paymentInfo.ApprovedAmount   = Convert.ToDecimal(totalAmount);
                    paymentInfo.CardNumberMasked = "5413********4012";                                                                       //TODO : FIX for issue where EPS is returning first 4 digits of card masked in panprint causing POS to error;
                    paymentInfo.CardType         = Microsoft.Dynamics.Commerce.HardwareStation.CardPayment.CardType.InternationalCreditCard; //TODO:do we need to send this in response ?

                    //Doing this just to test ,should not be manually set like this
                    paymentInfo.CashbackAmount = 0;
                    //paymentInfo.Errors

                    ////Building PaymentSdkData v0.1
                    List <PaymentProperty> paymentSdkProperties = new List <PaymentProperty>();
                    //TODO: The connector name should be based on the payment properties sent by POS in initial call and not hardcoded initial
                    paymentSdkProperties.Add(new PaymentProperty(GenericNamespace.Connector, ConnectorProperties.ConnectorName, paymentConnectorName));

                    List <PaymentProperty> paymentSdkAuthorizationProperties = new List <PaymentProperty>();
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ApprovedAmount, paymentInfo.ApprovedAmount));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AvailableBalance, 100.00m));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ApprovalCode, approvalCode));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ProviderTransactionId, captureReference));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.AuthorizationResult, AuthorizationResult.Success.ToString()));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, TransactionDataProperties.TerminalId, terminalID));
                    // paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.ExternalReceipt, "<ReceiptData><Receipt Type='Customer'><Line>Line 1 of receipt.</Line><Line>Line 2 of receipt.</Line></Receipt><Receipt Type='Merchant'><Line>Line 1 of receipt.</Line><Line>Line 2 of receipt.</Line> </Receipt></ReceiptData>"));
                    paymentSdkProperties.Add(new PaymentProperty(GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.Properties, paymentSdkAuthorizationProperties.ToArray()));

                    string paymentSdkData = PaymentProperty.ConvertPropertyArrayToXML(paymentSdkProperties.ToArray());

                    paymentInfo.PaymentSdkData = paymentSdkData;

                    Logger.WriteLog($"Payment sdk Data: {paymentSdkData}");
                }
                else
                {
                    //EPS has not returned success
                    var    privateDataNode      = xmlDoc.GetElementsByTagName("PrivateData");
                    string privateDataNodeValue = privateDataNode[0].InnerText;
                    Logger.WriteLog($"EPS returned overallResult : {overallResult} with message {privateDataNodeValue}");

                    var paymentError  = new Microsoft.Dynamics.Retail.PaymentSDK.Portable.PaymentError(Microsoft.Dynamics.Retail.PaymentSDK.Portable.ErrorCode.GeneralException, $"EPS returned overallResult : {overallResult} with message {privateDataNodeValue}", true);
                    var PaymentErrors = new Microsoft.Dynamics.Retail.PaymentSDK.Portable.PaymentError[] { paymentError };
                    paymentInfo.Errors = PaymentErrors;
                    return(paymentInfo);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog($"An exception occoured while trying to parse the Authorize response .Message :{ex.Message} ,InnerException :{ex.InnerException},StackTrace{ex.StackTrace}");
            }
            return(paymentInfo);
        }
        public PaymentInfo MapVoidResponse(string responseStr, string paymentConnectorName)
        {
            PaymentInfo paymentInfo = new PaymentInfo
            {
                IsApproved = false
            };

            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(responseStr);

                XmlNodeList cardServiceResponseNode = xmlDoc.GetElementsByTagName("CardServiceResponse");
                string      requestType             = cardServiceResponseNode[0].Attributes["RequestType"].Value;
                string      workstationID           = cardServiceResponseNode[0].Attributes["WorkstationID"].Value;
                string      requestID     = cardServiceResponseNode[0].Attributes["RequestID"].Value;
                string      overallResult = cardServiceResponseNode[0].Attributes["OverallResult"].Value;

                Logger.WriteLog($"OverallResult value is :{overallResult}");

                //If OverallResult is not Success , then read the error  node and return else proceed further
                if (overallResult.ToLower().Equals("success"))
                {
                    var    terminalNode  = xmlDoc.GetElementsByTagName("Terminal");
                    string terminalID    = terminalNode[0].Attributes["TerminalID"].Value;
                    string terminalBatch = terminalNode[0].Attributes["TerminalBatch"].Value;

                    var tenderNode = xmlDoc.GetElementsByTagName("Tender");

                    var    totalAmountNode = xmlDoc.GetElementsByTagName("TotalAmount");
                    string totalAmount     = totalAmountNode[0].InnerText;

                    var    authorisationNode = xmlDoc.GetElementsByTagName("Authorisation");
                    string acquirerID        = authorisationNode[0].Attributes["AcquirerID"].Value;
                    string startDate         = authorisationNode[0].Attributes["StartDate"].Value;
                    string expiryDate        = authorisationNode[0].Attributes["ExpiryDate"].Value;
                    string timeStamp         = authorisationNode[0].Attributes["TimeStamp"].Value;

                    string actionCode        = authorisationNode[0].Attributes["ActionCode"].Value;
                    string approvalCode      = authorisationNode[0].Attributes["ApprovalCode"].Value;
                    string acquirerBatch     = authorisationNode[0].Attributes["AcquirerBatch"].Value;
                    string panprint          = authorisationNode[0].Attributes["PANprint"].Value;
                    string merchant          = authorisationNode[0].Attributes["Merchant"].Value;
                    string authorisationType = authorisationNode[0].Attributes["AuthorisationType"].Value;
                    string captureReference  = authorisationNode[0].Attributes["CaptureReference"].Value;

                    if (overallResult.Equals(OverallResult.Success.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        paymentInfo.IsApproved = true;
                    }


                    ////Building PaymentSdkData v0.1

                    List <PaymentProperty> paymentSdkAuthorizationProperties = new List <PaymentProperty>();
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, VoidResponseProperties.CloseAmount, totalAmount));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, VoidResponseProperties.ResponseCode, approvalCode));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, VoidResponseProperties.ProviderTransactionId, captureReference));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, VoidResponseProperties.VoidResult, RefundResult.Success.ToString()));
                    paymentSdkAuthorizationProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, TransactionDataProperties.TerminalId, terminalID));

                    List <PaymentProperty> paymentSdkProperties = new List <PaymentProperty>();
                    //TODO: The connector name should be based on the payment properties sent by POS in initial call and not hardcoded initial
                    paymentSdkProperties.Add(new PaymentProperty(GenericNamespace.Connector, ConnectorProperties.ConnectorName, paymentConnectorName));
                    paymentSdkProperties.Add(new PaymentProperty(GenericNamespace.VoidResponse, AuthorizationResponseProperties.Properties, paymentSdkAuthorizationProperties.ToArray()));

                    string paymentSdkData = PaymentProperty.ConvertPropertyArrayToXML(paymentSdkProperties.ToArray());

                    //Map all values to paymentinfo object
                    paymentInfo.ApprovedAmount   = Convert.ToDecimal(totalAmount);
                    paymentInfo.CardNumberMasked = "5413********4012";                                                                       //TODO : FIX for issue where EPS is returning first 4 digits of card masked in panprint causing POS to error;
                    paymentInfo.CardType         = Microsoft.Dynamics.Commerce.HardwareStation.CardPayment.CardType.InternationalCreditCard; //TODO:do we need to send this in response ?
                    paymentInfo.CashbackAmount   = decimal.Zero;
                    paymentInfo.PaymentSdkData   = paymentSdkData;
                    paymentInfo.IsApproved       = true;
                }
                else
                {
                    //EPS has not returned success
                    var    privateDataNode      = xmlDoc.GetElementsByTagName("PrivateData");
                    string privateDataNodeValue = privateDataNode[0].InnerText;
                    Logger.WriteLog($"EPS returned overallResult : {overallResult} with message {privateDataNodeValue}");

                    var paymentError  = new Microsoft.Dynamics.Retail.PaymentSDK.Portable.PaymentError(Microsoft.Dynamics.Retail.PaymentSDK.Portable.ErrorCode.GeneralException, $"EPS returned overallResult : {overallResult} with message {privateDataNodeValue}", true);
                    var PaymentErrors = new Microsoft.Dynamics.Retail.PaymentSDK.Portable.PaymentError[] { paymentError };
                    paymentInfo.Errors = PaymentErrors;
                    return(paymentInfo);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog($"An exception occoured while trying to parse VoidResponse response .Message :{ex.Message} ,InnerException :{ex.InnerException},StackTrace{ex.StackTrace}");
            }
            return(paymentInfo);
        }
示例#23
0
        protected override void BuildBody(StringBuilder page, PaymentRequest paymentRequest)
        {
            // create client
            string apiKey    = paymentRequest.PaymentMethod.DynamicProperty <string>().PublicKey;
            string apiSecret = paymentRequest.PaymentMethod.DynamicProperty <string>().SecretKey;
            string acceptUrl = paymentRequest.PaymentMethod.DynamicProperty <string>().AcceptUrl;

            var client = new StripeClient(apiSecret);
            var paymentIntentService = new PaymentIntentService(client);

            var createIntent = new PaymentIntentCreateOptions()
            {
                Currency = paymentRequest.Amount.CurrencyIsoCode,
                Amount   = Convert.ToInt64(paymentRequest.Amount.Value * 100)
            };

            var    paymentIntent       = paymentIntentService.Create(createIntent);
            string paymentFormTemplate = paymentRequest.PaymentMethod.DynamicProperty <string>().PaymentFormTemplate;
            var    allLines            = File.ReadAllLines(HttpContext.Current.Server.MapPath(paymentFormTemplate));

            foreach (var line in allLines)
            {
                page.AppendLine(line);
            }

            var billingDetails = new ChargeBillingDetails()
            {
                Name    = $"{paymentRequest.PurchaseOrder.BillingAddress.FirstName} {paymentRequest.PurchaseOrder.BillingAddress.LastName}",
                Address = new s.Address()
                {
                    Line1      = paymentRequest.PurchaseOrder.BillingAddress.Line1,
                    Line2      = paymentRequest.PurchaseOrder.BillingAddress.Line2,
                    City       = paymentRequest.PurchaseOrder.BillingAddress.City,
                    State      = paymentRequest.PurchaseOrder.BillingAddress.State,
                    PostalCode = paymentRequest.PurchaseOrder.BillingAddress.PostalCode,
                    Country    = paymentRequest.PurchaseOrder.BillingAddress.Country.TwoLetterISORegionName
                }
            };

            page.Replace("##STRIPE:PUBLICKEY##", apiKey);
            page.Replace("##STRIPE:PAYMENTINTENT##", JsonConvert.SerializeObject(paymentIntent));
            page.Replace("##STRIPE:BILLINGDETAILS##", JsonConvert.SerializeObject(billingDetails));
            page.Replace("##PROCESSURL##", $"/{paymentRequest.PaymentMethod.PaymentMethodId}/{paymentRequest.Payment["paymentGuid"]}/PaymentProcessor.axd");
            page.Replace("##ACCEPTURL##", acceptUrl);

            PaymentProperty paymentIntentProp;

            if (paymentRequest.Payment.PaymentProperties.Any(p => p.Key == PaymentIntentKey))
            {
                var allProps = paymentRequest.Payment.PaymentProperties.Where(p => p.Key == PaymentIntentKey).ToList();
                foreach (var prop in allProps)
                {
                    paymentRequest.Payment.PaymentProperties.Remove(prop);
                }
                paymentRequest.Payment.Save();
            }

            paymentIntentProp = new PaymentProperty()
            {
                Guid  = Guid.NewGuid(),
                Key   = PaymentIntentKey,
                Value = paymentIntent.Id
            };
            paymentRequest.Payment.AddPaymentProperty(paymentIntentProp);
            paymentRequest.Payment.Save();
        }
示例#24
0
            internal static AuthorizeRequest ConvertFrom(Request request)
            {
                var authorizeRequest = new AuthorizeRequest();
                var errors           = new List <PaymentError>();

                authorizeRequest.ReadBaseProperties(request, errors);

                // Read card data
                Hashtable 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("Card type is not supported: {0}.", authorizeRequest.CardType)));
                }

                authorizeRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                    hashtable,
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.IsSwipe);
                if (authorizeRequest.IsSwipe ?? false)
                {
                    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.HasValue &&
                    authorizeRequest.ExpirationMonth.HasValue &&
                    authorizeRequest.ExpirationYear >= 0M &&
                    authorizeRequest.ExpirationMonth >= 0M &&
                    !PaymentUtilities.ValidateExpirationDate(authorizeRequest.ExpirationYear.Value, authorizeRequest.ExpirationMonth.Value))
                {
                    errors.Add(new PaymentError(ErrorCode.InvalidExpirationDate, "Invalid expiration date."));
                }

                if (Microsoft.Dynamics.Retail.PaymentSDK.Portable.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.HasValue &&
                    authorizeRequest.CashBackAmount > 0M &&
                    !Microsoft.Dynamics.Retail.PaymentSDK.Portable.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("Currency code is not supported: {0}.", authorizeRequest.CurrencyCode)));
                }

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

                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);
            }
示例#25
0
            internal static RefundRequest ConvertFrom(Request request)
            {
                var refundRequest = new RefundRequest();
                var errors        = new List <PaymentError>();

                refundRequest.ReadBaseProperties(request, errors);

                // Check capture response
                Hashtable       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
                    Hashtable 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("Card type is not supported: {0}.", refundRequest.CardType)));
                    }

                    refundRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue(
                        hashtable,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.IsSwipe);
                    if (refundRequest.IsSwipe ?? false)
                    {
                        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.HasValue &&
                        refundRequest.ExpirationMonth.HasValue &&
                        refundRequest.ExpirationYear >= 0M &&
                        refundRequest.ExpirationMonth >= 0M &&
                        !PaymentUtilities.ValidateExpirationDate(refundRequest.ExpirationYear.Value, refundRequest.ExpirationMonth.Value))
                    {
                        errors.Add(new PaymentError(ErrorCode.InvalidExpirationDate, "Invalid expiration date."));
                    }

                    if (Microsoft.Dynamics.Retail.PaymentSDK.Portable.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("Currency code is not supported: {0}.", refundRequest.CurrencyCode)));
                }

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

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

                refundRequest.Level2Data = PaymentUtilities.GetLevel2Data(hashtable);
                refundRequest.Level3Data = PaymentUtilities.GetLevel3Data(hashtable);

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

                return(refundRequest);
            }
示例#26
0
            private void AddMerchantProperties(List <PaymentProperty> properties)
            {
                PaymentProperty property;

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.AssemblyName,
                    ConnectorAssembly);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.ServiceAccountId,
                    "136e9c86-31a1-4177-b2b7-a027c63edbe0");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.MerchantId,
                    "136e9c86-31a1-4177-b2b7-a027c63edbe0");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    "ProviderId",
                    "467079b4-1601-4f79-83c9-f569872eb94e");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    "Environment",
                    "ONEBOX");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.SupportedCurrencies,
                    "USD;CAD");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.SupportedTenderTypes,
                    "Visa;MasterCard;Amex;Discover;Debit");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    "TestString",
                    "Test string 1234567890 1234567890 End.");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    "TestDecimal",
                    12345.67M);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.MerchantAccount,
                    "TestDate",
                    new DateTime(2011, 9, 22, 11, 3, 0));
                properties.Add(property);
            }
            public Response RetrievePaymentAcceptResult([FromBody] Request request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                if (request.Properties == null)
                {
                    throw new ArgumentException("request.Properties cannot be null.");
                }

                // Initialize response
                var errorList = new List <PaymentError>();
                var response  = new Response()
                {
                    Locale = request.Locale,
                };

                // Validate merchant information
                ValidateMerchantAccount(request, errorList);

                // Get result access code from request
                var    requestProperties = PaymentProperty.ConvertToHashtable(request.Properties);
                string serviceAccountId  = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.MerchantAccount,
                    MerchantAccountProperties.ServiceAccountId,
                    required: true,
                    errors: errorList);
                string resultAccessCode = GetPropertyStringValue(
                    requestProperties,
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.PaymentAcceptResultAccessCode,
                    required: true,
                    errors: errorList);

                if (errorList.Count > 0)
                {
                    response.Errors = errorList.ToArray();
                    return(response);
                }

                // Retrieve payment result if no errors
                var dataManager = new DataManager();
                CardPaymentResult cardPaymentResult = dataManager.GetCardPaymentResultByResultAccessCode(serviceAccountId, resultAccessCode);

                if (cardPaymentResult == null)
                {
                    // Result does not exist.
                    errorList.Add(new PaymentError(ErrorCode.InvalidRequest, "Invalid payment result access code."));
                    response.Errors = errorList.ToArray();
                    return(response);
                }

                // Mark the result as retrieved so it cannot be retrieved again.
                dataManager.UpdateCardPaymentResultAsRetrieved(cardPaymentResult.ServiceAccountId, cardPaymentResult.ResultAccessCode);

                // Success
                response = JsonConvert.DeserializeObject <Response>(cardPaymentResult.ResultData);
                return(response);
            }
示例#28
0
            internal static Level2Data GetLevel2Data(Hashtable properties)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                Level2Data level2Data = null;

                PaymentProperty[] level2DataPropertyArray;
                if (PaymentProperty.GetPropertyValue(properties, GenericNamespace.PurchaseLevelData, PurchaseLevelDataProperties.L2Data, out level2DataPropertyArray))
                {
                    Hashtable level2DataProperties = PaymentProperty.ConvertToHashtable(level2DataPropertyArray);

                    level2Data = new Level2Data();
                    level2Data.OrderDateTime              = PaymentUtilities.GetPropertyDateTimeValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.OrderDateTime);
                    level2Data.OrderNumber                = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.OrderNumber);
                    level2Data.InvoiceDateTime            = PaymentUtilities.GetPropertyDateTimeValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.InvoiceDateTime);
                    level2Data.InvoiceNumber              = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.InvoiceNumber);
                    level2Data.OrderDescription           = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.OrderDescription);
                    level2Data.SummaryCommodityCode       = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.SummaryCommodityCode);
                    level2Data.MerchantContact            = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantContact);
                    level2Data.MerchantTaxId              = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantTaxId);
                    level2Data.MerchantType               = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantType);
                    level2Data.PurchaserId                = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.PurchaserId);
                    level2Data.PurchaserTaxId             = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.PurchaserTaxId);
                    level2Data.ShipToCity                 = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipToCity);
                    level2Data.ShipToCounty               = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipToCounty);
                    level2Data.ShipToState_ProvinceCode   = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipToState_ProvinceCode);
                    level2Data.ShipToPostalCode           = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipToPostalCode);
                    level2Data.ShipToCountryCode          = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipToCountryCode);
                    level2Data.ShipFromCity               = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipFromCity);
                    level2Data.ShipFromCounty             = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipFromCounty);
                    level2Data.ShipFromState_ProvinceCode = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipFromState_ProvinceCode);
                    level2Data.ShipFromPostalCode         = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipFromPostalCode);
                    level2Data.ShipFromCountryCode        = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.ShipFromCountryCode);
                    level2Data.DiscountAmount             = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.DiscountAmount);
                    level2Data.MiscCharge                 = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MiscCharge);
                    level2Data.DutyAmount                 = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.DutyAmount);
                    level2Data.FreightAmount              = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.FreightAmount);
                    level2Data.IsTaxable              = PaymentUtilities.GetPropertyBooleanValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.IsTaxable);
                    level2Data.TotalTaxAmount         = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TotalTaxAmount);
                    level2Data.TotalTaxRate           = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TotalTaxRate);
                    level2Data.MerchantName           = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantName);
                    level2Data.MerchantStreet         = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantStreet);
                    level2Data.MerchantCity           = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantCity);
                    level2Data.MerchantState          = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantState);
                    level2Data.MerchantCounty         = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantCounty);
                    level2Data.MerchantCountryCode    = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantCountryCode);
                    level2Data.MerchantZip            = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MerchantZip);
                    level2Data.TaxRate                = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TaxRate);
                    level2Data.TaxAmount              = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TaxAmount);
                    level2Data.TaxDescription         = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TaxDescription);
                    level2Data.TaxTypeIdentifier      = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TaxTypeIdentifier);
                    level2Data.RequesterName          = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.RequesterName);
                    level2Data.TotalAmount            = PaymentUtilities.GetPropertyDecimalValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TotalAmount);
                    level2Data.PurchaseCardType       = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.PurchaseCardType);
                    level2Data.AmexLegacyDescription1 = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.AmexLegacyDescription1);
                    level2Data.AmexLegacyDescription2 = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.AmexLegacyDescription2);
                    level2Data.AmexLegacyDescription3 = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.AmexLegacyDescription3);
                    level2Data.AmexLegacyDescription4 = PaymentUtilities.GetPropertyStringValue(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.AmexLegacyDescription4);

                    level2Data.TaxDetails           = PaymentUtilities.GetTaxDetails(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.TaxDetails);
                    level2Data.MiscellaneousCharges = PaymentUtilities.GetMiscellaneousCharges(level2DataProperties, GenericNamespace.L2Data, L2DataProperties.MiscellaneousCharges);
                }

                return(level2Data);
            }
示例#29
0
            internal static IEnumerable <Level3Data> GetLevel3Data(Hashtable properties)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                IEnumerable <Level3Data> level3Data = null;

                PaymentProperty[] level3DataPropertyArray;
                if (PaymentProperty.GetPropertyValue(properties, GenericNamespace.PurchaseLevelData, PurchaseLevelDataProperties.L3Data, out level3DataPropertyArray))
                {
                    if (level3DataPropertyArray.Length > 0)
                    {
                        level3Data = new List <Level3Data>();
                    }

                    foreach (var level3DataProperty in level3DataPropertyArray)
                    {
                        var       level3DataItems           = new Level3Data();
                        Hashtable level3DataItemsProperties = PaymentProperty.ConvertToHashtable(level3DataProperty.PropertyList);

                        level3DataItems.SequenceNumber        = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.SequenceNumber);
                        level3DataItems.CommodityCode         = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.CommodityCode);
                        level3DataItems.ProductCode           = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.ProductCode);
                        level3DataItems.ProductName           = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.ProductName);
                        level3DataItems.ProductSKU            = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.ProductSKU);
                        level3DataItems.Descriptor            = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.Descriptor);
                        level3DataItems.UnitOfMeasure         = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.UnitOfMeasure);
                        level3DataItems.UnitPrice             = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.UnitPrice);
                        level3DataItems.Discount              = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.Discount);
                        level3DataItems.DiscountRate          = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.DiscountRate);
                        level3DataItems.Quantity              = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.Quantity);
                        level3DataItems.MiscCharge            = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.MiscCharge);
                        level3DataItems.NetTotal              = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.NetTotal);
                        level3DataItems.TaxAmount             = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.TaxAmount);
                        level3DataItems.TaxRate               = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.TaxRate);
                        level3DataItems.TotalAmount           = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.TotalAmount);
                        level3DataItems.CostCenter            = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.CostCenter);
                        level3DataItems.FreightAmount         = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.FreightAmount);
                        level3DataItems.HandlingAmount        = PaymentUtilities.GetPropertyDecimalValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.HandlingAmount);
                        level3DataItems.CarrierTrackingNumber = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.CarrierTrackingNumber);
                        level3DataItems.MerchantTaxID         = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.MerchantTaxID);
                        level3DataItems.MerchantCatalogNumber = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.MerchantCatalogNumber);
                        level3DataItems.TaxCategoryApplied    = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.TaxCategoryApplied);
                        level3DataItems.PickupAddress         = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupAddress);
                        level3DataItems.PickupCity            = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupCity);
                        level3DataItems.PickupState           = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupState);
                        level3DataItems.PickupCounty          = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupCounty);
                        level3DataItems.PickupZip             = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupZip);
                        level3DataItems.PickupCountry         = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupCountry);
                        level3DataItems.PickupDateTime        = PaymentUtilities.GetPropertyDateTimeValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupDateTime);
                        level3DataItems.PickupRecordNumber    = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.PickupRecordNumber);
                        level3DataItems.CarrierShipmentNumber = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.CarrierShipmentNumber);
                        level3DataItems.UNSPSCCode            = PaymentUtilities.GetPropertyStringValue(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.UNSPSCCode);

                        level3DataItems.TaxDetails           = PaymentUtilities.GetTaxDetails(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.TaxDetails);
                        level3DataItems.MiscellaneousCharges = PaymentUtilities.GetMiscellaneousCharges(level3DataItemsProperties, GenericNamespace.L3Data, L3DataProperties.MiscellaneousCharges);

                        (level3Data as List <Level3Data>).Add(level3DataItems);
                    }
                }

                return(level3Data);
            }
示例#30
0
            private void GetPaymentAcceptPoint()
            {
                // Get payment processor
                PaymentProcessorManager.Create(new string[] { ConnectorAssembly });
                IPaymentProcessor processor = PaymentProcessorManager.GetPaymentProcessor(ConnectorName);

                // Prepare payment request
                var request = new Request();

                request.Locale = this.requestLocale;

                var properties = new List <PaymentProperty>();

                this.AddMerchantProperties(properties);

                PaymentProperty property;

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardType,
                    "Visa;MasterCard;Amex;Discover;Debit");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ShowSameAsShippingAddress,
                    this.showSameAsShippingAddress);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress,
                    "1 Microsoft Way");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.City,
                    "Redmond");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.State,
                    "WA");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.PostalCode,
                    "98052");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Country,
                    "US");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.TransactionType,
                    this.transactionType.ToString());
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardSwipe,
                    this.supportCardSwipe);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardTokenization,
                    this.supportCardTokenization);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.HostPageOrigin,
                    HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority));
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.IndustryType,
                    this.industryType);
                properties.Add(property);

                if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                {
                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.PurchaseLevel,
                        PurchaseLevel.Level1.ToString());
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.AllowPartialAuthorization,
                        "true");
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.AllowVoiceAuthorization,
                        this.supportVoiceAuthorization);
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.CurrencyCode,
                        "USD");
                    properties.Add(property);
                }

                request.Properties = properties.ToArray();

                // Call
                Response response = processor.GetPaymentAcceptPoint(request);

                if (response != null && response.Errors == null && response.Properties != null)
                {
                    Hashtable responseProperties = PaymentProperty.ConvertToHashtable(response.Properties);

                    string paymentAcceptUrl;
                    PaymentProperty.GetPropertyValue(
                        responseProperties,
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.PaymentAcceptUrl,
                        out paymentAcceptUrl);

                    if (!string.IsNullOrEmpty(paymentAcceptUrl))
                    {
                        this.PaymentAcceptUrl = string.Format(
                            "{0}&fontsize={1}&fontfamily={2}&labelcolor={3}&textbackgroundcolor={4}&textcolor={5}&disabledtextbackgroundcolor={6}&columnnumber={7}",
                            paymentAcceptUrl,
                            HttpUtility.UrlEncode(this.fontSize),
                            HttpUtility.UrlEncode(this.fontFamily),
                            HttpUtility.UrlEncode(this.labelColor),
                            HttpUtility.UrlEncode(this.textBackgroundColor),
                            HttpUtility.UrlEncode(this.textColor),
                            HttpUtility.UrlEncode(this.disabledTextBackgroundColor),
                            HttpUtility.UrlEncode(this.columnNumber));
                        this.CardPageOriginHiddenField.Value = new Uri(paymentAcceptUrl).GetLeftPart(UriPartial.Authority);
                    }
                    else
                    {
                        throw new InvalidOperationException("Failed to retrieve card page. Payment accepting URL is null or empty.");
                    }
                }
                else
                {
                    string errorMessage = string.Empty;
                    if (response == null)
                    {
                        errorMessage = "Response is null. ";
                    }
                    else
                    {
                        if (response.Properties == null)
                        {
                            errorMessage += "Response properties is null. ";
                        }

                        if (response.Errors != null)
                        {
                            errorMessage += "Response contains error(s). ";
                            foreach (var error in response.Errors)
                            {
                                errorMessage += string.Format("{0}: {1}.", error.Code, error.Message);
                            }
                        }
                    }

                    throw new InvalidOperationException("Failed to retrieve card page. " + errorMessage);
                }
            }