public async Task <CreditResult> Apply(CreditApplyRequest request)
        {
            var score = await _creditScoreService.GetScore(request.IdentificationNumber);

            var creditParameters = new CreditParameters
            {
                Salary = request.Salary,
                Score  = score
            };

            var limit = _limitCalculator.Calculate(creditParameters);

            if (limit <= 0)
            {
                return(CreditResult.Fail());
            }

            var credit = new Credit
            {
                IdentificationNumber = request.IdentificationNumber,
                Name            = request.Name,
                Surname         = request.Surname,
                Salary          = request.Salary,
                TelephoneNumber = request.TelephoneNumber,
                CreditLimit     = limit
            };

            await _creditRepository.InsertAsync(credit);

            return(CreditResult.Success(limit));
        }
        public CreditResult GetCredit()
        {
            var _getCreditResult = new CreditResult();
            #region Get Account Credit
            try
            {
                var _userCredit = new getUserCredit(_userCredential);
                getUserCreditResponse _getUserCreditResponse = _webService.getUserCredit(_userCredit);

                if ([email protected] == 0)
                {
                    _getCreditResult.Status = SmsSendStatus.Success;
                    _getCreditResult.Number = [email protected];
                    _getCreditResult.ResultMessage = "Success";
                }
                else
                {
                    _getCreditResult.Status = SmsSendStatus.Error;
                    _getCreditResult.Number = 0;
                    _getCreditResult.ResultMessage = "Error : " + [email protected];
                }

                return _getCreditResult;
            }
            catch (Exception ex)
            {
                _getCreditResult.Status = SmsSendStatus.Error;
                _getCreditResult.Number = 0;
                _getCreditResult.ResultMessage = "Exception : " + ex.Message;

                return _getCreditResult;
            }
            #endregion
        }
        public async Task <IActionResult> CreditApplicationPOST()
        {
            if (ModelState.IsValid)
            {
                var(validationPassed, errorMessages) = await _creditValidator.PassAllValidations(CreditModel);

                CreditResult creditResult = new CreditResult()
                {
                    ErrorList = errorMessages,
                    CreditID  = 0,
                    Success   = validationPassed
                };
                if (validationPassed)
                {
                    //Add record to database;;
                    return(RedirectToAction(nameof(CreditResult), creditResult));
                }
                else
                {
                    return(RedirectToAction(nameof(CreditResult), creditResult));
                    //return RedirectToAction(nameof(CreditResult), creditResult);
                    //nameof expression prodcuce the name of a varibale,type or member as the stirng constant.
                }
            }
            return(View(CreditModel));
        }
Esempio n. 4
0
        public IActionResult CreditApplicationPOST([FromServices] Func <CreditApprovedEnum, ICreditApproved> creditService)
        {
            if (ModelState.IsValid)
            {
                var(validationPassed, errorMessages) = _creditValidator.PassAllValidations(CreditApplication);
                var creditResult = new CreditResult
                {
                    ErrorList = errorMessages,
                    CreditID  = 0,
                    Success   = validationPassed
                };

                if (validationPassed)
                {
                    var creditApprovedEnum = CreditApplication.Salary > 50000 ? CreditApprovedEnum.High : CreditApprovedEnum.Low;
                    CreditApplication.CreditApproved = creditService(creditApprovedEnum).GetCreditApproved(CreditApplication);

                    _unitOfWork.CreditApplicationRepository.Add(CreditApplication);
                    _unitOfWork.Save();
                    creditResult.CreditID       = CreditApplication.Id;
                    creditResult.CreditApproved = CreditApplication.CreditApproved;
                }
                return(RedirectToAction(nameof(CreditResult), creditResult));
            }
            return(View(CreditApplication));
        }
        public async Task <IActionResult> CreditApplicationPOST([FromServices] Func <CreditApprovedEnum, ICreditApproved> _creditService)
        {
            if (ModelState.IsValid)
            {
                var(validationPassed, errorMessages) = await _creditValidator.PassAllValidations(creditModel);

                CreditResult creditResult = new CreditResult()
                {
                    ErrorList = errorMessages,
                    CreditID  = 0,
                    Success   = validationPassed
                };

                if (validationPassed)
                {
                    creditModel.CreditApproved = _creditService(creditModel.Salary > 50000 ?CreditApprovedEnum.High : CreditApprovedEnum.Low).GetCreditApproved(creditModel);

                    _context.CreditApplication.Add(creditModel);
                    _context.SaveChanges();
                    creditResult.CreditID       = creditModel.Id;
                    creditResult.CreditApproved = creditModel.CreditApproved;

                    return(RedirectToAction(nameof(CreditResult), creditResult));
                }
                else
                {
                    return(RedirectToAction(nameof(CreditResult), creditResult));
                }
            }
            else
            {
                return(View(creditModel));
            }
        }
        public bool Credit(PaymentMethod currentPayment)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Crediting payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx Transaction Id from purchase order with ID: {0}", currentPayment.PurchaseOrder.Id);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            long         amount = payment.Amount.RoundToLong();
            CreditResult result = _paymentManager.Credit(transactionId, amount,
                                                         currentPayment.PurchaseOrder.TrackingNumber, currentPayment.Payment.Vat, string.Empty);

            bool success = false;

            if (result.Success && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during credit", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.TransactionID = result.TransactionNumber;
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully credited payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCreditor != null)
            {
                return(_paymentCreditor.Credit(currentPayment) && success);
            }
            return(success);
        }
        /// <summary>
        /// This method allows you make a refund. In this case a Refund button will be visible on the order details page in admin
        /// area. Note that an order should be paid, and SupportRefund or SupportPartiallyRefund property should return true.
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result = new RefundPaymentResult();

            Order order = refundPaymentRequest.Order;

            if (int.TryParse(order.CaptureTransactionId, out int transactionNumber))
            {
                decimal amount = Math.Round(refundPaymentRequest.AmountToRefund, 2);

                PayexInterface payex        = GetPayexInterface();
                CreditResult   creditResult = payex.Credit(transactionNumber, amount, order.OrderGuid.ToString())
                                              .GetAwaiter().GetResult();

                if (creditResult.IsRequestSuccessful)
                {
                    // NOTE: We should save the transaction id for the refund, but no field is available in order.
                    // Add order note
                    var note = new StringBuilder();
                    note.AppendLine("PayEx: Credit succeeded");
                    note.AppendLine(string.Format("Credited amount: {0:n2}", amount));
                    note.AppendLine("TransactionNumber: " + creditResult.TransactionNumber);
                    note.AppendLine("TransactionStatus: " + creditResult.TransactionStatus);
                    order.OrderNotes.Add(
                        new OrderNote
                    {
                        Note = note.ToString(),
                        DisplayToCustomer = false,
                        CreatedOnUtc      = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);
                    // Set new payment status
                    if (refundPaymentRequest.IsPartialRefund &&
                        refundPaymentRequest.AmountToRefund + order.RefundedAmount < order.OrderTotal)
                    {
                        result.NewPaymentStatus = PaymentStatus.PartiallyRefunded;
                    }
                    else
                    {
                        result.NewPaymentStatus = PaymentStatus.Refunded;
                    }
                }
                else
                {
                    result.AddError(creditResult.GetErrorDescription());
                }
            }
            else
            {
                result.AddError(
                    string.Format(
                        "The order did not contain a valid TransactionNumber in the AuthorizationTransactionId field ('{0}').",
                        order.AuthorizationTransactionId));
            }

            return(result);
        }
Esempio n. 8
0
        internal void Success_ReturnsCorrectResult(TransactionStatus transactionStatus, bool statusSuccess, bool expected)
        {
            Status status = Factory.CreateStatus(statusSuccess);

            CreditResult creditResult = new CreditResult {
                Status = status, TransactionStatus = transactionStatus
            };

            Assert.AreEqual(expected, creditResult.Success);
        }
Esempio n. 9
0
        public static CreditResult ParseCreditResult(string xmlText)
        {
            var result = new CreditResult {
                RawXml = xmlText
            };
            var root = result.GetRootElement();

            ParseTransactionResult(result, root);
            return(result);
        }
        public async Task Apply_WhenLimitIsZero_ShouldReturnFail()
        {
            //Arrange
            var creditApplyRequest = _fixture.Build <CreditApplyRequest>().Create();

            _mockCreditScoreService.Setup(x => x.GetScore(creditApplyRequest.IdentificationNumber)).Returns(Task.FromResult <long>(2));
            _mockLimitCalculator.Setup(x => x.Calculate(It.IsAny <CreditParameters>())).Returns(0);
            //Act
            var result = await _sut.Apply(creditApplyRequest);

            //Verify
            result.Should().BeEquivalentTo(CreditResult.Fail());
        }
        public async Task Apply_WhenCreditResultIsApplied_ShouldReturnOkRequest()
        {
            // Arrange
            var creditResult = CreditResult.Success(It.IsAny <decimal>());

            _mockCreditService.Setup(x => x.Apply(It.IsAny <CreditApplyRequest>())).Returns(Task.FromResult(creditResult));

            // Act
            var result = await _sut.Apply(It.IsAny <CreditApplyRequest>());

            //Verify
            result.Should().BeOfType <OkObjectResult>();
        }
Esempio n. 12
0
        public CreditResult EvaluateCredit(CreditInput creditInput)
        {
            ICredit credit = creditFactory.Create(creditInput.CreditType,
                                                  creditInput.Value,
                                                  creditInput.QtdInstallments,
                                                  creditInput.FirstDueDate);


            CreditResult result = new CreditResult(credit.IsApproved,
                                                   credit.TotalValue,
                                                   credit.InterestValue);


            return(result);
        }
        public bool Credit(PaymentMethod currentPayment)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Crediting payment with ID:{0} belonging to order with ID: {1}, by order lines", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx Transaction Id from purchase order with ID: {0}", currentPayment.PurchaseOrder.Id);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            CreditResult result      = null;
            string       orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber);

            foreach (OrderForm orderForm in currentPayment.PurchaseOrder.OrderForms)
            {
                foreach (LineItem lineItem in orderForm.LineItems)
                {
                    result = _paymentManager.CreditOrderLine(transactionId, lineItem.CatalogEntryId, orderNumber);
                }
            }

            bool success = false;

            if (result != null && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during credit", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.TransactionID = result.TransactionNumber;
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully credited payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCreditor != null)
            {
                return(_paymentCreditor.Credit(currentPayment) && success);
            }
            return(success);
        }
Esempio n. 14
0
        public void CreditWithCardDataAndTransactionInfo()
        {
            //arrange
            var    sixMonthsFromNowDate = DateTime.Now.AddMonths(6);
            var    shopOrderId          = Guid.NewGuid().ToString();
            Double amount   = 100.23;
            var    currency = Currency.DKK;

            IDictionary <string, object> TransactionInfo = new Dictionary <string, object>();

            TransactionInfo.Add("sdkName", "sdk-csharp");
            TransactionInfo.Add("sdkVersion", "1.1.5");

            var request = new CreditRequest
            {
                Terminal       = _testTerminal,
                ShopOrderId    = shopOrderId,
                Amount         = Amount.Get(amount, currency),
                Pan            = "4111000011110087",
                ExpiryMonth    = sixMonthsFromNowDate.Month,
                ExpiryYear     = sixMonthsFromNowDate.Year,
                Cvc            = "123",
                PaymentSource  = PaymentSource.eCommerce,
                CardHolderName = "Test CardHolder Name",
                PaymentInfos   = TransactionInfo
            };

            //act
            CreditResult result = _api.Credit(request);

            //assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Result);
            Assert.IsNotNull(result.Payment);

            Assert.AreEqual(result.Result, Result.Success);
            Assert.AreEqual(result.Payment.TransactionStatus, GatewayConstants.CreditedTransactionStatus);
            Assert.AreEqual(result.Payment.ShopOrderId, shopOrderId);
            //TODO:
            //Assert.AreEqual(result.Payment.ReservedAmount, 0d);
            Assert.AreEqual(result.Payment.MerchantCurrencyAlpha, currency.ShortName);
        }
Esempio n. 15
0
        public CreditResult CreditOrderLine(int transactionNumber, string itemNumber, string orderId)
        {
            Log.InfoFormat("Calling CreditOrderLine for TransactionNumber:{0}. ItemNumber:{1}. OrderId:{2}.",
                           transactionNumber, itemNumber, orderId);

            string hash      = _hasher.Create(_payExSettings.AccountNumber, transactionNumber, itemNumber, orderId, _payExSettings.EncryptionKey);
            string xmlResult = _orderFacade.CreditOrderLine(_payExSettings.AccountNumber, transactionNumber, itemNumber, orderId, hash);

            CreditResult result = _resultParser.Deserialize <CreditResult>(xmlResult);

            if (result.Success)
            {
                Log.InfoFormat("Successfully called CreditOrderLine for TransactionNumber:{0}. ItemNumber:{1}. OrderId:{2}.",
                               transactionNumber, itemNumber, orderId);
            }
            else
            {
                Log.ErrorFormat("Error when calling CreditOrderLine for TransactionNumber:{0}. ItemNumber:{1}. OrderId:{2}.",
                                transactionNumber, itemNumber, orderId);
            }
            return(result);
        }
Esempio n. 16
0
        public CreditResult Credit(int transactionNumber, long amount, string orderId, int vatAmount, string additionalValues)
        {
            Log.InfoFormat("Calling Credit for TransactionNumber:{0}. Amount:{1}. OrderId:{2}. VatAmount:{3}. AdditionalValues:{4}",
                           transactionNumber, amount, orderId, vatAmount, additionalValues);

            string hash      = _hasher.Create(_payExSettings.AccountNumber, transactionNumber, amount, orderId, vatAmount, additionalValues, _payExSettings.EncryptionKey);
            string xmlResult = _orderFacade.Credit(_payExSettings.AccountNumber, transactionNumber, amount, orderId, vatAmount,
                                                   additionalValues, hash);

            CreditResult result = _resultParser.Deserialize <CreditResult>(xmlResult);

            if (result.Success)
            {
                Log.InfoFormat("Successfully called Credit for TransactionNumber:{0}. Amount:{1}. OrderId:{2}. VatAmount:{3}. AdditionalValues:{4}. Result:{5}",
                               transactionNumber, amount, orderId, vatAmount, additionalValues, xmlResult);
            }
            else
            {
                Log.ErrorFormat("Error when calling Credit for TransactionNumber:{0}. Amount:{1}. OrderId:{2}. VatAmount:{3}. AdditionalValues:{4}. Result:{5}",
                                transactionNumber, amount, orderId, vatAmount, additionalValues, xmlResult);
            }
            return(result);
        }
Esempio n. 17
0
 public IActionResult CreditResult(CreditResult creditResult)
 {
     return(View(creditResult));
 }