我正在开发一个应用程序,允许会员使用 Stripe 预订/支付课程费用。但是,我发现很难更新应用程序来表明用户是否已付款成功。
目的是当用户付款时,付款将分配给他们,并且他们能够在其帐户中获取付款列表。下面是我的控制器中的代码:
[HttpPost]
public IActionResult PaymentSuccess(Event obj, int memberId, int eventId)
{
// add member to event attendees? if so just call BookEvent above
var eventBook = BookEvent(memberId, eventId);
var result = new { eventBook }; //service.UpdateEventAfterPayment(obj);
return Json(result);
}
public IActionResult Charge(string stripeEmail, string stripeToken, Event obj)
{
//var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
var customers = new Stripe.CustomerService();
var charges = new Stripe.ChargeService();
var customer = customers.Create(new Stripe.CustomerCreateOptions
{
Email = stripeEmail,
Source = stripeToken
}) ;
var charge = charges.Create(new Stripe.ChargeCreateOptions
{
Amount = 300,
Description = "Class Payment",
Currency="gbp",
Customer= customer.Id,
ReceiptEmail= stripeEmail,
Metadata = new Dictionary<string, string>()
{
{"OrderId", "123" },
{"PostCode", "BT480GY" }
}
});
if(charge.Status == "succeeded")
{
string BalanceTransactionId = charge.BalanceTransactionId;
var email = User.FindFirst("sub")?.Value;
var customerPaid = charge.Paid;
customerPaid = true;
return RedirectToAction(nameof(Index));
}
return RedirectToAction(nameof(Index));
}
}
我不确定我是否从条带中传递了正确的数据来将付款分配给特定用户,然后他们可以继续查看交易列表。
翻翻过去那场雪
尚方宝剑之说
相关分类