public async Task <IActionResult> InsertWalletHistory([FromBody] WalletHistoryDto walletHistoryDto) { try { if (walletHistoryDto.isExistingCard.Value) { Checkout.Payments.PaymentResponse paymentResponse = walletHistoryDto.PaymentResponseSource; walletHistoryDto.Transaction = paymentResponse.Payment.Id; walletHistoryDto.TransactionDescription = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme + "****" + ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4; } else { if (walletHistoryDto.SourceId != null) { Checkout.Payments.GetPaymentResponse payment = walletHistoryDto.SourceId; if (walletHistoryDto.SaveCard) { var customerID = await _UsersService.getCustomerID(walletHistoryDto.CustomerID); List <GetPaymentCardsDto> paymentCards = _paymentCardsService.GetPaymentByCustomer(walletHistoryDto.CustomerID); var itemExists = paymentCards.Find(p => p.CardType == ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme && p.Expyear == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear) && p.Expmonth == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth) && p.last4digits == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4) ); if (itemExists == null) { await _paymentCardsService.InsertPaymentCards( new PaymentCardsDto { CardCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id, CardSourceId = ((Checkout.Payments.CardSourceResponse)payment.Source).Id, CardType = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme, CustomerId = customerID, Expyear = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear), Expmonth = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth), last4digits = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4) } ); } } walletHistoryDto.Transaction = payment.Id; walletHistoryDto.TransactionDescription = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme + "****" + ((Checkout.Payments.CardSourceResponse)payment.Source).Last4; } } await _WalletHistoryService.InsertWalletHistory(walletHistoryDto); } catch (Exception err) { return(BadRequest(new GenericResultDto <string> { Result = err.Message })); } return(Ok(new GenericResultDto <string> { Result = "Insert successfully" })); }
private async Task ShouldIncrementPaymentAuthorization_Idempotently() { PaymentResponse paymentResponse = await MakeAuthorizationEstimatedPayment(); AuthorizationRequest authorizationRequest = new AuthorizationRequest { Amount = 10, Reference = "payment_reference" }; AuthorizationResponse authorizationResponse1 = await DefaultApi.PaymentsClient() .IncrementPaymentAuthorization(paymentResponse.Id, authorizationRequest, "idempotency_key"); authorizationResponse1.ShouldNotBeNull(); AuthorizationResponse authorizationResponse2 = await DefaultApi.PaymentsClient() .IncrementPaymentAuthorization(paymentResponse.Id, authorizationRequest, "idempotency_key"); authorizationResponse2.ShouldNotBeNull(); authorizationResponse1.ActionId.ShouldBe(authorizationResponse2.ActionId); }
private async Task ShouldRequestPayment() { var paymentRequest = new PaymentRequest { Source = new RequestProviderTokenSource { Token = "token", PaymentMethod = "method", AccountHolder = new AccountHolder() } }; var paymentResponse = new PaymentResponse(); _apiClient.Setup(apiClient => apiClient.Post <PaymentResponse>(PaymentsPath, _authorization, paymentRequest, CancellationToken.None, null)) .ReturnsAsync(() => paymentResponse); IPaymentsClient paymentsClient = new PaymentsClient(_apiClient.Object, _configuration.Object); var response = await paymentsClient.RequestPayment(paymentRequest, null, CancellationToken.None); response.ShouldNotBeNull(); response.ShouldBeSameAs(paymentResponse); }
private async Task ShouldRequestPayment_CustomSource() { var paymentRequest = new PaymentRequest { Customer = new CustomerRequest { Phone = new Phone() }, Processing = new ProcessingSettings { TaxAmount = 500, ShippingAmount = 1000, }, Source = new RequestTamaraSource { BillingAddress = new Address { AddressLine1 = "Cecilia Chapman", AddressLine2 = "711-2880 Nulla St.", City = "Mankato", State = "Mississippi", Zip = "96522", Country = CountryCode.SA } }, Items = new List <Product> { new Product { Name = "Item name", Quantity = 3, UnitPrice = 100, TotalAmount = 100, TaxAmount = 19, DiscountAmount = 2, Reference = "some description about item", ImageUrl = "https://some_s3bucket.com", Url = "https://some.website.com/item", Sku = "123687000111" } } }; var paymentResponse = new PaymentResponse { Customer = new CustomerResponse { Id = "id", Email = "email", Name = "name", Phone = new Phone() }, Processing = new PaymentProcessing { PartnerPaymentId = "123456" } }; _apiClient.Setup(apiClient => apiClient.Post <PaymentResponse>(PaymentsPath, _authorization, paymentRequest, CancellationToken.None, null)) .ReturnsAsync(() => paymentResponse); IPaymentsClient paymentsClient = new PaymentsClient(_apiClient.Object, _configuration.Object); var response = await paymentsClient.RequestPayment(paymentRequest, null, CancellationToken.None); response.ShouldNotBeNull(); response.ShouldBeSameAs(paymentResponse); response.Customer.ShouldNotBeNull(); response.Customer.Phone.ShouldNotBeNull(); }
// [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 })); } }