예제 #1
0
        public List <GetPaymentCardsDto> GetPaymentByCustomer(string CustomerID)
        {
            var getPaymentCardslist = (from s in this.Repository.Where(m => m.CustomerRegistration.Users.GUID == CustomerID)
                                       select new
            {
                s.Id,
                //  s.CustomerId,
                //  s.CardCustomerId,
                //  s.CardSourceId,
                s.last4digits,
                s.CardType,
                s.Expyear,
                s.Expmonth,
            }).Distinct().ToList();

            List <GetPaymentCardsDto> PaymentCardslist = new List <GetPaymentCardsDto>();

            foreach (var Paymentlist in getPaymentCardslist)
            {
                GetPaymentCardsDto PaymentCard = new GetPaymentCardsDto();
                PaymentCard.paymentcardId = Paymentlist.Id;
                //   PaymentCard.CustomerId = Paymentlist.CustomerId;
                //  PaymentCard.CardCustomerId = Paymentlist.CardCustomerId;
                //  PaymentCard.CardSourceId = Paymentlist.CardSourceId;
                PaymentCard.last4digits = Paymentlist.last4digits;
                PaymentCard.CardType    = Paymentlist.CardType;
                PaymentCard.Expmonth    = Paymentlist.Expmonth;
                PaymentCard.Expyear     = Paymentlist.Expyear;
                PaymentCardslist.Add(PaymentCard);
            }
            return(PaymentCardslist);
        }
예제 #2
0
        public GetPaymentCardsDto GetPaymentCardInfo(int paymentCardId)
        {
            PaymentCards paymentCard = Repository.Where(c => c.Id == paymentCardId).FirstOrDefault();

            GetPaymentCardsDto paymentCardDto = new GetPaymentCardsDto();

            paymentCardDto.paymentcardId  = paymentCard.Id;
            paymentCardDto.CustomerId     = paymentCard.CustomerId;
            paymentCardDto.CardCustomerId = paymentCard.CardCustomerId;
            paymentCardDto.CardSourceId   = paymentCard.CardSourceId;
            paymentCardDto.last4digits    = paymentCard.last4digits;
            paymentCardDto.CardType       = paymentCard.CardType;
            paymentCardDto.Expmonth       = paymentCard.Expmonth;
            paymentCardDto.Expyear        = paymentCard.Expyear;

            return(paymentCardDto);
        }
        //  [ValidateAntiForgeryToken]
        public async Task <IActionResult> PostPayment(PaymentModel model)
        {
            try
            {
                var  user   = _usersService.GetUser(model.CustomerId).Result;
                bool isMada = false;
                #region Check for Mada

                CardBinHelper  cardBinHelper = new CardBinHelper();
                IList <string> binValues     = new List <string>();
                binValues = cardBinHelper.GetMadaCardBins();

                var isFound = binValues.Where(b => b == model.CardBin).FirstOrDefault();
                if (isFound != null)
                {
                    isMada = true;
                }

                #endregion
                #region Source - user existing card

                if (model.isExistingCard.Value)
                {
                    if (string.IsNullOrWhiteSpace(model.CVV))
                    {
                        return(Ok(new GenericResultDto <string> {
                            Result = "Please enter cvv"
                        }));
                    }
                    GetPaymentCardsDto paymentCardsDto = _paymentCardsService.GetPaymentCardInfo(model.PaymentCardId.Value);

                    var source = new SourceInfo(paymentCardsDto.CardSourceId, model.CVV);

                    var sourceRequest = new PaymentRequest <SourceInfo>(source, model.Currency, Convert.ToInt32(model.Amount))
                    {
                        Capture   = model.Capture,
                        Reference = model.Reference,
                        ThreeDS   = false,//model.DoThreeDS,
                        Customer  = new Checkout.Payments.CustomerRequest
                        {
                            Email = user.Username,
                            Id    = paymentCardsDto.CardCustomerId,
                            Name  = user.CustomerRegistration.FirstName + " " + user.CustomerRegistration.LastName
                        }
                    };
                    var sourceResponse = await _checkoutApi.Payments.RequestAsync(sourceRequest);

                    //if (sourceResponse.Payment.Approved)
                    //{
                    //    await _walletHistoryService.InsertWalletHistory(new WalletHistoryDto
                    //    {
                    //        CustomerID = model.CustomerId,
                    //        Status = 1,
                    //        Transaction = model.Currency,
                    //        TransactionAmount = model.Amount,
                    //        TransactionDate = System.DateTime.Now,
                    //        TransactionDescription = model.Reference,
                    //        Type = "CC"

                    //    });
                    //}
                    if (!string.IsNullOrEmpty(sourceResponse.Payment.ResponseCode))
                    {
                        sourceResponse.Payment.ResponseSummary = new PaymentStatusCodes().GetPaymentStatus(sourceResponse.Payment.ResponseCode);
                    }

                    return(Ok(sourceResponse));
                }
                #endregion

                else
                {
                    if (string.IsNullOrWhiteSpace(model.CardToken))
                    {
                        throw new ArgumentException("Model", $"{nameof(model.CardToken)} is missing.");
                    }

                    var tokenSource = new TokenSource(model.CardToken);
                    var metaData    = new Dictionary <string, object>();
                    metaData.Add("udf1", "mada");
                    var paymentRequest = new PaymentRequest <TokenSource>(tokenSource, model.Currency, Convert.ToInt32(model.Amount))
                    {
                        // Capture = model.Capture,
                        Reference = model.Reference,
                        ThreeDS   = new ThreeDSRequest {
                            Enabled = model.DoThreeDS, AttemptN3D = true
                        },
                        Customer = new Checkout.Payments.CustomerRequest
                        {
                            Email = user.Username,
                            //   Id = user.GUID,
                            Name = user.CustomerRegistration.FirstName + " " + user.CustomerRegistration.LastName
                        }
                    };
                    if (isMada)
                    {
                        paymentRequest.Metadata = metaData;
                    }
                    var response = await _checkoutApi.Payments.RequestAsync(paymentRequest);

                    if (model.SaveCard)
                    {
                        PaymentCardsDto paymentCardsDto = new PaymentCardsDto();
                        StoreCard(paymentCardsDto);
                    }
                    if (response.IsPending && response.Pending.RequiresRedirect())
                    {
                        //await _walletHistoryService.InsertWalletHistory(new WalletHistoryDto
                        //{
                        //    CustomerID = model.CustomerId,
                        //    Status = 1,
                        //    Transaction = model.Currency,
                        //    TransactionAmount = model.Amount,
                        //    TransactionDate = System.DateTime.Now,
                        //    TransactionDescription = model.Reference,
                        //    Type = "CC"

                        //});
                        return(Ok(response));
                    }



                    //if (response.Payment.Approved)
                    //{
                    //    await _walletHistoryService.InsertWalletHistory(new WalletHistoryDto
                    //    {
                    //        CustomerID = model.CustomerId,
                    //        Status = 1,
                    //        Transaction = model.Currency,
                    //        TransactionAmount = model.Amount,
                    //        TransactionDate = System.DateTime.Now,
                    //        TransactionDescription = model.Reference,
                    //        Type = "CC"

                    //    });

                    //}
                    return(Ok(response));
                }
            }
            catch (CheckoutValidationException validateEx)
            {
                Checkout.Payments.PaymentResponse response = new Checkout.Payments.PaymentResponse();
                response.Payment = null;
                return(Ok(new PaymentResultDto <Checkout.Payments.PaymentResponse> {
                    Result = response,
                    Message = validateEx.Message + "Invalid CVV"
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new GenericResultDto <string> {
                    Result = ex.Message
                }));
            }
        }