我在MVC有一个项目。使用IPN接收更新数据库的付款通知。该项目工作正常,直到我点击"返回___测试商店"。
我收到以下服务器错误:
控制器:我按照这个例子=> PayPal & MVC
if (sAmountPaid != null)
{
// look up the requested service using the item_number
int id = int.Parse(Request["item_number"]);
var requestedService = db.RequestedServices.Where(rs => rs.RequestedServiceId == id).SingleOrDefault();
// look up the payment adjustment
var paymentAdjustment = requestedService.PaymentAdjustments.FirstOrDefault();
decimal amount = decimal.Parse(Request["mc_gross"]); // pull out the total amount
string payerEmail = Request["payer_email"]; // and the paypal user email
// before creating a new payment object, make sure there isn't an item with the transaction id already
// in the database
var paymentCheck = db.Payments.Where(p => p.TransactionId == transactionID).SingleOrDefault();
if (paymentCheck != null)
{
ViewBag.Success = "yes";
return View();
}
// if a payment with that id hasn't been made, create one
Payment payment = new Payment()
{
DateSubmitted = DateTime.Now.AddHours(2),
IsActive = true,
IsCompleted = false,
RequestedServiceId = id,
TransactionId = transactionID,
Amount = amount,
Email = payerEmail,
};
// set the payment completion status based on the result
if (Request["payment_status"].ToLower() == "completed")
{
payment.IsCompleted = true;
paymentAdjustment.IsCompleted = true;
}
db.Payments.Add(payment);
db.Entry(paymentAdjustment).State = EntityState.Modified;
db.SaveChanges();
// send an email notifying the contractor that a new service has been requested
IEmailSender emailsender = new GoDaddyEmailSender(); // send the emails via GoDaddy (implementing IEmailSender interface)
string subject = "Full Payment Adjustment Completed!";
string body = null;
var customer = db.my_aspnet_users.Where(u => u.id == requestedService.UserId).SingleOrDefault();
var yardladEmail = db.SiteSettings.Where(ss => ss.Name == "Yard Lad Contact Email").Single().Value;
foreach (var user in requestedService.Contractor.ContractorUsers)
{
var recipientEmail = Membership.GetUser(user.UserId, false).Email;
var userProfile = db.UserProfiles.Where(up => up.UserId == user.UserId).SingleOrDefault();
body += "<p>A new payment amount for the " + requestedService.ContractorService.Service.Name.ToLower() + " service has been completed!</p>";
body += "<p>Login to your account <a href=\"https://www.yardlad.com/Contractor/ServiceHistory/" + requestedService.ContractorId + "\">here</a> to view the changes</p>";
// send email to the users (will need to replace the emails when deploying)
try
{
emailsender.SendEmail(subject, body, from: yardladEmail, recipient: recipientEmail);
}
catch (Exception ex)
{
// log
}
}
ViewBag.Success = "yes";
return View();
}
我已经尝试运行调试器,但是当它到达我的控制器的这一部分时,什么都没有被触发。所有其他步骤和流程在工作之前没有问题。