public static PaymentInfo PaymentTransactionDataToPaymentInfo(PaymentTransactionData transData)
        {
            PaymentInfo paymentInfo = null;

            if (transData != null && transData.ProductData != null)
            {
                paymentInfo = new PaymentInfo();

                try
                {
                    paymentInfo.ProductID = transData.ProductData.Product.ProductId;
                    paymentInfo.ProductName = transData.ProductData.Product.ProductName;
                    paymentInfo.SetPrice(transData.ProductData.Amount.ToString());
                    paymentInfo.TransactionID = transData.TransactionId;
                    paymentInfo.PaymentTime = transData.ChargeDate;
                    paymentInfo.PaymentTimeSpecified = true;
                    paymentInfo.SetPaymentType(transData.ProductData.Term.TermType);

                }
                catch (Exception e)
                {
                    // ignore.
                }
            }

            return paymentInfo;
        }
 public PaymentTransactionData GetPaymentTransactionData(string TransactionId)
 {
     PaymentTransactionData result = null;
     //string sql = "SELECT * FROM PaymentTransactionInfo where IsPay='True' and TransactionId='" + TransactionId + "'";
     string sql = "SELECT Pd.TransactionId, Pd.InywhereId, Pd.ProductTermId, Pd.AccountType, Pd.ChargeDate, CAST(Pd.CustomerInfo AS VARCHAR(MAX)) AS CustomerInfo, CAST(Pd.ChargeAccount AS VARCHAR(MAX)) AS ChargeAccount, CAST(Pd.TransactionResult AS VARCHAR(MAX)) AS TransactionResult, CAST(Pd.TransactionSettings AS VARCHAR(MAX)) AS TransactionSettings, CAST(Pd.ProductInfo AS VARCHAR(MAX)) AS ProductInfo" +
         " ,Pd.InAppPurchase FROM	[dbo].[PaymentTransactionInfo] AS Pd " +
         " LEFT JOIN [dbo].[ProductsTerm] AS Pt ON Pd.ProductTermId = Pt.Id" +
         " LEFT JOIN [dbo].[Products] AS P ON Pt.ProductId = P.ProductId " +
         " LEFT JOIN [dbo].[Terms] AS T ON Pt.TermId = T.TermId" +
         " WHERE Pd.TransactionId ='" + TransactionId + "'";
     var reader = da.GetDataReader(sql);
     if (reader.Read())
     {
         if (reader.FieldCount > 0)
         {
             result = new PaymentTransactionData();
             result.TransactionId = reader["TransactionId"].ToString();
             result.InywhereId = reader["InywhereId"].ToString();
             result.ChargeDate = DateTime.Parse(reader["ChargeDate"].ToString());
             if (reader["ChargeAccount"] != null && reader["ChargeAccount"].ToString() != "")
                 result.AccountData = SerializeHelper<BaseChargeAccountData>.Deserialize(reader["ChargeAccount"].ToString());
             if (reader["CustomerInfo"] != null && reader["CustomerInfo"].ToString() != "")
                 result.CustomerData = SerializeHelper<CustomerData>.Deserialize(reader["CustomerInfo"].ToString());
             if (reader["ProductInfo"] != null && reader["ProductInfo"].ToString() != "")
                 result.ProductData = SerializeHelper<ProductData>.Deserialize(reader["ProductInfo"].ToString());
             if (reader["TransactionResult"] != null && reader["TransactionResult"].ToString() != "")
                 result.TransactionResult = SerializeHelper<TransactionResult>.Deserialize(reader["TransactionResult"].ToString());
             if (reader["TransactionSettings"] != null && reader["TransactionSettings"].ToString() != "")
                 result.TransactionSettings = SerializeHelper<TransactionSettings>.Deserialize(reader["TransactionSettings"].ToString());
         }
     }
     reader.Close();
     return result;
 }
Beispiel #3
0
        public static void SendEmail(PaymentTransactionData data)
        {
            EMailItem item = new EMailItem();
            item.SenderAddress = @"*****@*****.**";
            item.SenderName = "Inywhere Products Center";
            item.Priority = MailPriority.High;
            item.ReplyTo = "*****@*****.**";
            //item.CC = new string[] { "*****@*****.**" };   //"*****@*****.**"
            //item.BCC = new string[] { "*****@*****.**" };
            item.To = new string[] { data.InywhereId }; // TODO:data.InywhereId
            item.Subject = "Thanks For Purchasing Inywhere Products.";
            item.Body = string.Format("Your order has been proceed. Thanks for purchasing {0}.", data.ProductData.Description); // TODO:

            item.EntityID = Guid.NewGuid().ToString();
            // item.Callback = new SendMailCallback(OnSent); // TODO: Define Send callback
            //item.Context = context; // TODO: context can be used for send callback processing.
            item.IsHtmlBody = false;

            //MailSender.Instance.Send(item);

            SendGridMailSender.SendMail(item);
        }
        public bool SavePaymentTransactionData(PaymentTransactionData data)
        {
            using (SqlConnection conn = new SqlConnection(da.dbConnection.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand(m_SavePaymentTransactionData, conn))
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(string.Format("Unable to connect to InywherePaymentInfo DB using connect string: {0}", conn.ConnectionString));
                        System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                        return false;
                    }

                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter[] callParameters = new SqlParameter[12];
                    callParameters[0] = new SqlParameter();
                    callParameters[0].ParameterName = "@TransactionId";
                    callParameters[0].IsNullable = false;
                    callParameters[0].SqlDbType = SqlDbType.VarChar;
                    callParameters[0].Direction = ParameterDirection.Input;
                    callParameters[0].Value = data.TransactionId;

                    callParameters[1] = new SqlParameter();
                    callParameters[1].ParameterName = "@InywhereId";
                    callParameters[1].IsNullable = false;
                    callParameters[1].SqlDbType = SqlDbType.VarChar;
                    callParameters[1].Direction = ParameterDirection.Input;
                    callParameters[1].Value = data.InywhereId;

                    callParameters[2] = new SqlParameter();
                    callParameters[2].ParameterName = "@ProductTermId";
                    callParameters[2].IsNullable = false;
                    callParameters[2].SqlDbType = SqlDbType.VarChar;
                    callParameters[2].Direction = ParameterDirection.Input;
                    callParameters[2].Value = data.ProductData.ProductTermId;

                    callParameters[3] = new SqlParameter();
                    callParameters[3].ParameterName = "@ChargeDate";
                    callParameters[3].IsNullable = false;
                    callParameters[3].SqlDbType = SqlDbType.DateTime;
                    callParameters[3].Direction = ParameterDirection.Input;
                    callParameters[3].Value = data.ChargeDate;

                    callParameters[4] = new SqlParameter();
                    callParameters[4].ParameterName = "@CustomerInfo";
                    callParameters[4].IsNullable = false;
                    callParameters[4].SqlDbType = SqlDbType.VarChar;
                    callParameters[4].Direction = ParameterDirection.Input;
                    callParameters[4].Value = SerializeHelper<CustomerData>.Serialize(data.CustomerData);

                    callParameters[5] = new SqlParameter();
                    callParameters[5].ParameterName = "@ChargeAccount";
                    callParameters[5].IsNullable = false;
                    callParameters[5].SqlDbType = SqlDbType.VarChar;
                    callParameters[5].Direction = ParameterDirection.Input;
                    callParameters[5].Value = SerializeHelper<BaseChargeAccountData>.Serialize(data.AccountData);

                    callParameters[6] = new SqlParameter();
                    callParameters[6].ParameterName = "@TransactionResult";
                    callParameters[6].IsNullable = false;
                    callParameters[6].SqlDbType = SqlDbType.VarChar;
                    callParameters[6].Direction = ParameterDirection.Input;
                    callParameters[6].Value = SerializeHelper<TransactionResult>.Serialize(data.TransactionResult);

                    callParameters[7] = new SqlParameter();
                    callParameters[7].ParameterName = "@TransactionSettings";
                    callParameters[7].IsNullable = false;
                    callParameters[7].SqlDbType = SqlDbType.VarChar;
                    callParameters[7].Direction = ParameterDirection.Input;
                    callParameters[7].Value = SerializeHelper<TransactionSettings>.Serialize(data.TransactionSettings);

                    callParameters[8] = new SqlParameter();
                    callParameters[8].ParameterName = "@AccountType";
                    callParameters[8].IsNullable = false;
                    callParameters[8].SqlDbType = SqlDbType.VarChar;
                    callParameters[8].Direction = ParameterDirection.Input;
                    callParameters[8].Value = data.AccountData.GetType().ToString();

                    callParameters[9] = new SqlParameter();
                    callParameters[9].ParameterName = "@ProductInfo";
                    callParameters[9].IsNullable = false;
                    callParameters[9].SqlDbType = SqlDbType.VarChar;
                    callParameters[9].Direction = ParameterDirection.Input;
                    callParameters[9].Value = SerializeHelper<ProductData>.Serialize(data.ProductData);

                    callParameters[10] = new SqlParameter();
                    callParameters[10].ParameterName = "@IsPay";
                    callParameters[10].IsNullable = true;
                    callParameters[10].SqlDbType = SqlDbType.Bit;
                    callParameters[10].Direction = ParameterDirection.Input;
                    callParameters[10].Value = data.TransactionResult.Suceeded;

                    callParameters[11] = new SqlParameter();
                    callParameters[11].ParameterName = "@InAppPurchase";
                    callParameters[11].IsNullable = true;
                    callParameters[11].SqlDbType = SqlDbType.Bit;
                    callParameters[11].Direction = ParameterDirection.Input;
                    callParameters[11].Value = false;
                    cmd.Parameters.AddRange(callParameters);

                    var reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        int returnCode = int.Parse(reader[0].ToString());
                        if (returnCode == 0)
                        {
                            return true;
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("Not able to insert transaction data, error code {0}", returnCode));
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
        private NVPCodec DoExpressCheckOut(PaymentTransactionData transData)
        {
            NVPCodec decoder = new NVPCodec();
            com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "DoExpressCheckoutPayment";
            encoder["TOKEN"] = Session["TOKEN"].ToString();
            encoder["PAYERID"] = Session["PAYERID"].ToString();
            encoder["AMT"] = transData.ProductData.Amount.ToString();
            encoder["PAYMENTACTION"] = ConfigurationManager.AppSettings["paymentType"];
            encoder["CURRENCYCODE"] = ConfigurationManager.AppSettings["currency"];
            encoder["IPADDRESS"] = GetClientIP();

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp = caller.Call(pStrrequestforNvp);

            decoder.Decode(pStresponsenvp);
            return decoder;
        }
        private NVPCodec DirectPay(PaymentTransactionData data)
        {
            com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "DoDirectPayment";
            //encoder["PAYMENTACTION"] = this.Request.QueryString[Constants.PAYMENT_TYPE_PARAM];
            encoder["PAYMENTACTION"] = "Sale";
            encoder["AMT"] = data.ProductData.Amount.ToString();
            encoder["CURRENCYCODE"] = "USD";
            encoder["CREDITCARDTYPE"] = CreditCardUtility.GetCardTypeFromNumber(data.AccountData.CardNumber).ToString();
            encoder["ACCT"] = data.AccountData.CardNumber;
            encoder["EXPDATE"] = data.AccountData.ExpirationMonth.ToString() + data.AccountData.ExpirationYear.ToString();
            encoder["CVV2"] = data.AccountData.SecurityCode;
            //encoder["FIRSTNAME"] = data.CustomerData.FirstName;
            //encoder["LASTNAME"] = data.CustomerData.LastName;
            //encoder["STREET"] = data.CustomerData.AddressLine1;
            //encoder["CITY"] = data.CustomerData.City;
            //encoder["STATE"] = data.CustomerData.State;
            //encoder["ZIP"] = data.CustomerData.PostalCode;
            //encoder["COUNTRYCODE"] = data.CustomerData.Country;

            encoder["IPADDRESS"] = GetClientIP();

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(pStresponsenvp);

            //string strAck = decoder["ACK"];
            //if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning"))
            //{
            //    Session["result"] = decoder;
            //    //string pStrResQue = "API=" + "DoDirect Payment ";
            //    //Response.Redirect("DoDirectPaymentReceipt.aspx?" + pStrResQue);
            //    return decoder["ACK"];
            //}
            //else
            //{
            //    Session["errorresult"] = decoder;
            //    //string pStrResQue = "API=" + "Error Detail ";
            //    //Response.Redirect("APIError.aspx?" + pStrResQue);
            //    //ClientScript.RegisterStartupScript(this.GetType(), "a", "alert('" + decoder["L_LONGMESSAGE0"] + "')");
            //    return decoder["L_LONGMESSAGE0"];
            //}
            return decoder;
        }
        private static PaymentTransactionData PaymentInfoToPaymentTransactionData(PaymentInfo paymentInfo)
        {
            PaymentTransactionData transData = null;

            if (paymentInfo != null)
            {
                transData = new PaymentTransactionData();

                try
                {
                    ProductData productdata = new ProductData();
                    Product product = new Product();
                    product.ProductId = paymentInfo.ProductID;
                    product.ProductName = paymentInfo.ProductName;
                    product.IsVip = paymentInfo.ProductID.ToLower() == "vip";
                    productdata.Product = product;

                    productdata.Amount = Convert.ToDecimal(paymentInfo.Price.Amount);

                    Term term = new Term();
                    DataAccess da = new DataAccess();
                    DataTable dtterm = da.GetDataTable("select * from Terms where [Type]='" + productdata.Term.TermType + "'");
                    term.TermId = Convert.ToInt32(dtterm.Rows[0]["TermId"].ToString());
                    term.TermType = dtterm.Rows[0]["Type"].ToString();
                    term.Description = dtterm.Rows[0]["Description"].ToString();
                    productdata.Term = term;

                    productdata.ProductTermId = prefix + productdata.Product.ProductId.ToLower() + "_" + productdata.Term.Description.ToLower();
                    transData.TransactionId = paymentInfo.TransactionID;
                    transData.ChargeDate = paymentInfo.PaymentTime;
                    transData.ProductData = productdata;
                }
                catch { }
            }

            return transData;
        }