【发布时间】:2020-04-21 11:13:14
【问题描述】:
我正在开发一款应用,允许会员使用 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));
}
}
以下是我的 chtml 文件中的内容:
<div id="eventBook" class="text-center">
<form asp-action="Charge" asp-controller="Timetable" method="post">
<article>
<label>Amount: £3.00</label>
</article>
<script src="//checkout.stripe.com/v2/checkout.js"
class="stripe-button"
data-key="@Stripe.Value.PublishableKey"
data.locale="auto"
data-description="Class Charge">
</script>
</form>
</div>
我不确定我是否从条带中传递了正确的数据以将付款分配给特定用户,然后他们可以继续查看交易列表。
【问题讨论】:
标签: javascript html asp.net-core stripe-payments