Beispiel #1
0
        public async Task <ActionResult> IndividualOnlineResponse(string InvoiceId)
        {
            DomesticInvoicePaymentManager Mgr; bool offline;

            if (Request.IsAuthenticated && User.Identity.IsAuthenticated)
            {
                offline = false;
                Mgr     = new DomesticInvoicePaymentManager(Lang, UserManager.FindById(User.Identity.GetUserId()));
            }
            else
            {
                offline = true;
                Mgr     = new OfflineDomesticInvoicePaymentManager(Lang);
            }
            ViewBag.Offline = offline;

            DomesticInvoice invoice = await Mgr.GetDomesticInvoice(InvoiceId);


            var paymentResponse = Mgr.GetPaymentResponse(Request.QueryString["id"].ToString());

            if (paymentResponse.Status == HyperPayStatus.Success)
            {
                // Add Succeed Transaction to LaborServices Db
                var transaction = Mgr.AddSuccessTransaction(invoice.CustomerId, invoice.Number, InvoiceId, invoice.InvoiceAmount.Value, paymentResponse);

                // Add reciept voucher & Update Invoice IsPaid Field
                var response = await Mgr.CreateReceiptVoucher(invoice);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    // success CRM voucher creation
                    transaction.IsVoucherSaved = true;
                    Mgr.UpdatePaymentTransaction(transaction);
                }
                else
                {
                    // fail CRM voucher creation
                    Mgr.SaveFailedReceiptVoucher(response.Result, transaction.Id);
                }
                // return success msg
                return(View("Success", IndividualSuccessOnlinePayment(InvoiceId, offline)));
            }
            else
            {
                // Add Failed Transaction to LaborServices Db
                Mgr.AddFailTransaction(invoice.CustomerId, invoice.Number, InvoiceId, invoice.InvoiceAmount.Value, paymentResponse);

                // return fail msg
                return(View("Failure", PaymentFailureMsg(InvoiceId, paymentResponse.Reason,
                                                         Url.Action("IndividualOnlinePayment", "Pay", new { id = InvoiceId, lang = LangCode }))));
            }
        }