public async Task <string> InsertPaymentCards(PaymentCardsDto PaymentCardsDto) { try { await Repository.InsertAsync(new PaymentCards { CardCustomerId = PaymentCardsDto.CardCustomerId, CardSourceId = PaymentCardsDto.CardSourceId, last4digits = PaymentCardsDto.last4digits, CardType = PaymentCardsDto.CardType, Expyear = PaymentCardsDto.Expyear, Expmonth = PaymentCardsDto.Expmonth, CustomerId = PaymentCardsDto.CustomerId, }); return("Card inserted successfully"); } catch (Exception err) { return(err.Message); } }
// [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 })); } }
private void StoreCard(PaymentCardsDto paymentCardsDto) { }