这是一个非常混乱的问题,所以我会尽我所能详细说明。我有一个Facebook的画布应用程序,需要支付,当用户点击付款按钮,将出现以下情况:以错误的顺序完成回调函数
我的JavaScript回调函数被调用,并通过支付ID,所以我保存这个支付的ID等信息到我的订单数据库。
Facebook调用一个回叫网址,我已经设置了让我知道付款何时通过。它只给我付款ID,所以我使用它来搜索数据库中的行,并附上他们发送的付款ID。然后,我使用该行中的信息填充发送给客户的电子邮件,以确认其订单。
我的大问题是,由于某种原因步骤2中得到第1步之前完成,所以当我尝试查找付款ID在数据库中,它还不存在,所以我不能发给客户发电子邮件。我能做些什么来解决这个问题?我在下面的两个步骤都有伪代码。
第1步:
using (OrderDBContext order = new OrderDBContext())
{
string message = Encryption.SimpleDecryptWithPassword(orderDetails.request_id, GlobalFacebookConfiguration.Configuration.AppId, 0);
string[] finalMessage = message.Split('@');
int orderID = Convert.ToInt16(finalMessage.ElementAtOrDefault(2));
Models.Order row = order.Orders.Where(i => i.ID == orderID).FirstOrDefault();
switch (orderDetails.status)
{
case "completed":
row.PaymentID = orderDetails.payment_id;
row.Currency = orderDetails.currency;
row.HashKey = orderDetails.request_id;
row.Paid = true;
order.SaveChanges();
return Json(new { message = "Your payment was processed! You will receive a confirmation email soon." }, JsonRequestBehavior.AllowGet);
case "initiated":
row.PaymentID = orderDetails.payment_id;
row.Currency = orderDetails.currency;
row.HashKey = orderDetails.request_id;
row.Paid = false;
order.SaveChanges();
return Json(new { message = "Your payment is being processed! You will receive a confirmation email as soon as the payment is confirmed." }, JsonRequestBehavior.AllowGet);
}
}
第2步:
dynamic result = new StreamReader(request.InputStream).ReadToEnd();
var items = JsonConvert.DeserializeObject<RootObject>(result);
string paymentID;
if (items.entry != null && items.entry.Count > 0)
{
paymentID = items.entry[0].id;
}
else
{
// logic when items.entry is null or doesn't have any elements
paymentID = null;
}
if (PaymentHelper.confirmPayment(paymentID, GlobalFacebookConfiguration.Configuration.AppId, GlobalFacebookConfiguration.Configuration.AppSecret))
{
// if payment is confirmed then send email to us with the order details
// then send confirmation email to user letting them know that we are working on it
using (OrderDBContext order = new OrderDBContext())
{
Order row = order.Orders.Where(i => i.PaymentID == paymentID).FirstOrDefault();
SendEmail.sendOrderDetailsToWriter(row);
SendEmail.sendOrderDetailsToCustomer(row);
}
}
你需要第三步同步2个第一。 – tschmit007 2014-12-06 10:25:04
@ tschmit007不确定你的意思。你能举一些例子代码吗? – user3610374 2014-12-06 11:03:51