Example #1
0
        /// <summary>
        /// Takes a GCR Response from Pinpad and translates it into Card information.
        /// </summary>
        /// <param name="rawResponse">GCR original response from Pinpad.</param>
        /// <param name="cardBrands">List of supported brands.</param>
        /// <returns>CardEntry containing basic information about the card.</returns>
        internal static CardEntry MapCardFromTracks(GcrResponse rawResponse,
                                                    IList <PinpadCardBrand> cardBrands)
        {
            CardType  readingMode = CardMapper.GetCardType(rawResponse.GCR_CARDTYPE.Value);
            CardEntry card        = null;

            if (readingMode == CardType.Emv)
            {
                card = EmvTrackMapper.MapCardFromEmvTrack(rawResponse);
            }
            else
            {
                card = MagneticStripeTrackMapper.MapCardFromTrack(rawResponse);
            }

            card.BrandName = CardMapper.GetBrandName(card.PrimaryAccountNumber,
                                                     cardBrands);

            // Unknown card type:
            return(card);
        }
Example #2
0
        /// <summary>
        /// Based on the Primary Account Number and the list of brands supported,
        /// determines the name of the card brand.
        /// </summary>
        /// <param name="pan">Card Primary Account Number.</param>
        /// <param name="cardBrands">List of supported brands.</param>
        /// <returns>Name of the card brand.</returns>
        internal static string GetBrandName(string pan,
                                            IList <PinpadCardBrand> cardBrands)
        {
            if (cardBrands != null)
            {
                // Get PAN as decimal:
                decimal decimalPan = CardMapper.PanToDecimal(pan);

                // Iterate through each brad to find the corresponding card read brand:
                foreach (PinpadCardBrand currentBrand in cardBrands)
                {
                    foreach (PinpadBinRange currentRange in currentBrand.Ranges)
                    {
                        // If PAN of read card is within the range, return it's brand name:
                        if (currentRange.IsWithin(decimalPan) == true)
                        {
                            return(currentBrand.Description);
                        }
                    }
                }
            }
            return(null);
        }