Example #1
0
        /// <summary>
        /// All payment requests are processed and persisted. Bank Service mock respondes with the current  payment status
        /// </summary>
        /// <param name="paymentRequest">The requested payment as <see cref="PaymentRequest"/>.</param>
        /// <returns>The result of the payment processing as <see cref="PaymentResponse"/>.</returns>
        public async Task <PaymentResponse> ProcessPaymentAsync(
            PaymentRequest paymentRequest, CancellationToken cancellationToken)
        {
            PaymentAuthorizationResponse paymentAuthorizationResponse = null;
            var paymentAuthorizationRequest = new PaymentAuthorizationRequest(
                paymentRequest.CardNumber,
                paymentRequest.Expiry,
                paymentRequest.Amount,
                paymentRequest.Cvv,
                paymentRequest.Currency
                );

            paymentAuthorizationResponse = _bankService.AuthorizePayment(paymentAuthorizationRequest);

            var payment = new Core.Entities.Payment()
            {
                CardNumber    = MaskCardNumber(paymentRequest.CardNumber),
                Cvv           = paymentRequest.Cvv,
                Expiry        = paymentRequest.Expiry,
                Currency      = paymentRequest.Currency,
                Amount        = paymentRequest.Amount,
                SuccessStatus = paymentAuthorizationResponse.SuccessStatus
            };

            await _paymentRepository.AddAsync(payment, cancellationToken);

            return(new PaymentResponse(payment.Id, payment.SuccessStatus));
        }
Example #2
0
        /// <summary>
        /// Simulates a payment authorization, invalid expiry or card number or a payment does not match the payment policy returns false as status
        /// </summary>
        /// <param name="paymentAuthorizationRequest"></param>
        /// <returns>Indicating the current payment authorization response in <see cref="PaymentAuthorizationResponse"/>.</returns>
        public PaymentAuthorizationResponse AuthorizePayment(
            PaymentAuthorizationRequest paymentAuthorizationRequest)
        {
            // Check payment based on the payment policy
            if (_paymentPolicy.MaxAllowedAmount < paymentAuthorizationRequest.Amount ||
                _paymentPolicy.MinAllowedAmount > paymentAuthorizationRequest.Amount ||
                _paymentPolicy.AllowedCurrencies.Count(c => c.Code == paymentAuthorizationRequest.Currency) == 0 ||
                !ExpiryValidator.Validate(paymentAuthorizationRequest.Expiry) ||
                !CardNumberValidator.Validate(paymentAuthorizationRequest.CardNumber))
            {
                return(new PaymentAuthorizationResponse(Guid.NewGuid(), false));
            }

            return(new PaymentAuthorizationResponse(Guid.NewGuid(), true));
        }
Example #3
0
        public ActionResult Authorize(PaymentAuthorizationRequest request)
        {
            var payment = _paymentService.GetPaymentById(request.Id);

            if (payment == null)
            {
                return(Json("Failed:Payment not found to authorized!!", JsonRequestBehavior.AllowGet));
            }
            decimal?credit;

            //credit
            foreach (var details in payment.PaymentDetails)
            {
                var item = new LedgerPosting();
                item.LedgerId      = details.LedgerId;
                item.CreatedBy     = CurrentSession.GetCurrentSession().UserId;
                item.Credit        = 0;
                item.Debit         = request.Amount;
                item.InvoiceNo     = payment.InvoiceNo;
                item.VoucherNo     = payment.VoucherNo;
                item.PostingDate   = payment.LedgerDate;
                item.ChequeDate    = details.ChequeDate;
                item.ChequeNo      = details.ChequeNo;
                item.VoucherTypeId = payment.VoucherTypeId;
                item.Extra1        = "Voucher:" + payment.VoucherNo + " " + payment.Narration + "|" + request.Notes;
                postingService.Save(item);
                break;
            }
            //debit
            LedgerPosting posting = new LedgerPosting();

            posting.ChequeDate    = DateTime.Now;
            posting.VoucherNo     = payment.VoucherNo;
            posting.ChequeNo      = "";
            posting.VoucherTypeId = (int)BAL.VoucherTypeEnum.PaymentVoucher;
            posting.LedgerId      = payment.LedgerId;
            posting.PostingDate   = payment.LedgerDate;
            posting.Credit        = request.Amount;
            posting.Debit         = 0;
            posting.Extra1        = "Voucher:" + payment.VoucherNo + " " + request.Notes;
            postingService.Save(posting);
            //balance
            //party balance
            PartyBalance balance = new PartyBalance();

            balance.AgainstVoucherTypeId = 4;
            balance.VoucherNo            = payment.VoucherNo;
            balance.PostingDate          = payment.LedgerDate;
            balance.LedgerId             = payment.LedgerId ?? 0;
            balance.Debit         = request.Amount;
            balance.Credit        = 0;
            balance.VoucherTypeId = (int)BAL.VoucherTypeEnum.PaymentVoucher;
            balance.extra1        = "Payment Invoice: " + payment.VoucherNo + " Notes:" + request.Notes;
            balance.extra2        = posting.Id.ToString();

            partyBalanceService.Save(balance);

            //isSendSMS = false;
            //if (isSendSMS)
            //{
            //    SMSEmailService sMSEmailService = new SMSEmailService();
            //    string phone = supplierInfo.Phone;
            //    rptIndividualLedger_Result due = customerService.GetBalance((supplierInfo.LedgerId ?? 0));

            //    string balanceText = "";
            //    credit = due.Balance;
            //    var num = new decimal();
            //    if ((credit.GetValueOrDefault() < num ? !credit.HasValue : true))
            //    {
            //        credit = due.Balance;
            //        balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/=.");
            //    }
            //    else
            //    {
            //        decimal minusOne = decimal.MinusOne;
            //        credit = due.Balance;
            //        balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", minusOne * decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/= Thanks.");
            //    }
            //    balanceText = "";
            //    string[] name = new string[] { "Dear ", supplierInfo.Name, " Tk=", null, null, null };
            //    credit = balance.Credit;
            //    name[3] = string.Format("{0:#,#.}", decimal.Round((posting.Credit.HasValue ? posting.Credit.GetValueOrDefault() : decimal.Zero)), "");
            //    name[4] = "/- has been Deposited to your Account. Ref:No-" + voucherNo + ", Dated:" + voucherDate.ToString("dd-MM-yyyy") + ". Thanks with Dada Rice";
            //    sMSEmailService.SendOneToOneSingleSms("01979110321", string.Concat(string.Concat(name), balanceText), false);
            //}
            //updated au authorized
            payment.ApprovedBy    = DateTime.Now;
            payment.ApprovedNotes = request.Notes;
            payment.IsApproved    = true;
            _paymentService.Update(payment, payment.Id);
            foreach (var item in payment.PaymentDetails)
            {
                payment.ApprovedBy    = DateTime.Now;
                payment.ApprovedNotes = request.Notes;
                payment.IsApproved    = true;
                _paymentService.Update(item, item.Id);
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }