public Task <bool> Handle(RemoveCardBrandCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            CardBrand cardBrand = _cardBrandRepository.GetById(message.Id);

            if (cardBrand == null)
            {
                // notificar o dominio
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "Registro não encontrado"));

                return(Task.FromResult(false));
            }

            _cardBrandRepository.Remove(message.Id);

            if (Commit())
            {
                Bus.RaiseEvent(new CardBrandRemovedEvent(message.Id));
            }

            return(Task.FromResult(true));
        }
        public async Task <dynamic> GetCardBrandByName(string url, string name)
        {
            string urlInfo = "https://localhost:44338/api/v1/CardBrand-management/";

            CardBrand cardBrand = null;

            using (HttpResponseMessage response = await _httpClient.GetAsync(urlInfo + name))
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    dynamic contents = await response.Content.ReadAsStringAsync();

                    dynamic message = JsonConvert.DeserializeObject <ExpandoObject>(contents, new ExpandoObjectConverter());
                    var     success = message.success;
                    var     data    = message.data;
                    cardBrand = JsonConvert.DeserializeObject <CardBrand>(JsonConvert.SerializeObject(data));
                }

                return(new
                {
                    Status = response.StatusCode,
                    Data = cardBrand
                });
            }
        }
// RetrieveCardByPartnerToken
        /// <summary>
        /// Retrieve the list of cards that are currently active
        /// and have same partner card id.
        /// </summary>
        /// <returns>
        /// The list of cards
        /// </returns>
        public IEnumerable <InternalCard> RetrieveCardsByPartnerCardId()
        {
            List <InternalCard> result = new List <InternalCard>();

            string    partnerCardId = (string)Context[Key.PartnerCardId];
            CardBrand cardBrand     = (CardBrand)Context[Key.CardBrand];

            SqlProcedure("GetCardByPartnerToken",
                         new Dictionary <string, object>
            {
                { "@cardBrand", cardBrand },
                { "@partnerToken", partnerCardId }
            },

                         (sqlDataReader) =>
            {
                while (sqlDataReader.Read() == true)
                {
                    result.Add(new InternalCard
                    {
                        Id           = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("CardId")),
                        GlobalUserId = sqlDataReader.GetGuid(sqlDataReader.GetOrdinal("GlobalUserID"))
                    });
                }
            });

            Context.Log.Verbose("GetCardByPartnerToken retrieved {0} cards for the specified PartnerCardId.", result.Count);

            return(result);
        }
Beispiel #4
0
        public async Task <dynamic> GetByNameCardBrand(string url, string name)
        {
            using (HttpResponseMessage response = await _httpClient.GetAsync(url + name))
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    dynamic contents = await response.Content.ReadAsStringAsync();

                    dynamic   message  = JsonConvert.DeserializeObject <ExpandoObject>(contents, new ExpandoObjectConverter());
                    var       success  = message.success;
                    var       data     = message.data;
                    CardBrand cardType = JsonConvert.DeserializeObject <CardBrand>(JsonConvert.SerializeObject(data));
                    return(new
                    {
                        Status = response.StatusCode,
                        Data = cardType
                    });
                }
                return(new
                {
                    Status = response.StatusCode,
                    Data = new List <CardBrand>()
                });
            }
        }
        private PaymentNetwork(CardBrand cardBrand)
        {
            switch (cardBrand)
            {
            case CardBrand.AMERICAN_EXPRESS:
                rawValue = "AmEx";
                break;

            case CardBrand.DISCOVER:
                rawValue = "Discover";
                break;

            case CardBrand.JCB:
                rawValue = "JCB";
                break;

            case CardBrand.MASTERCARD:
                rawValue = "MasterCard";
                break;

            case CardBrand.VISA:
                rawValue = "Visa";
                break;

            default:
                rawValue = null;
                break;
            }
        }
        public async Task Post_CardBrand_The_Guid_is_empty()
        {
            CardBrand cardBrand = new CardBrand
            {
                Id   = Guid.Empty,
                Name = "1"
            };

            var service = new CardBrandService(_httpClient);
            var result  = await service.PostCardBrand(requestUri, cardBrand);

            if (result.Status == HttpStatusCode.OK)
            {
                Assert.True(result.Status == HttpStatusCode.OK, "OK");
            }
            else
            {
                List <string> listError = new List <string>();
                foreach (string error in result.Data)
                {
                    listError.Add(error);
                }
                Assert.Collection(listError,
                                  item => Assert.Equal("The Name is Required", item),
                                  item => Assert.Equal("The Name must have between 2 and 30 characters", item),
                                  item => Assert.Equal("The Guid is empty", item),
                                  item => Assert.Equal("The Guid is invalid and contains 00000000", item),
                                  item => Assert.Equal("The card brand id has already been taken.", item),
                                  item => Assert.Equal("The card brand name has already been taken.", item)
                                  );
            }
        }
        public async Task <dynamic> GetCardBrandByName(string url, string name)
        {
            string urlInfo = ConfigurationManager.AppSettings["url_servidor_comunicacoes"] + "/CardBrand-management/";

            CardBrand cardBrand = null;

            using (HttpResponseMessage response = await _httpClient.GetAsync(urlInfo + name))
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    dynamic contents = await response.Content.ReadAsStringAsync();

                    dynamic message = JsonConvert.DeserializeObject <ExpandoObject>(contents, new ExpandoObjectConverter());
                    var     success = message.success;
                    var     data    = message.data;
                    cardBrand = JsonConvert.DeserializeObject <CardBrand>(JsonConvert.SerializeObject(data));
                }

                return(new
                {
                    Status = response.StatusCode,
                    Data = cardBrand
                });
            }
        }
        public async Task Put_CardBrand_The_Name_must_have_between_2_and_30_characters()
        {
            Guid guid = new Guid("1BF784F8-7B94-47EC-9FD9-5257D83E8E7D");

            CardBrand cardBrand = new CardBrand
            {
                Id   = guid,
                Name = "o"
            };

            var service = new CardBrandService(_httpClient);
            var result  = await service.PutCardBrand(requestUri, cardBrand);

            if (result.Status == HttpStatusCode.OK)
            {
                Assert.True(result.Status == HttpStatusCode.OK, "OK");
            }
            else
            {
                List <string> listError = new List <string>();
                foreach (string error in result.Data)
                {
                    listError.Add(error);
                }
                Assert.Collection(listError,
                                  item => Assert.Equal("The Name is Required", item),
                                  item => Assert.Equal("The Name must have between 2 and 30 characters", item),
                                  item => Assert.Equal("The Guid is empty", item),
                                  item => Assert.Equal("The Guid is invalid and contains 00000000", item),
                                  item => Assert.Equal("The card brand name has already been taken.", item)
                                  );
            }
        }
        public async Task Put_CardBrand_Valido()
        {
            Guid guid = new Guid("5E210F4F-D12B-4F85-8464-6F8740920FAA");

            CardBrand cardBrand = new CardBrand
            {
                Id   = guid,
                Name = "ALTERADO..."
            };

            var service = new CardBrandService(_httpClient);
            var result  = await service.PutCardBrand(requestUri, cardBrand);

            if (result.Status == HttpStatusCode.OK)
            {
                Assert.True(result.Status == HttpStatusCode.OK, "OK");
            }
            else
            {
                List <string> listError = new List <string>();
                foreach (string error in result.Data)
                {
                    listError.Add(error);
                }
                Assert.Collection(listError,
                                  item => Assert.Equal("The Name is Required", item),
                                  item => Assert.Equal("The Name must have between 2 and 30 characters", item),
                                  item => Assert.Equal("The Guid is empty", item),
                                  item => Assert.Equal("The Guid is invalid and contains 00000000", item),
                                  item => Assert.Equal("The card brand name has already been taken.", item)
                                  );
            }
        }
Beispiel #10
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is Card other &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((CardBrand == null && other.CardBrand == null) || (CardBrand?.Equals(other.CardBrand) == true)) &&
                   ((Last4 == null && other.Last4 == null) || (Last4?.Equals(other.Last4) == true)) &&
                   ((ExpMonth == null && other.ExpMonth == null) || (ExpMonth?.Equals(other.ExpMonth) == true)) &&
                   ((ExpYear == null && other.ExpYear == null) || (ExpYear?.Equals(other.ExpYear) == true)) &&
                   ((CardholderName == null && other.CardholderName == null) || (CardholderName?.Equals(other.CardholderName) == true)) &&
                   ((BillingAddress == null && other.BillingAddress == null) || (BillingAddress?.Equals(other.BillingAddress) == true)) &&
                   ((Fingerprint == null && other.Fingerprint == null) || (Fingerprint?.Equals(other.Fingerprint) == true)) &&
                   ((CardType == null && other.CardType == null) || (CardType?.Equals(other.CardType) == true)) &&
                   ((PrepaidType == null && other.PrepaidType == null) || (PrepaidType?.Equals(other.PrepaidType) == true)) &&
                   ((Bin == null && other.Bin == null) || (Bin?.Equals(other.Bin) == true)));
        }
        public Task <bool> Handle(RegisterNewCardBrandCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            //var cardBrand = new CardBrand(Guid.NewGuid(), message.Name);
            var cardBrand = new CardBrand(message.Id, message.Name);

            if (_cardBrandRepository.GetByName(message.Name) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card brand name has already been taken."));
                return(Task.FromResult(false));
            }

            if (_cardBrandRepository.GetById(message.Id) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card brand id has already been taken."));
                return(Task.FromResult(false));
            }

            _cardBrandRepository.Add(cardBrand);

            if (Commit())
            {
                Bus.RaiseEvent(new CardBrandRegisteredEvent(cardBrand.Id, cardBrand.Name));
            }

            return(Task.FromResult(true));
        }
Beispiel #12
0
        public static CardType ToClearSaleCardBrand(this CardBrand cardBrand)
        {
            switch (cardBrand)
            {
            case CardBrand.Master:
                return(CardType.MasterCard);

            case CardBrand.Visa:
                return(CardType.Visa);

            case CardBrand.Amex:
                return(CardType.AmericanExpress);

            case CardBrand.Aura:
                return(CardType.Aura);

            case CardBrand.Diners:
                return(CardType.Diners);

            case CardBrand.Hipercard:
                return(CardType.HiperCard);

            default:
                return(CardType.Others);
            }
        }
Beispiel #13
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is V1Tender other &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((Type == null && other.Type == null) || (Type?.Equals(other.Type) == true)) &&
                   ((Name == null && other.Name == null) || (Name?.Equals(other.Name) == true)) &&
                   ((EmployeeId == null && other.EmployeeId == null) || (EmployeeId?.Equals(other.EmployeeId) == true)) &&
                   ((ReceiptUrl == null && other.ReceiptUrl == null) || (ReceiptUrl?.Equals(other.ReceiptUrl) == true)) &&
                   ((CardBrand == null && other.CardBrand == null) || (CardBrand?.Equals(other.CardBrand) == true)) &&
                   ((PanSuffix == null && other.PanSuffix == null) || (PanSuffix?.Equals(other.PanSuffix) == true)) &&
                   ((EntryMethod == null && other.EntryMethod == null) || (EntryMethod?.Equals(other.EntryMethod) == true)) &&
                   ((PaymentNote == null && other.PaymentNote == null) || (PaymentNote?.Equals(other.PaymentNote) == true)) &&
                   ((TotalMoney == null && other.TotalMoney == null) || (TotalMoney?.Equals(other.TotalMoney) == true)) &&
                   ((TenderedMoney == null && other.TenderedMoney == null) || (TenderedMoney?.Equals(other.TenderedMoney) == true)) &&
                   ((TenderedAt == null && other.TenderedAt == null) || (TenderedAt?.Equals(other.TenderedAt) == true)) &&
                   ((SettledAt == null && other.SettledAt == null) || (SettledAt?.Equals(other.SettledAt) == true)) &&
                   ((ChangeBackMoney == null && other.ChangeBackMoney == null) || (ChangeBackMoney?.Equals(other.ChangeBackMoney) == true)) &&
                   ((RefundedMoney == null && other.RefundedMoney == null) || (RefundedMoney?.Equals(other.RefundedMoney) == true)) &&
                   ((IsExchange == null && other.IsExchange == null) || (IsExchange?.Equals(other.IsExchange) == true)));
        }
        public Task <bool> Handle(UpdateCardBrandCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var cardBrand         = new CardBrand(message.Id, message.Name);
            var existingCardBrand = _cardBrandRepository.GetByName(cardBrand.Name);

            if (existingCardBrand != null && existingCardBrand.Id != cardBrand.Id)
            {
                if (!existingCardBrand.Equals(cardBrand))
                {
                    Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card brand name has already been taken."));
                    return(Task.FromResult(false));
                }
            }

            _cardBrandRepository.Update(cardBrand);

            if (Commit())
            {
                Bus.RaiseEvent(new CardBrandUpdatedEvent(cardBrand.Id, cardBrand.Name));
            }

            return(Task.FromResult(true));
        }
Beispiel #15
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is Dispute other &&
                   ((DisputeId == null && other.DisputeId == null) || (DisputeId?.Equals(other.DisputeId) == true)) &&
                   ((AmountMoney == null && other.AmountMoney == null) || (AmountMoney?.Equals(other.AmountMoney) == true)) &&
                   ((Reason == null && other.Reason == null) || (Reason?.Equals(other.Reason) == true)) &&
                   ((State == null && other.State == null) || (State?.Equals(other.State) == true)) &&
                   ((DueAt == null && other.DueAt == null) || (DueAt?.Equals(other.DueAt) == true)) &&
                   ((DisputedPayment == null && other.DisputedPayment == null) || (DisputedPayment?.Equals(other.DisputedPayment) == true)) &&
                   ((EvidenceIds == null && other.EvidenceIds == null) || (EvidenceIds?.Equals(other.EvidenceIds) == true)) &&
                   ((CardBrand == null && other.CardBrand == null) || (CardBrand?.Equals(other.CardBrand) == true)) &&
                   ((CreatedAt == null && other.CreatedAt == null) || (CreatedAt?.Equals(other.CreatedAt) == true)) &&
                   ((UpdatedAt == null && other.UpdatedAt == null) || (UpdatedAt?.Equals(other.UpdatedAt) == true)) &&
                   ((BrandDisputeId == null && other.BrandDisputeId == null) || (BrandDisputeId?.Equals(other.BrandDisputeId) == true)) &&
                   ((ReportedDate == null && other.ReportedDate == null) || (ReportedDate?.Equals(other.ReportedDate) == true)) &&
                   ((Version == null && other.Version == null) || (Version?.Equals(other.Version) == true)) &&
                   ((LocationId == null && other.LocationId == null) || (LocationId?.Equals(other.LocationId) == true)));
        }
Beispiel #16
0
        /// <summary>
        /// Gets the hash code for this object.
        /// </summary>
        /// <returns>
        /// The hash code for this object.
        /// </returns>
        /// <remarks>
        /// * CA2218:
        ///   * If two objects are equal in value based on the Equals override, they must both return the same value for calls
        ///     to GetHashCode.
        ///   * GetHashCode must be overridden whenever Equals is overridden.
        /// * It is fine if the value overflows.
        /// </remarks>
        public override int GetHashCode()
        {
            int result = Id.GetHashCode() +
                         GlobalUserId.GetHashCode() +
                         Expiration.GetHashCode() +
                         CardBrand.GetHashCode() +
                         RewardPrograms.GetHashCode();

            if (NameOnCard != null)
            {
                result += NameOnCard.GetHashCode();
            }

            if (LastFourDigits != null)
            {
                result += LastFourDigits.GetHashCode();
            }

            if (PanToken != null)
            {
                result += PanToken.GetHashCode();
            }

            return(result);
        }
Beispiel #17
0
 /// <summary>
 /// Credit card information.
 /// </summary>
 /// <param name="cardToken">Saved Card Token</param>
 /// <param name="securityCode">Card's Secutiry Code</param>
 /// <param name="cardBrand">Card Brand</param>
 public CreditCard(string cardToken,
                   string securityCode,
                   CardBrand cardBrand)
 {
     CardToken    = cardToken;
     SecurityCode = securityCode;
     Brand        = cardBrand.ToDescription();
 }
 public Card(string cardToken, CardBrand cardBrand, string provider)
 {
     if (!string.IsNullOrEmpty(cardToken))
     {
         CardToken = new Guid(cardToken);
     }
     CardBrand = cardBrand;
     Provider  = provider;
 }
Beispiel #19
0
 /// <summary>
 /// Debit card information.
 /// </summary>
 /// <param name="cardNumber">Card Number</param>
 /// <param name="holder">Card's Holder Name</param>
 /// <param name="expirationDate">Card's Expiration Date</param>
 /// <param name="securityCode">Card's Secutiry Code</param>
 /// <param name="cardBrand">Card Brand</param>
 public DebitCard(string cardNumber,
                  string holder,
                  CardExpiration expirationDate,
                  string securityCode,
                  CardBrand cardBrand)
 {
     CardNumber   = cardNumber.ToNumbers();
     Holder       = holder;
     _expiration  = expirationDate;
     SecurityCode = securityCode;
     Brand        = cardBrand.ToDescription();
 }
Beispiel #20
0
 /// <summary>
 /// Credit card information.
 /// </summary>
 /// <param name="customerName">Customer Name</param>
 /// <param name="cardNumber">Card Number</param>
 /// <param name="holder">Card's Holder Name</param>
 /// <param name="expirationDate">Card's Expiration Date</param>
 /// <param name="cardBrand">Card Brand</param>
 public CreditCardRequest(string customerName,
                          string cardNumber,
                          string holder,
                          CardExpiration expirationDate,
                          CardBrand cardBrand)
 {
     CustomerName = customerName;
     CardNumber   = cardNumber.ToNumbers();
     Holder       = holder;
     _expiration  = expirationDate;
     Brand        = cardBrand.ToDescription();
 }
 public CieloCard(string cardNumber, string holder, short yearExpired, byte monthExpired, string securityCode, CardBrand brand,
                  byte installments, bool saveCard = false, decimal?valorMinimoParcela = null, int?limiteMaximoParcelas = null)
     : this(valorMinimoParcela, limiteMaximoParcelas)
 {
     CardNumber   = cardNumber;
     Holder       = holder;
     YearExpired  = yearExpired;
     MonthExpired = monthExpired;
     SecurityCode = securityCode;
     Brand        = brand;
     Installments = installments;
     SaveCard     = saveCard;
 }
        public static PaymentNetwork FromCardBrand(CardBrand cardBrand)
        {
            var network = new PaymentNetwork(cardBrand);

            if (network.rawValue == null)
            {
                return(null);
            }
            else
            {
                return(network);
            }
        }
        public override int GetHashCode()
        {
            int hashCode = 805936600;

            if (BeginTime != null)
            {
                hashCode += BeginTime.GetHashCode();
            }

            if (EndTime != null)
            {
                hashCode += EndTime.GetHashCode();
            }

            if (SortOrder != null)
            {
                hashCode += SortOrder.GetHashCode();
            }

            if (Cursor != null)
            {
                hashCode += Cursor.GetHashCode();
            }

            if (LocationId != null)
            {
                hashCode += LocationId.GetHashCode();
            }

            if (Total != null)
            {
                hashCode += Total.GetHashCode();
            }

            if (Last4 != null)
            {
                hashCode += Last4.GetHashCode();
            }

            if (CardBrand != null)
            {
                hashCode += CardBrand.GetHashCode();
            }

            if (Limit != null)
            {
                hashCode += Limit.GetHashCode();
            }

            return(hashCode);
        }
Beispiel #24
0
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"Id = {(Id == null ? "null" : Id == string.Empty ? "" : Id)}");
     toStringOutput.Add($"CardBrand = {(CardBrand == null ? "null" : CardBrand.ToString())}");
     toStringOutput.Add($"Last4 = {(Last4 == null ? "null" : Last4 == string.Empty ? "" : Last4)}");
     toStringOutput.Add($"ExpMonth = {(ExpMonth == null ? "null" : ExpMonth.ToString())}");
     toStringOutput.Add($"ExpYear = {(ExpYear == null ? "null" : ExpYear.ToString())}");
     toStringOutput.Add($"CardholderName = {(CardholderName == null ? "null" : CardholderName == string.Empty ? "" : CardholderName)}");
     toStringOutput.Add($"BillingAddress = {(BillingAddress == null ? "null" : BillingAddress.ToString())}");
     toStringOutput.Add($"Fingerprint = {(Fingerprint == null ? "null" : Fingerprint == string.Empty ? "" : Fingerprint)}");
     toStringOutput.Add($"CardType = {(CardType == null ? "null" : CardType.ToString())}");
     toStringOutput.Add($"PrepaidType = {(PrepaidType == null ? "null" : PrepaidType.ToString())}");
     toStringOutput.Add($"Bin = {(Bin == null ? "null" : Bin == string.Empty ? "" : Bin)}");
 }
Beispiel #25
0
 /// <summary>
 /// Credit card information.
 /// </summary>
 /// <param name="cardNumber">Card Number</param>
 /// <param name="holder">Card's Holder Name</param>
 /// <param name="expirationDate">Card's Expiration Date</param>
 /// <param name="securityCode">Card's Secutiry Code</param>
 /// <param name="cardBrand">Card Brand</param>
 /// <param name="saveCard">Save Card</param>
 public CreditCard(string cardNumber,
                   string holder,
                   CardExpiration expirationDate,
                   string securityCode,
                   CardBrand cardBrand,
                   bool saveCard = false)
 {
     CardNumber   = cardNumber.ToNumbers();
     Holder       = holder;
     _expiration  = expirationDate;
     SecurityCode = securityCode;
     Brand        = cardBrand.ToDescription();
     SaveCard     = saveCard;
 }
Beispiel #26
0
        public string AutorizacaoCredito()
        {
            decimal   value = 150.01M;
            CardBrand brand = CardBrand.Visa;

            var customer = new Customer(_nomeCartao);

            customer.SetIdentityType(IdentityType.CPF);
            customer.Identity = "14258222402"; //numero gerado aleatoriamente
            customer.SetBirthdate(1990, 2, 1);
            customer.Email = "*****@*****.**";

            var creditCard = new Card(
                cardNumber: SandboxCreditCard.Authorized1,
                holder: _nomeCartao,
                expirationDate: _validDate,
                securityCode: "123",
                brand: brand);

            var payment = new Payment(
                amount: value,
                currency: Currency.BRL,
                installments: 1,
                capture: false,
                softDescriptor: _descricao,
                card: creditCard,
                returnUrl: "http://www.cielo.com.br");

            /* store order number */
            var merchantOrderId = new Random().Next();

            var transaction = new Transaction(
                merchantOrderId: merchantOrderId.ToString(),
                customer: customer,
                payment: payment);

            var returnTransaction = _api.CreateTransaction(Guid.NewGuid(), transaction);

            //Consultando
            var result = _api.GetTransaction(returnTransaction.Payment.PaymentId.Value);

            Assert.IsTrue(result.Payment.CreditCard.GetBrand() == brand, "Erro na bandeira do cartão");
            Assert.IsTrue(result.Payment.CreditCard.ExpirationDate == _validDate.ToString("MM/yyyy"), "Erro na data de vencimento do cartão");
            Assert.IsTrue(result.Payment.GetAmount() == value, "Erro no valor da fatura");
            Assert.IsTrue(result.Payment.GetStatus() == Status.Authorized, "Transação não foi autorizada");

            return(merchantOrderId.ToString());
        }
Beispiel #27
0
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"DisputeId = {(DisputeId == null ? "null" : DisputeId == string.Empty ? "" : DisputeId)}");
     toStringOutput.Add($"AmountMoney = {(AmountMoney == null ? "null" : AmountMoney.ToString())}");
     toStringOutput.Add($"Reason = {(Reason == null ? "null" : Reason.ToString())}");
     toStringOutput.Add($"State = {(State == null ? "null" : State.ToString())}");
     toStringOutput.Add($"DueAt = {(DueAt == null ? "null" : DueAt == string.Empty ? "" : DueAt)}");
     toStringOutput.Add($"DisputedPayment = {(DisputedPayment == null ? "null" : DisputedPayment.ToString())}");
     toStringOutput.Add($"EvidenceIds = {(EvidenceIds == null ? "null" : $"[{ string.Join(", ", EvidenceIds)} ]")}");
     toStringOutput.Add($"CardBrand = {(CardBrand == null ? "null" : CardBrand.ToString())}");
     toStringOutput.Add($"CreatedAt = {(CreatedAt == null ? "null" : CreatedAt == string.Empty ? "" : CreatedAt)}");
     toStringOutput.Add($"UpdatedAt = {(UpdatedAt == null ? "null" : UpdatedAt == string.Empty ? "" : UpdatedAt)}");
     toStringOutput.Add($"BrandDisputeId = {(BrandDisputeId == null ? "null" : BrandDisputeId == string.Empty ? "" : BrandDisputeId)}");
     toStringOutput.Add($"ReportedDate = {(ReportedDate == null ? "null" : ReportedDate == string.Empty ? "" : ReportedDate)}");
     toStringOutput.Add($"Version = {(Version == null ? "null" : Version.ToString())}");
     toStringOutput.Add($"LocationId = {(LocationId == null ? "null" : LocationId == string.Empty ? "" : LocationId)}");
 }
Beispiel #28
0
        public void AutorizacaoDebito()
        {
            decimal   value = 178.91M;
            CardBrand brand = CardBrand.Master;

            var customer = new Customer(name: _nome);

            var card = new Card(
                cardNumber: SandboxCreditCard.Authorized1,
                holder: _nomeCartao,
                expirationDate: _validDate,
                securityCode: "123",
                brand: brand);

            var payment = new Payment(
                amount: value,
                currency: Currency.BRL,
                paymentType: PaymentType.DebitCard,
                installments: 1,
                capture: true,
                softDescriptor: _descricao,
                card: card,
                returnUrl: "http://www.cielo.com.br");

            /* store order number */
            var merchantOrderId = new Random().Next();

            var transaction = new Transaction(
                merchantOrderId: merchantOrderId.ToString(),
                customer: customer,
                payment: payment);

            var returnTransaction = _api.CreateTransaction(Guid.NewGuid(), transaction);

            //Consultando
            var result = _api.GetTransaction(returnTransaction.Payment.PaymentId.Value);

            Assert.IsTrue(result.Payment.DebitCard.GetBrand() == brand, "Erro na bandeira do cartão");
            Assert.IsTrue(result.Payment.DebitCard.ExpirationDate == _validDate.ToString("MM/yyyy"), "Erro na data de vencimento do cartão");
            Assert.IsTrue(result.Payment.GetAmount() == value, "Erro no valor da fatura");
            Assert.IsTrue(!string.IsNullOrEmpty(result.Payment.Links[0].Href), "Link para o redirecionamento não retornado");

            //No caso primeiro tem q ser redirecionado para depois consultar
            Assert.IsTrue(!String.IsNullOrEmpty(returnTransaction.Payment.AuthenticationUrl), "AuthenticationUrl não foi retornada");
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (BillingAddress != null ? BillingAddress.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CardBrand != null ? CardBrand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ CardExpMonth.GetHashCode();
         hashCode = (hashCode * 397) ^ CardExpYear.GetHashCode();
         hashCode = (hashCode * 397) ^ (CardLast4 != null ? CardLast4.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ CustomerId.GetHashCode();
         hashCode = (hashCode * 397) ^ HasCardErrorInDunning.GetHashCode();
         hashCode = (hashCode * 397) ^ (PaymentType != null ? PaymentType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ProcessorName != null ? ProcessorName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StatusReason != null ? StatusReason.GetHashCode() : 0);
         return(hashCode);
     }
 }
Beispiel #30
0
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"Id = {(Id == null ? "null" : Id == string.Empty ? "" : Id)}");
     toStringOutput.Add($"Type = {(Type == null ? "null" : Type.ToString())}");
     toStringOutput.Add($"Name = {(Name == null ? "null" : Name == string.Empty ? "" : Name)}");
     toStringOutput.Add($"EmployeeId = {(EmployeeId == null ? "null" : EmployeeId == string.Empty ? "" : EmployeeId)}");
     toStringOutput.Add($"ReceiptUrl = {(ReceiptUrl == null ? "null" : ReceiptUrl == string.Empty ? "" : ReceiptUrl)}");
     toStringOutput.Add($"CardBrand = {(CardBrand == null ? "null" : CardBrand.ToString())}");
     toStringOutput.Add($"PanSuffix = {(PanSuffix == null ? "null" : PanSuffix == string.Empty ? "" : PanSuffix)}");
     toStringOutput.Add($"EntryMethod = {(EntryMethod == null ? "null" : EntryMethod.ToString())}");
     toStringOutput.Add($"PaymentNote = {(PaymentNote == null ? "null" : PaymentNote == string.Empty ? "" : PaymentNote)}");
     toStringOutput.Add($"TotalMoney = {(TotalMoney == null ? "null" : TotalMoney.ToString())}");
     toStringOutput.Add($"TenderedMoney = {(TenderedMoney == null ? "null" : TenderedMoney.ToString())}");
     toStringOutput.Add($"TenderedAt = {(TenderedAt == null ? "null" : TenderedAt == string.Empty ? "" : TenderedAt)}");
     toStringOutput.Add($"SettledAt = {(SettledAt == null ? "null" : SettledAt == string.Empty ? "" : SettledAt)}");
     toStringOutput.Add($"ChangeBackMoney = {(ChangeBackMoney == null ? "null" : ChangeBackMoney.ToString())}");
     toStringOutput.Add($"RefundedMoney = {(RefundedMoney == null ? "null" : RefundedMoney.ToString())}");
     toStringOutput.Add($"IsExchange = {(IsExchange == null ? "null" : IsExchange.ToString())}");
 }
 public void OnCardSelected(object sender, EventArgs e)
 {
     RadioButton rb = sender as RadioButton;
     string rbName = rb.Name;
     switch (rbName)
     {
         case "Visa":
             selectedCard = CardBrand.Visa;
             break;
         case "MasterCard":
             selectedCard = CardBrand.MasterCard;
             break;
         case "AmericanExpress":
             selectedCard = CardBrand.AmericanExpress;
             break;
         default:
             selectedCard = CardBrand.Discover;
             break;
     }
 }
        public static bool Validate(CardBrand cardBrand, string cardNumber)
        {
            byte[] number = new byte[16]; // card number to validate

            // Remove non-digits
            int length = 0;
            for (int i = 0; i < cardNumber.Length; i++)
            {
                if (char.IsDigit(cardNumber, i))
                {
                    if (length == 16) return false; // card has too many digits
                    number[length++] = byte.Parse(cardNumber[i].ToString());
                }
            }

            // To validate a card, you need to test length then prefix...
            switch (cardBrand)
            {
                case CardBrand.BankCard:
                    if (length != 16)
                        return false;
                    if (number[0] != 5 || number[1] != 6 || number[2] > 1)
                        return false;
                    break;

                case CardBrand.MasterCard:
                    if (length != 16)
                        return false;
                    if (number[0] != 5 || number[1] == 0 || number[1] > 5)
                        return false;
                    break;

                case CardBrand.Visa:
                    if (length != 16 && length != 13)
                        return false;
                    if (number[0] != 4)
                        return false;
                    break;

                case CardBrand.AmericanExpress:
                    if (length != 15)
                        return false;
                    if (number[0] != 3 || (number[1] != 4 && number[1] != 7))
                        return false;
                    break;

                case CardBrand.Discover:
                    if (length != 16)
                        return false;
                    if (number[0] != 6 || number[1] != 0 || number[2] != 1 || number[3] != 1)
                        return false;
                    break;

                case CardBrand.DinersClub:
                    if (length != 14)
                        return false;
                    if (number[0] != 3 || (number[1] != 0 && number[1] != 6 && number[1] != 8)
                       || number[1] == 0 && number[2] > 5)
                        return false;
                    break;

            }

            // Now we use the classic Luhn Algorithm to validate
            int sum = 0;
            for (int i = length - 1; i >= 0; i--)
            {
                if (i % 2 == length % 2)
                {
                    int n = number[i] * 2;
                    sum += (n / 10) + (n % 10);
                }
                else
                    sum += number[i];
            }
            return (sum % 10 == 0);

            /*
             * [From http://en.wikipedia.org/wiki/Luhn_algorithm ]
             *
             *
             * The Luhn algorithm or Luhn formula, also known as the "modulus 10" or
             * "mod 10" algorithm, is a simple checksum formula used to validate a
             * variety of identification numbers, such as credit card numbers and
             * Canadian Social Insurance Numbers. It was created by IBM scientist
             * Hans Peter Luhn and described in US Patent 2,950,048, filed on
             * January 6, 1954 and granted on August 23, 1960.
             *
             * The algorithm is in the public domain and is in wide use today. It is
             * not intended to be a cryptographically secure hash function; it was
             * designed to protect against accidental errors, not malicious attacks.
             * Most credit cards and many government identification numbers use the
             * algorithm as a simple method of distinguishing valid numbers from
             * collections of random digits.
             *
             */
        }