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); }
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); }
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); }
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); }
internal static VoidRequest ConvertFrom(Request request) { var voidRequest = new VoidRequest(); var errors = new List <PaymentError>(); voidRequest.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 voidRequest.CardType = PaymentUtilities.GetPropertyStringValue( authorizationHashtable, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.CardType, errors, ErrorCode.InvalidRequest); voidRequest.IsSwipe = PaymentUtilities.GetPropertyBooleanValue( authorizationHashtable, GenericNamespace.AuthorizationResponse, AuthorizationResponseProperties.IsSwiped); 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); }
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."); } Hashtable properties = PaymentProperty.ConvertToHashtable(request.Properties); this.AssemblyName = PaymentUtilities.GetPropertyStringValue( properties, GenericNamespace.MerchantAccount, MerchantAccountProperties.AssemblyName, errors, ErrorCode.InvalidMerchantProperty); 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.TestString = PaymentUtilities.GetPropertyStringValue( properties, GenericNamespace.MerchantAccount, SampleMerchantAccountProperty.TestString, errors, ErrorCode.InvalidMerchantProperty); this.TestDecimal = PaymentUtilities.GetPropertyDecimalValue( properties, GenericNamespace.MerchantAccount, SampleMerchantAccountProperty.TestDecimal, errors, ErrorCode.InvalidMerchantProperty); this.TestDate = PaymentUtilities.GetPropertyDateTimeValue( properties, GenericNamespace.MerchantAccount, SampleMerchantAccountProperty.TestDate, errors, ErrorCode.InvalidMerchantProperty); 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); }