public static IEnumerable <PaymentProfileWrapper> GetPaymentProfiles(int customerId, string email) { Int64 profileId = DataUtility.GetProfileId(customerId); if (profileId <= 0) { yield break; } var profileMgr = new ProfileManager(customerId, email, profileId); using (SqlConnection connection = new SqlConnection(DB.GetDBConn())) { connection.Open(); using (SqlCommand command = new SqlCommand("select AuthorizeNetProfileId, CardType, ExpirationMonth, ExpirationYear from CIM_AddressPaymentProfileMap where CustomerId = @customerId", connection)) { command.Parameters.AddRange(new[] { new SqlParameter("@customerId", customerId), }); using (SqlDataReader reader = command.ExecuteReader()) { int authorizeNetProfileIdColumn = reader.GetOrdinal("AuthorizeNetProfileId"); int cardTypeColumn = reader.GetOrdinal("CardType"); int expirationMonthColumn = reader.GetOrdinal("ExpirationMonth"); int expirationYearColumn = reader.GetOrdinal("ExpirationYear"); while (reader.Read()) { long authorizeNetProfileId = reader.GetInt64(authorizeNetProfileIdColumn); string cardType = reader.GetString(cardTypeColumn); string expirationMonth = reader.GetString(expirationMonthColumn); string expirationYear = reader.GetString(expirationYearColumn); var cimProfile = profileMgr.GetPaymentProfile(authorizeNetProfileId); if (cimProfile == null) { continue; } CreditCardMaskedType maskedCard = (CreditCardMaskedType)cimProfile.payment.Item; yield return(new PaymentProfileWrapper() { CreditCardNumberMasked = string.Format("**** **** **** {0}", maskedCard.cardNumber.Substring(4)), CardType = cardType, ExpirationMonth = expirationMonth, ExpirationYear = expirationYear, CustomerId = customerId, ProfileId = authorizeNetProfileId, }); } } } } }
public static PaymentProfileWrapper GetPaymentProfileWrapper(int customerId, string email, Int64 paymentProfileId) { long profileID = DataUtility.GetProfileId(customerId); var profileMgr = new ProfileManager(customerId, email, profileID); var paymentProfile = profileMgr.GetPaymentProfile(paymentProfileId); var creditCardMasked = (CreditCardMaskedType)paymentProfile.payment.Item; var cimPaymentProfile = DataUtility.GetPaymentProfile(customerId, paymentProfileId); if (creditCardMasked != null && cimPaymentProfile != null) { return(new PaymentProfileWrapper() { CreditCardNumberMasked = creditCardMasked.cardNumber.Replace("XXXX", "****"), CardType = cimPaymentProfile.CardType, ExpirationMonth = cimPaymentProfile.ExpirationMonth, ExpirationYear = cimPaymentProfile.ExpirationYear, CustomerId = customerId, ProfileId = profileID }); } return(null); }