PDA

View Full Version : سوال: paypl صفحه ipp.aspx من رافراخوانی نمی کند



favoritefa1
چهارشنبه 30 اردیبهشت 1388, 12:12 عصر
سلام

لطفا کمک کنید نیاز فوری دارم
من قطعه کدی به نام Ipn handler نوشته ام که در صورتی که فرد با سیستم paypal خرید کرد، paypal باید این کد را فراخوانی کند ، تا برنامه من چک کند که درست فراخوانی شده یا نه و در صورتی که درست یا نادرست باشد برای کاربر یک ایمیل می فرستد و وضعیت خرید را برای او ایمیل می کند ولی این کار صورت نمی گیرد. در واقع صفحه ipp.aspx من که توسط پارامتر "<input name=\"¬ify_url\" type=\"hidden\" value=\"http://www.test.ir/ipp.aspx\">"به paypal پاس داده می شود
و صفحه ی ipp.aspx من به صورت زیر می باشد:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;
using System.Net;
using System.IO;
using Commerce;
using CreatePaymentTableAdapters;
using System.Text;
using System.Net.Mail;
using System.Runtime.CompilerServices;
public partial class ipp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreatePaymentResponsesTableAdapter createPaymentTable = new CreatePaymentResponsesTableAdapter();

string Custom = "a.m@gmail.com"; //Request.Params["payer_email"];
string First_name = Request.Params["first_name"];
string Last_name = Request.Params["last_name"];
string business = Request.Params["business"];
string currency_code = Request.Params["currency_code"];
//string requestPrice = Request.Params["custom"];
// string Txn_id = Request.Params["txn_id"];

string requestUriString;
CultureInfo provider = new CultureInfo("en-us");

string strFormValues = Encoding.ASCII.GetString(
this.Request.BinaryRead(this.Request.ContentLength ));

// getting the URL to work with
if (String.Compare(
ConfigurationManager.AppSettings["UseSandbox"].ToString(),
"true", false) == 0)
{
requestUriString =
"https://www.sandbox.paypal.com/cgi-bin/webscr";
}
else
{
requestUriString = "https://www.paypal.com/cgi-bin/webscr";
}

// Create the request back
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(requestUriString );

// Set values for the request back
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string obj2 = strFormValues + "&cmd=_notify-validate";
request.ContentLength = obj2.Length;



// Write the request back IPN strings
StreamWriter writer =
new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
writer.Write(RuntimeHelpers.GetObjectValue(obj2));
writer.Close();

//send the request, read the response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("utf-8");
StreamReader reader = new StreamReader(responseStream, encoding);

// Reads 256 characters at a time.

char[] buffer = new char[0x101];
int length = reader.Read(buffer, 0, 0x100);
while (length > 0)
{
// Dumps the 256 characters to a string

string requestPrice;
string IPNResponse = new string(buffer, 0, length);
length = reader.Read(buffer, 0, 0x100);


try
{
// getting the total cost of the goods in
// cart for an identifier
// of the request stored in the "custom" variable
requestPrice = Request.Params["custom"];//GetRequestPrice(this.Request["custom"].ToString());
if (String.Compare(requestPrice, "", false) == 0)
{

SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: amount = \\", txn_id);
/* Carts.WriteFile("Error in IPNHandler: amount = \");*/

return;
}
}
catch (Exception exception)
{
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: " + exception.Message, Request.Params["txn_id"]);

return;
}

NumberFormatInfo info2 = new NumberFormatInfo();
info2.NumberDecimalSeparator = ".";
info2.NumberGroupSeparator = ",";
info2.NumberGroupSizes = new int[] { 3 };

// if the request is verified

if (String.Compare(IPNResponse, "VERIFIED", false) == 0)
{
// check the receiver's e-mail (login is user's
// identifier in PayPal)
// and the transaction type
if ((String.Compare(this.Request["receiver_email"], business, false) != 0)// برابر نیست paypal ایمیل دریافتی با ایمیل اصلی در
|| (String.Compare(this.Request["txn_type"], "web_accept", false) != 0))//نبوده است buy now نوع تراکنش
{
try
{
// parameters are not correct. Write a
// response from PayPal
// and create a record in the Log file.

/*this.CreatePaymentResponses(Request.Params["txn_id"],
Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), false,
"INVALID payment's parameters" +
"(receiver_email or txn_type)");*/
createPaymentTable.Insert(Request.Params["txn_id"], Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), false,
"INVALID payment's parameters" +
"(receiver_email or txn_type)");
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: INVALID payment's" +
" parameters(receiver_email or txn_type)", Request.Params["txn_id"]);
/*Carts.WriteFile(
"Error in IPNHandler: INVALID payment's" +
" parameters(receiver_email or txn_type)");*/
}
catch (Exception exception)
{
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: " +
exception.Message, Request.Params["txn_id"]);/*Carts.WriteFile("Error in IPNHandler: " +
exception.Message);*/
}
reader.Close();
// response.Close();
return;
}


// check whether this request was performed
// earlier for its identifier
if (createPaymentTable.CountTxn_Id(Request.Params["txn_id"]) > 0) /*if (this.IsDuplicateID(Request.Params["txn_id"]))*/
{
// the current request is processed. Write
// a response from PayPal
// and create a record in the Log file.
/*this.CreatePaymentResponses(Request.Params["txn_id"],
Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), false,
"Duplicate txn_id found");*/

createPaymentTable.Insert(Request.Params["txn_id"],
Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), false,
"Duplicate txn_id found");
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: Duplicate txn_id found", Request.Params["txn_id"]);
/* Carts.WriteFile(
"Error in IPNHandler: Duplicate txn_id found");*/
reader.Close();
// response.Close();
return;
}

// the amount of payment, the status of the
// payment, and a possible reason of delay
// The fact that Getting txn_type=web_accept or
// txn_type=subscr_payment are got odes not mean that
// seller will receive the payment.
// That's why we check payment_status=completed. The
// single exception is when the seller's account in
// not American and pending_reason=intl
if (((String.Compare(this.Request["mc_gross"].ToString(provider), requestPrice, false) != 0) ||//مبلغ پرداختی با مبلغی که مشتری باید بپردازد یکی نباشد
(String.Compare(this.Request["mc_currency"], currency_code, false) != 0)) ||//رایج پرداختی با رایج تعریف شده یکی نباشد
((String.Compare(this.Request["payment_status"], "Completed", false) != 0) &&//وضعیت پرداخت کامل شده نباشد
(String.Compare(this.Request["pending_reason"], "intl", false) != 0)))//حساب فروشنده آمریکایی نباشد
{
// parameters are incorrect or the payment
// was delayed. A response from PayPal should not be
// written to DB of an XML file
// because it may lead to a failure of
// uniqueness check of the request identifier.
// Create a record in the Log file with information
// about the request.
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: INVALID payment's parameters." +
"Request: " + strFormValues, Request.Params["txn_id"]);

/*Carts.WriteFile(
"Error in IPNHandler: INVALID payment's parameters."+
"Request: " + strFormValues);*/
reader.Close();
// response.Close();
return;
}
try
{
// write a response from PayPal
/* this.CreatePaymentResponses(Request.Params["txn_id"],
Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), true, "");*/


createPaymentTable.Insert(Request.Params["txn_id"],
Convert.ToDecimal(this.Request["mc_gross"], info2),
this.Request["payer_email"],
this.Request["first_name"],
this.Request["last_name"],
this.Request["address_street"],
this.Request["address_city"],
this.Request["address_state"],
this.Request["address_zip"],
this.Request["address_country"],
Convert.ToInt32(this.Request["custom"]), true, "");
SendEmail(Custom, First_name, Last_name, "Success in IPNHandler: PaymentResponses created", Request.Params["txn_id"]);
/*Carts.WriteFile(
"Success in IPNHandler: PaymentResponses created");*/

///////////////////////////////////////////////////
// Here we notify the person responsible for
// goods delivery that
// the payment was performed and providing
// him with all needed information about
// the payment. Some flags informing that
// user paid for a services can be also set here.
// For example, if user paid for registration
// on the site, then the flag should be set
// allowing the user who paid to access the site
//////////////////////////////////////////////////
}
catch (Exception exception)
{
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler: " + exception.Message, Request.Params["txn_id"]);
/*Carts.WriteFile(
"Error in IPNHandler: " + exception.Message);*/
}
}//نیست verified
else
{
SendEmail(Custom, First_name, Last_name, "Error in IPNHandler. IPNResponse = 'INVALID'", Request.Params["txn_id"]);
/*Carts.WriteFile(
"Error in IPNHandler. IPNResponse = 'INVALID'");*/
}
}
reader.Close();
//response.Close();

}

private void SendEmail(string Custom,string Name, string Family, string Subject,string txn_id)
{
MailMessage mail = new MailMessage();
System.Collections.Specialized.ListDictionary ld = new System.Collections.Specialized.ListDictionary();


ld.Add("%txn_id%", txn_id);//az paigahe dadeh migirim
ld.Add("%Name%", Name);
ld.Add("%Family%", Family);


EmailSender.SendEmailFromUs(Custom, "", Subject, "~/UserDownload.htm", ld, this, true);

}
}