示例#1
0
        public async Task<IHttpActionResult> ReturnFrom2CO()
        {
            ////string companyId = User.Identity.GetUserId();
            string companyId = HttpContext.Current.Request.Form["clientId"].ToString();
            var success = HttpContext.Current.Request.Form["credit_card_processed"].ToString();
            if (success.Equals("Y", StringComparison.InvariantCultureIgnoreCase))
            {
                var guid = Guid.NewGuid();
                bool result = this.paymentService.InsertPayPalTransaction(new PaypalPayTransactionModel
                {
                    CreatedOn = DateTime.UtcNow,
                    PaymentId = HttpContext.Current.Request.Form["order_number"].ToString(),
                    PayToken = guid,
                    IsPaymentDone = true,
                    ClientId = HttpContext.Current.Request.Form["li_0_product_id"].ToString(),
                    CompanyId = companyId,
                    Need = HttpContext.Current.Request.Form["li_0_name"].ToString(),
                    Amount = Convert.ToDecimal(HttpContext.Current.Request.Form["tPrice"]),
                    IsPaypalTransaction = false
                });

                if (result)
                {
                    PaypalPayTransactionModel paymentTransaction = this.paymentService.GetPaypalPaymentId(guid, true);
                    PaypalPaymentDetailsModel paymentDetail = new PaypalPaymentDetailsModel();
                    paymentDetail.TransactionId = paymentTransaction.Id;
                    paymentDetail.PayerId = "2COpayer";
                    paymentDetail.Email = HttpContext.Current.Request.Form["email"].ToString();
                    paymentDetail.FirstName = HttpContext.Current.Request.Form["card_holder_name"].ToString();
                    paymentDetail.Address = HttpContext.Current.Request.Form["ship_street_address"].ToString() + " " + HttpContext.Current.Request.Form["ship_street_address2"].ToString() + " " + HttpContext.Current.Request.Form["ship_state"].ToString() + " " + HttpContext.Current.Request.Form["ship_city"].ToString() + " " + HttpContext.Current.Request.Form["ship_zip"].ToString() + " " + HttpContext.Current.Request.Form["ship_country"].ToString();
                    paymentDetail.Status = "SUCCESS";
                    paymentDetail.IsComplete = true;
                    paymentDetail.CreatedOn = DateTime.UtcNow;
                    if (this.paymentService.CompletePaypalTransaction(paymentDetail))
                    {
                        try
                        {
                            bool isSuccess = true;

                            BuyUserModelDto buyUserModelDto = new BuyUserModelDto { CompanyId = paymentTransaction.CompanyId, UserId = paymentTransaction.ClientId, Interest = paymentTransaction.Need, Amount = paymentTransaction.Amount, PurchasedFromCash = false, PurchasedFromCredit = false };
                            isSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto);

                            ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Done"));
                            return this.Redirect(AppSettings.Get<string>("site_payment_url").ToString() + "?status=success");
                        }
                        catch (Exception ex)
                        {
                            this.LoggerService.LogException("PaymentController > ReturnFrom2CO(while updating system after successfull payment): " + ex.StackTrace);
                        }
                    }
                }
            }

            return this.Redirect(AppSettings.Get<string>("site_payment_url").ToString() + "?status=error");
        }
示例#2
0
        /// <summary>
        /// Finalize the paypal transaction
        /// </summary>
        /// <param name="model">model to finalize</param>
        /// <returns>bool object</returns>
        public bool CompletePaypalTransaction(PaypalPaymentDetailsModel model)
        {
            bool result = false;
            try
            {
                PaypalPaymentDetails table = this.mapperFactory.GetMapper<PaypalPaymentDetailsModel, PaypalPaymentDetails>().Map(model);
                this.paypalPayDetailsRepository.Insert(table);
                PaypalPayTransaction trans = this.paypalPayTransactionRepository.Find(p => p.Id.Equals(model.TransactionId)).FirstOrDefault();
                trans.IsPaymentDone = true;
                this.paypalPayTransactionRepository.Update(trans);
                this.paypalPayTransactionRepository.Commit();
                this.paypalPayDetailsRepository.Commit();
                result = true;
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("CompletePaypalTransaction :- " + ex.Message);
                result = false;                
            }

            return result;
        }
示例#3
0
        public async Task<IHttpActionResult> PaypalConfirmed(string token, string payerId, string id)
        {
            try
            {
                PaypalDetails paypalDetails = this.commonService.GetCache<PaypalDetails>(id);
                PaypalPayTransactionModel paymentTransaction = this.paymentService.GetPaypalPaymentId(Guid.Parse(id));
                if (paymentTransaction == null)
                {
                    return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), paypalDetails.Domain, "Invalid request"));
                }

                string paymentId = paymentTransaction.PaymentId;
                if (string.IsNullOrWhiteSpace(paymentId))
                {
                    return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), paypalDetails.Domain, "Can not proceed now, please try again."));
                }

                var paymentExecution = new PaymentExecution
                {
                    payer_id = payerId
                };

                var payment = new Payment { id = paymentId };
                var response = payment.Execute(this.Api, paymentExecution);
                if (response.state.ToLower() == "approved")
                {
                    PaypalPaymentDetailsModel paymentDetail = new PaypalPaymentDetailsModel();
                    paymentDetail.TransactionId = paymentTransaction.Id;
                    paymentDetail.PayerId = payerId;
                    paymentDetail.Email = response.payer.payer_info.email;
                    paymentDetail.FirstName = response.payer.payer_info.first_name;
                    paymentDetail.LastName = response.payer.payer_info.last_name;
                    paymentDetail.Address = response.payer.payer_info.shipping_address.line1 + " " + response.payer.payer_info.shipping_address.line2 + " " + response.payer.payer_info.shipping_address.state;
                    paymentDetail.Status = response.payer.status;
                    paymentDetail.IsComplete = true;
                    paymentDetail.CreatedOn = DateTime.UtcNow;
                    if (this.paymentService.CompletePaypalTransaction(paymentDetail))
                    {
                        try
                        {
                            bool isSuccess = true;
                            string crmContactId = this.youfferContactService.GetMappingEntryByContactId(paymentTransaction.ClientId).ContactCRMId;
                            string crmLeadId = this.youfferContactService.GetMappingEntryByContactId(paymentTransaction.ClientId).LeadId;
                            string crmOrgId = this.youfferContactService.GetOrgCRMId(paymentTransaction.CompanyId).CRMId;
                            LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId);

                            decimal price = AppSettings.Get<decimal>(ConfigConstants.UserPrice);
                            BuyUserModelDto buyUserModelDto = new BuyUserModelDto { CompanyId = paymentTransaction.CompanyId, UserId = paymentTransaction.ClientId, Interest = paymentTransaction.Need, Amount = price, PurchasedFromCash = false, PurchasedFromCredit = false };
                            isSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto);

                            ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Done"));
                            return this.Redirect(string.Format(AppSettings.Get<string>("WebPaymentDone").ToString() + "?status=success", paypalDetails.Domain));
                        }
                        catch (Exception ex)
                        {
                            this.LoggerService.LogException("PaymentController > G2SSuccess(while updating system for who purchased what): " + ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("PaypalConfirmed :- " + ex.Message);
            }

            ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Error found"));
            return this.Redirect(string.Format(AppSettings.Get<string>("WebPaymentDone").ToString() + "?status=error"));
        }