Auto Return is enabled, donations are getting posted, but user has to click yellow "Return To Coordinator" button to come back. Anything you see wrong with this snippet, please let me know..
P.S. I don't want to user custom buttons.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="email@gmail.com">
<!-- Specify a Donate button. -->
<input type="hidden" name="cmd" value="_donations">
<!-- Specify details about the contribution -->
<input type="hidden" name="item_name" value="@Resources.Donations.Strings.ThankYou">
<input type="hidden" name="return" value="http://www.return.com/thankyou"/>
<input type="hidden" name="cancel_return" value="http://www.return.com/cancel"/>
<input type="hidden" name="rm" value="2"/>
<input type="hidden" name="item_number" value="5.00">
<select name="amount" onchange="$('input[name=item_number]').val($(this).val())">
<option value="1.00">$1.00</option>
<option value="5.00" selected>$5.00</option>
<option value="10.00">$10.00</option>
<option value="15.00">$15.00</option>
<option value="25.00">$25.00</option>
<option value="50.00">$50.00</option>
<option value="">@Resources.Donations.Labels.Other</option>
</select>
<input type="hidden" name="currency_code" value="USD">
<!-- Display the payment button. -->
<button type="submit" name="submit" class="btn btn-large btn-paypal"></button>
</form>
As Andrew suggested, I refactored my code to use IPN. Here's some code I started with.. This is some code with logging that can get you started..
HTML form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="donations@myemail.org">
<!-- Specify a Donate button. -->
<input type="hidden" name="cmd" value="_donations">
<!-- Specify details about the contribution -->
<input type="hidden" name="item_name" value="@Resources.Donations.Strings.ThankYou">
<input type="hidden" name="return" value="auto_return_url_here"/>
<input type="hidden" name="notify_url" value="IPN_notify_url_here"/>
<input type="hidden" name="cancel_return" value="user_clicked_cancel_url_here"/>
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="item_number" value="5.00">
<select name="amount" onchange="$('input[name=item_number]').val($(this).val())">
<option value="1.00">$1.00</option>
<option value="5.00" selected>$5.00</option>
<option value="10.00">$10.00</option>
<option value="15.00">$15.00</option>
<option value="25.00">$25.00</option>
<option value="50.00">$50.00</option>
<option value="">Other</option>
</select>
<input type="hidden" name="currency_code" value="USD">
<!-- Display the payment button. -->
<button type="submit" name="submit" class="btn btn-large btn-paypal"></button>
</form>
IPN handler sample:
[HttpPost]
[AllowAnonymous]
public ActionResult PayPalDonationIpn(PayPalModel model)
{
Logger.InfoFormat("{0} - {1}",
model.txn_id, model.payment_status);
Logger.Info(model.ToXml());
if (!model.receiver_email.Equals(PayPalEmail, StringComparison.OrdinalIgnoreCase))
{
Logger.WarnFormat("Email 'receiver_email' value '{0}' does not match our email '{1}'.", model.receiver_email, base.PayPalEmail);
}
if (model.txn_id == null)
{
Logger.Warn("Parameter 'txn_id' is empty.");
}
var request = (HttpWebRequest)WebRequest.Create(PayPalPostUri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var param = Request.BinaryRead(Request.ContentLength);
var message = Encoding.ASCII.GetString(param);
message += "&cmd=_notify-validate";
request.ContentLength = message.Length;
//send the request to PayPal and get the response
using (var streamOut = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
{
streamOut.Write(message);
streamOut.Close();
using (var streamIn = new StreamReader(request.GetResponse().GetResponseStream()))
{
var response = streamIn.ReadToEnd();
streamIn.Close();
Logger.Info(response);
if (response.Equals("VERIFIED", StringComparison.OrdinalIgnoreCase))
{
Logger.InfoFormat("{0} - {1}, {2}", model.txn_id, model.mc_gross, model.mc_currency);
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that payment_amount/payment_currency are correct
//process payment
}
else if (response.Equals("INVALID", StringComparison.OrdinalIgnoreCase))
{
Logger.WarnFormat("INVALID response: {0}.", message);
}
else
{
Logger.WarnFormat("No status. Manual investinagation needed for {0}.", message);
}
}
}
return new EmptyResult();
}
And here's the PayPalModel with variable names:
public class PayPalModel
{
public string mc_gross { get; set; }
public string protection_eligibility { get; set; }
public string address_status { get; set; }
public string payer_id { get; set; }
public string tax { get; set; }
public string address_street { get; set; }
public string payment_date { get; set; }
public string payment_status { get; set; }
public string charset { get; set; }
public string address_zip { get; set; }
public string first_name { get; set; }
public string address_country_code { get; set; }
public string address_name { get; set; }
public string notify_version { get; set; }
public string custom { get; set; }
public string payer_status { get; set; }
public string address_country { get; set; }
public string address_city { get; set; }
public string quantity { get; set; }
public string payer_email { get; set; }
public string verify_sign { get; set; }
public string txn_id { get; set; }
public string payment_type { get; set; }
public string payer_business_name { get; set; }
public string last_name { get; set; }
public string address_state { get; set; }
public string receiver_email { get; set; }
public string pending_reason { get; set; }
public string txn_type { get; set; }
public string item_name { get; set; }
public string mc_currency { get; set; }
public string item_number { get; set; }
public string residence_country { get; set; }
public string test_ipn { get; set; }
public string transaction_subject { get; set; }
public string payment_gross { get; set; }
public string merchant_return_link { get; set; }
public string auth { get; set; }
public string ipn_track_id { get; set; }
}