コード例 #1
0
        /// <summary>
        /// prepares Remote post by populate all the necessary fields to generate PayUMoney post request.
        /// </summary>
        /// <param name="order">order details.</param>
        /// <param name="returnUrl">return url.</param>
        /// <returns>return remote post.</returns>
        private async Task <RemotePost> PrepareRemotePost(OrderViewModel order, string returnUrl)
        {
            string fname = string.Empty;
            string phone = string.Empty;
            string email = string.Empty;
            CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance);
            CustomerViewModel customerRegistrationInfo = await customerRegistrationRepository.RetrieveAsync(order.CustomerId);

            fname = customerRegistrationInfo.FirstName;
            phone = customerRegistrationInfo.Phone;
            email = customerRegistrationInfo.Email;

            decimal       paymentTotal = 0;
            StringBuilder productSubs  = new StringBuilder();
            StringBuilder prodQuants   = new StringBuilder();

            foreach (var subscriptionItem in order.Subscriptions)
            {
                productSubs.Append(":").Append(subscriptionItem.SubscriptionId);
                prodQuants.Append(":").Append(subscriptionItem.Quantity.ToString());
                paymentTotal += Math.Round(subscriptionItem.Quantity * subscriptionItem.SeatPrice, Resources.Culture.NumberFormat.CurrencyDecimalDigits);
            }

            productSubs.Remove(0, 1);
            prodQuants.Remove(0, 1);
            System.Collections.Specialized.NameValueCollection inputs = new System.Collections.Specialized.NameValueCollection();
            PaymentConfiguration payconfig = await this.GetAPaymentConfigAsync();

            inputs.Add("key", payconfig.ClientId);
            inputs.Add("txnid", this.GenerateTransactionId());
            inputs.Add("amount", paymentTotal.ToString());
            inputs.Add("productinfo", productSubs.ToString());
            inputs.Add("firstname", fname);
            inputs.Add("phone", phone);
            inputs.Add("email", email);
            inputs.Add("udf1", order.OperationType.ToString());
            inputs.Add("udf2", prodQuants.ToString());
            inputs.Add("surl", returnUrl + "&payment=success&PayerId=" + inputs.Get("txnid"));
            inputs.Add("furl", returnUrl + "&payment=failure&PayerId=" + inputs.Get("txnid"));
            inputs.Add("service_provider", Constant.PAYUPAISASERVICEPROVIDER);
            string hashString = inputs.Get("key") + "|" + inputs.Get("txnid") + "|" + inputs.Get("amount") + "|" + inputs.Get("productInfo") + "|" + inputs.Get("firstName") + "|" + inputs.Get("email") + "|" + inputs.Get("udf1") + "|" + inputs.Get("udf2") + "|||||||||" + payconfig.ClientSecret; // payconfig.ClientSecret;
            string hash       = this.GenerateHash512(hashString);

            inputs.Add("hash", hash);

            RemotePost myremotepost = new RemotePost();

            myremotepost.SetUrl(this.GetPaymentUrl(payconfig.AccountType));
            myremotepost.SetInputs(inputs);
            return(myremotepost);
        }