示例#1
0
 /// <summary>
 /// Fills the g2s response.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="g2SModel">The G2S Model.</param>
 /// <returns>G2S Request Model.</returns>
 private G2SRequestModel FillG2SRequest(Dictionary<string, string> parameters, G2SModel g2SModel)
 {
     G2SRequestModel request = new G2SRequestModel();
     request.Currency = parameters["currency"];
     request.ItemName = parameters["item_name_1"];
     request.ItemAmount = parameters["item_amount_1"];
     request.NumberOfItems = parameters["numberofitems"];
     request.TotalAmount = parameters["total_amount"];
     request.ItemNumber = parameters["item_number_1"];
     request.ItemQuantity = parameters["item_quantity_1"];
     request.Encoding = parameters["encoding"];
     request.TimeStamp = parameters["time_stamp"];
     request.Version = parameters["version"];
     request.InvoiceId = parameters["invoice_id"];
     request.SuccessUrl = parameters["success_url"];
     request.ErrorUrl = parameters["error_url"];
     request.PendingUrl = parameters["pending_url"];
     request.NotifyUrl = parameters["notify_url"];
     request.ClientId = g2SModel.ClientId;
     request.ClientInterest = g2SModel.ClientInterest;
     request.CompanyId = g2SModel.CompanyId;
     request.Address = string.Empty;
     request.City = string.Empty;
     request.Country = string.Empty;
     request.Email = string.Empty;
     request.Phone = string.Empty;
     request.Zip = string.Empty;
     return request;
 }
示例#2
0
 /// <summary>
 /// Generates invoice for the transaction.
 /// </summary>
 /// <param name="g2SModel">g2s model.</param>
 /// <returns>Invoice created successfully or not.</returns>
 private long CreateInvoice(G2SModel g2SModel)
 {
     InvoiceModel invoiceModel = new InvoiceModel();
     invoiceModel.ClientId = g2SModel.ClientId;
     invoiceModel.ClientInterest = g2SModel.ClientInterest;
     invoiceModel.CompanyId = g2SModel.CompanyId;
     invoiceModel.EnumStatus = InvoiceStatus.Pending;
     long result = this.paymentService.CreateInvoice(invoiceModel);
     return result;
 }
示例#3
0
 /// <summary>
 /// Creates parameters map
 /// </summary>
 /// <param name="encoding">The encoding.</param>
 /// <param name="g2SModel">The g2 s model.</param>
 /// <returns>Dictionary object</returns>
 private Dictionary<string, string> ConstructParametersMap(string encoding, G2SModel g2SModel)
 {
     Dictionary<string, string> parameters = new Dictionary<string, string>();
     string timestamp = DateTime.UtcNow.ToString(this.dateFormat);
     parameters.Add("merchant_site_id", AppSettings.Get<string>("merchant_site_id"));
     parameters.Add("merchant_id", AppSettings.Get<string>("merchant_id"));
     parameters.Add("currency", AppSettings.Get<string>("interestPriceCurrency"));
     parameters.Add("item_name_1", g2SModel.Product.Title);
     parameters.Add("item_amount_1", (Convert.ToDouble(g2SModel.Product.Price) + Convert.ToDouble(g2SModel.ProcessingFee)).ToString());
     parameters.Add("numberofitems", "1");
     parameters.Add("total_amount", (Convert.ToDouble(g2SModel.Product.Price) + Convert.ToDouble(g2SModel.ProcessingFee)).ToString());
     parameters.Add("item_number_1", "1");
     parameters.Add("item_quantity_1", "1");
     parameters.Add("encoding", encoding);
     parameters.Add("time_stamp", timestamp);
     parameters.Add("version", "4.0.0");
     parameters.Add("invoice_id", g2SModel.InvoiceId);
     parameters.Add("success_url", AppSettings.Get<string>("success_url"));
     parameters.Add("error_url", AppSettings.Get<string>("error_url"));
     parameters.Add("pending_url", AppSettings.Get<string>("pending_url"));
     parameters.Add("notify_url", AppSettings.Get<string>("dmn_url"));
     parameters.Add("customField1", g2SModel.ClientId);
     parameters.Add("customField2", g2SModel.ClientInterest);
     parameters.Add("customField3", g2SModel.CompanyId);
     return parameters;
 }
示例#4
0
        public async Task<IHttpActionResult> CreateRequest(G2SModel g2SModel)
        {
            UserResultModel userResultModel = new UserResultModel();
            string crmContactId = this.userService.GetContact(g2SModel.ClientId).CRMId;
            string crmLeadId = string.Empty;

            if (!string.IsNullOrEmpty(crmContactId))
            {
                crmLeadId = this.youfferContactService.GetMappingEntryByContactId(g2SModel.ClientId).LeadId;
            }

            CountryModel countryDet = this.commonService.GetUserCountryDetails(g2SModel.ClientId);
            decimal rank = this.crmManagerService.GetUserRank(crmContactId);

            var reviews = this.crmManagerService.GetUserReviews(crmContactId);
            List<UserReviewsDto> lstReviews = this.mapperFactory.GetMapper<List<CRMUserReview>, List<UserReviewsDto>>().Map(reviews);

            if (!string.IsNullOrEmpty(crmLeadId))
            {
                LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId);
                userResultModel = this.mapperFactory.GetMapper<LeadModel, UserResultModel>().Map(leadModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = leadModel.PaypalId,
                    Mode = (PaymentMode)leadModel.PaymentMode
                };
            }
            else
            {
                ContactModel contactModel = this.crmManagerService.GetContact(g2SModel.ClientId);
                userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = contactModel.PaypalId,
                    Mode = (PaymentMode)contactModel.PaymentMode
                };
            }

            userResultModel.Id = g2SModel.ClientId;
            userResultModel.Rank = rank;
            userResultModel.CountryDetails = countryDet;
            userResultModel.UserRole = Roles.Customer;
            userResultModel.UserReviews = lstReviews;

            ProductModel productModel = new ProductModel()
            {
                Id = userResultModel.Id,
                Title = userResultModel.FirstName,
                Price = AppSettings.Get<decimal>("interestPrice")
            };
            g2SModel.Product = productModel;
            g2SModel.ProcessingFee = (g2SModel.Product.Price * AppSettings.Get<decimal>("processingFeePercent")) / 100;
            g2SModel.CompanyId = User.Identity.GetUserId();
            string merchantKey = AppSettings.Get<string>("secret_key");
            string pppUrl = AppSettings.Get<string>("live_pppURL");
            ////string pppUrl = AppSettings.Get<string>("test_pppURL");
            try
            {
                g2SModel.InvoiceId = this.CreateInvoice(g2SModel).ToString();
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("PaymentController > CreateRequest(while creating invoice): " + ex.StackTrace);
            }

            Dictionary<string, string> parameters = this.ConstructParametersMap(this.encoding, g2SModel);
            string checksum = this.CalculateChecksum(parameters, merchantKey, this.encoding);
            parameters.Add("checksum", checksum);
            string encoded_params = this.EncodeParameters(parameters, this.encoding);
            try
            {
                G2SRequestModel g2SRequestModel = this.FillG2SRequest(parameters, g2SModel);
                this.paymentService.InsertG2SRequest(g2SRequestModel);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("PaymentController > G2SSuccess(while filling or inserting request): " + ex.StackTrace);
            }

            return this.Ok(pppUrl + encoded_params);
        }