Ejemplo n.º 1
0
 public FundingModel(FundingObject funding)
 {
     if (funding != null)
     {
         SortMainId              = funding.SortMainId;
         FundingId               = funding.FundingId;
         FundingTypeId           = funding.FundingTypeId;
         Year                    = funding.Year;
         Percent                 = funding.Percent;
         ContractNumber          = funding.ContractNumber;
         Org                     = funding.Org;
         ProjectArea             = funding.ProjectArea;
         DoeFundingCategoryId    = funding.DoeFundingCategoryId;
         GrantNumber             = funding.GrantNumber;
         TrackingNumber          = funding.TrackingNumber;
         ProjectNumber           = funding.ProjectNumber;
         PrincipalInvEmployeeId  = funding.PrincipalInvEmployeeId;
         SppCategoryId           = funding.SppCategoryId;
         FederalAgencyId         = funding.FederalAgencyId;
         OtherDescription        = funding.OtherDescription;
         CountryId               = funding.CountryId;
         AdditionalInfo          = funding.AdditionalInfo;
         SppApproved             = funding.SppApproved ?? false;
         ApproveNoReason         = funding.ApproveNoReason;
         MilestoneTrackingNumber = funding.MilestoneTrackingNumber;
         Funding                 = FundingObject.GetFundings(SortMainId);
     }
 }
Ejemplo n.º 2
0
        public void Save()
        {
            FundingObject o = new FundingObject();

            if (FundingId.HasValue && FundingId.Value > 0)
            {
                o = FundingObject.GetFunding(FundingId.Value);
            }

            o.SortMainId              = SortMainId;
            o.Year                    = Year;
            o.FundingTypeId           = FundingTypeId;
            o.ContractNumber          = ContractNumber;
            o.Percent                 = Percent.Replace("%", "").Trim();
            o.Org                     = Org;
            o.ProjectArea             = ProjectArea;
            o.DoeFundingCategoryId    = DoeFundingCategoryId;
            o.GrantNumber             = GrantNumber;
            o.TrackingNumber          = TrackingNumber;
            o.ProjectNumber           = ProjectNumber;
            o.PrincipalInvEmployeeId  = PrincipalInvEmployeeId;
            o.SppCategoryId           = SppCategoryId;
            o.FederalAgencyId         = FederalAgencyId;
            o.OtherDescription        = OtherDescription;
            o.CountryId               = CountryId;
            o.AdditionalInfo          = AdditionalInfo;
            o.SppApproved             = SppApproved;
            o.ApproveNoReason         = ApproveNoReason;
            o.MilestoneTrackingNumber = MilestoneTrackingNumber;
            o.Save();
        }
Ejemplo n.º 3
0
        public ActionResult GetFundingInfoPartial(int?id)
        {
            var model = new FundingObject();

            if (id.HasValue)
            {
                model = FundingObject.GetFunding(id.Value);
            }
            return(PartialView("Partials/_fundingInfo", model));
        }
Ejemplo n.º 4
0
        public ActionResult GetFundingInfoPartial(int?id)
        {
            if (!id.HasValue)
            {
                return(null);
            }

            var model = FundingObject.GetFunding(id.Value);

            return(PartialView("Partials/_fundingInfo", model));
        }
Ejemplo n.º 5
0
        [HttpPost]/*, ValidateAntiForgeryToken]*/
        public ActionResult AddFunding(FundingModel model)
        {
            if (ModelState.IsValid && MainObject.CheckUserHasWriteAccess(model.MainId))
            {
                model.Save();

                return(PartialView("Partials/_fundingList", FundingObject.GetFundings(model.MainId)));
            }

            return(null);
        }
Ejemplo n.º 6
0
        [HttpPost]/*, ValidateAntiForgeryToken]*/
        public ActionResult AddFunding(FundingModel model)
        {
            if (ModelState.IsValid && SortMainObject.CheckUserHasWriteAccess(model.SortMainId))
            {
                model.Save();

                return(PartialView("Partials/_fundingList", FundingObject.GetFundings(model.SortMainId)));
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(null);
        }
Ejemplo n.º 7
0
        public ActionResult GetFundingPartial(int?id)
        {
            if (id.HasValue)
            {
                var funding = FundingObject.GetFunding(id.Value);
                if (funding != null)
                {
                    return(PartialView("Partials/FundingPartial", new FundingModel(funding)));
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Refunds a payment that was previously captured (settled). You can expect partial refunds.
        /// </summary>
        /// <param name="refundPaymentRequest"></param>
        /// <returns></returns>
        public async Task <RefundPaymentResponse> RefundPayment(RefundPaymentRequest refundPaymentRequest, string publicKey, string privateKey)
        {
            bool isLive = !refundPaymentRequest.sandboxMode; // await this.GetIsLiveSetting();
            CreatePaymentRequest paymentRequest = await this._paymentRequestRepository.GetPaymentRequestAsync(refundPaymentRequest.paymentId);

            // Get Affirm id from storage
            refundPaymentRequest.authorizationId = paymentRequest.transactionId;

            int amount = decimal.ToInt32(refundPaymentRequest.value * 100);

            IAffirmAPI affirmAPI      = new AffirmAPI(_httpContextAccessor, _httpClient, isLive, _context);
            dynamic    affirmResponse = await affirmAPI.RefundAsync(publicKey, privateKey, refundPaymentRequest.authorizationId, amount);

            RefundPaymentResponse refundPaymentResponse = new RefundPaymentResponse
            {
                paymentId = refundPaymentRequest.paymentId,
                refundId  = affirmResponse.reference_id ?? affirmResponse.id,
                value     = affirmResponse.amount == null ? 0m : (decimal)affirmResponse.amount / 100m,
                code      = affirmResponse.type ?? affirmResponse.Error.Code,
                message   = affirmResponse.id != null ? $"Id:{affirmResponse.id} Fee={(affirmResponse.fee_refunded > 0 ? (decimal)affirmResponse.fee_refunded / 100m : 0):F2}" : affirmResponse.Error.Message,
                requestId = refundPaymentRequest.requestId
            };

            if (refundPaymentRequest.authorizationId.StartsWith(AffirmConstants.KatapultIdPrefix))
            {
                // Need to get details from Katapult
                VtexSettings vtexSettings = await _paymentRequestRepository.GetAppSettings();

                if (vtexSettings.enableKatapult)
                {
                    KatapultFunding katapultResponse = await affirmAPI.KatapultFundingAsync(vtexSettings.katapultPrivateToken);

                    if (katapultResponse != null)
                    {
                        FundingObject fundingObject = katapultResponse.FundingReport.FundingObjects.Where(f => f.OrderId.Equals(paymentRequest.orderId)).FirstOrDefault();
                        if (fundingObject != null)
                        {
                            refundPaymentResponse.message = $"Id:{affirmResponse.id} Fee={(fundingObject.Discount):F2}";
                            _context.Vtex.Logger.Info("RefundPayment", null, $"RefundPayment {refundPaymentResponse}");
                        }
                    }
                }
            }

            return(refundPaymentResponse);
        }
Ejemplo n.º 9
0
        public async Task FundingTestMethod()
        {
            string katapultPrivate = " ";
            string ordernumber     = "1033711204843";

            IAffirmAPI      affirmAPI        = new AffirmAPI(contextAccessor, httpClient, false, null);
            KatapultFunding katapultResponse = await affirmAPI.KatapultFundingAsync(katapultPrivate);

            if (katapultResponse != null)
            {
                FundingObject fundingObject = katapultResponse.FundingReport.FundingObjects.Where(f => f.OrderId.Equals(ordernumber)).FirstOrDefault();
                Console.WriteLine(JsonConvert.SerializeObject(fundingObject));
            }
            else
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 10
0
        public ActionResult RemoveFunding(int?id)
        {
            int mid = 0;

            if (id.HasValue)
            {
                var funding = FundingObject.GetFunding(id.Value);
                if (funding != null)
                {
                    mid = funding.MainId;
                    if (MainObject.CheckUserHasWriteAccess(mid))
                    {
                        funding.Delete();
                    }
                }
            }

            return(PartialView("Partials/_fundingList", FundingObject.GetFundings(mid)));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Captures (settle) a payment that was previously approved.
        /// </summary>
        /// <param name="capturePaymentRequest"></param>
        /// <returns></returns>
        public async Task <CapturePaymentResponse> CapturePayment(CapturePaymentRequest capturePaymentRequest, string publicKey, string privateKey)
        {
            bool isLive = !capturePaymentRequest.sandboxMode; // await this.GetIsLiveSetting();
            CapturePaymentResponse capturePaymentResponse = new CapturePaymentResponse
            {
                message = "Unknown Error."
            };

            // Load request from storage for order id
            CreatePaymentRequest paymentRequest = await this._paymentRequestRepository.GetPaymentRequestAsync(capturePaymentRequest.paymentId);

            if (paymentRequest == null)
            {
                capturePaymentResponse.message = "Could not load Payment Request.";
                _context.Vtex.Logger.Info("CapturePayment", null, $"{capturePaymentResponse.message}");
            }
            else
            {
                // Get Affirm id from storage
                capturePaymentRequest.authorizationId = paymentRequest.transactionId;

                if (string.IsNullOrEmpty(capturePaymentRequest.authorizationId))
                {
                    capturePaymentResponse.message = "Missing authorizationId.";
                }
                else
                {
                    IAffirmAPI affirmAPI = new AffirmAPI(_httpContextAccessor, _httpClient, isLive, _context);
                    try
                    {
                        dynamic affirmResponse = await affirmAPI.CaptureAsync(publicKey, privateKey, capturePaymentRequest.authorizationId, paymentRequest.orderId, capturePaymentRequest.value, capturePaymentRequest.transactionId);

                        if (affirmResponse == null)
                        {
                            capturePaymentResponse.message = "Null affirmResponse.";
                            _context.Vtex.Logger.Warn("CapturePaymentResponse", null, $"{capturePaymentResponse.message}");
                        }
                        else
                        {
                            // If "Already Captured" then fake a success response.
                            if (affirmResponse.type != null && affirmResponse.type == AffirmConstants.AlreadyCaptured)
                            {
                                capturePaymentResponse = new CapturePaymentResponse
                                {
                                    paymentId = capturePaymentRequest.paymentId,
                                    settleId  = affirmResponse.id ?? affirmResponse.type,
                                    value     = affirmResponse.amount == null ? capturePaymentRequest.value : (decimal)affirmResponse.amount / 100m,
                                    code      = affirmResponse.type ?? null,                                                                                                                                                   //affirmResponse.Error.Code,
                                    message   = affirmResponse.id != null ? $"Fee={((affirmResponse.fee != null && affirmResponse.fee > 0) ? (decimal)affirmResponse.fee / 100m : 0):F2}" : affirmResponse.message ?? "Error", //: affirmResponse.Error.Message,
                                    requestId = capturePaymentRequest.requestId
                                };
                            }
                            else
                            {
                                capturePaymentResponse = new CapturePaymentResponse
                                {
                                    paymentId = capturePaymentRequest.paymentId,
                                    settleId  = affirmResponse.id ?? null,
                                    value     = affirmResponse.amount == null ? 0m : (decimal)affirmResponse.amount / 100m,
                                    code      = affirmResponse.type ?? null,                                                                                                                                                   //affirmResponse.Error.Code,
                                    message   = affirmResponse.id != null ? $"Fee={((affirmResponse.fee != null && affirmResponse.fee > 0) ? (decimal)affirmResponse.fee / 100m : 0):F2}" : affirmResponse.message ?? "Error", //: affirmResponse.Error.Message,
                                    requestId = capturePaymentRequest.requestId
                                };
                            }

                            if (capturePaymentRequest.authorizationId.StartsWith(AffirmConstants.KatapultIdPrefix))
                            {
                                // Need to get details from Katapult
                                VtexSettings vtexSettings = await _paymentRequestRepository.GetAppSettings();

                                if (vtexSettings.enableKatapult)
                                {
                                    capturePaymentResponse.value = affirmResponse.amount == null ? capturePaymentRequest.value : (decimal)affirmResponse.amount / 100m;
                                    KatapultFunding katapultResponse = await affirmAPI.KatapultFundingAsync(vtexSettings.katapultPrivateToken);

                                    if (katapultResponse != null)
                                    {
                                        FundingObject fundingObject = katapultResponse.FundingReport.FundingObjects.Where(f => f.OrderId.Equals(paymentRequest.orderId)).FirstOrDefault();
                                        capturePaymentResponse.message = JsonConvert.SerializeObject(fundingObject);
                                        _context.Vtex.Logger.Info("CapturePayment", null, $"Katapult Funding Response  {capturePaymentResponse.message}");
                                    }
                                    else
                                    {
                                        _context.Vtex.Logger.Info("CapturePayment", null, $"Katapult Funding Response was null.  [{capturePaymentRequest.authorizationId}]");
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        _context.Vtex.Logger.Error("CapturePaymentAsync", null, $"CapturePaymentResponse:{ex.Message}", ex);
                        capturePaymentResponse.message = $"CapturePaymentAsync Error: {ex.Message}";
                    };
                }
            }

            return(capturePaymentResponse);
        }