Example #1
0
        public static string ProcessForm(HttpContext context)
        {
            File.WriteAllText(Constants.logDir + DateTime.UtcNow.Millisecond.ToString() + ".txt"
                              , "req recieved");
            StringBuilder bogusreason = new StringBuilder();

            if (context.Request.RequestType == "POST")
            {
                //verify receiver
                if (string.Compare(context.Request.Params["receiver_email"], receiverEmail, true) != 0)
                {
                    bogusreason.Append("invalid receiver");
                }



                string deviceId = context.Request.Params["option_selection1"];

                string appId = context.Request.Params["option_selection2"];

                string transactionId = context.Request.Params["txn_id"];

                if (string.IsNullOrEmpty(transactionId))
                {
                    bogusreason.Append("invalid trans id");
                }

                //verify payment status
                string paymentStatus = context.Request.Params["payment_status"];
                if (string.Compare(paymentStatus, Constants.successPaymentSatus, true) != 0)
                {
                    bogusreason.Append("payment status not complete");
                }
                else
                {//check it is not repeated transaction id
                    //verify txn_id is not repeated
                    bool isRepeated = PaymentProcessor.IsCompletedTransId(transactionId);
                    if (isRepeated)
                    {
                        bogusreason.Append("repeated transaction Id");
                    }
                }

                string firstName = context.Request.Params["first_name"];

                string lastName = context.Request.Params["last_name"];



                //verify trans type
                if (String.Compare(context.Request.Params["txn_type"],
                                   "web_accept", false) != 0)
                {
                    bogusreason.Append("invalid tran type");
                }

                string payAmountStr = context.Request.Params["mc_gross"];

                double payAmount;

                if (!double.TryParse(payAmountStr, out payAmount) || payAmount < minAmount)
                {
                    bogusreason.Append("payment not enough");
                }

                if (string.Compare(context.Request.Params["mc_currency"], currencyCode, true) != 0)
                {
                    bogusreason.Append("invalid currency");
                }

                string payerEMail = context.Request.Params["payer_email"];


                if (bogusreason.Length == 0)
                {
                    PaymentProcessor.AddTransactionInfo(new Payment(appId, transactionId, deviceId, paymentStatus, payAmount.ToString(), payerEMail, null, firstName, lastName));
                }
                else
                {
                    File.WriteAllText(Constants.logDir + DateTime.UtcNow.Ticks.ToString(),
                                      bogusreason.ToString());
                }

                return(null);
            }

            return(null);
        }