更新用户以显示他们已付款 - Stripe .Net Core

我正在开发一个应用程序,允许会员使用 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));

        }

    }


我不确定我是否从条带中传递了正确的数据来将付款分配给特定用户,然后他们可以继续查看交易列表。


BIG阳
浏览 110回答 2
2回答

翻翻过去那场雪

我正在开发一个应用程序,允许会员使用 Stripe 预订/支付课程费用。但是,我发现很难更新应用程序来表明用户是否已付款成功。目的是当用户付款时,付款将分配给他们,并且他们能够在其帐户中获取付款列表。下面是我的控制器中的代码:[HttpPost]public IActionResult PaymentSuccess(Event obj, int memberId, int eventId){&nbsp; &nbsp; // add member to event attendees? if so just call BookEvent above&nbsp; &nbsp; var eventBook = BookEvent(memberId, eventId);&nbsp; &nbsp; var result = new { eventBook }; //service.UpdateEventAfterPayment(obj);&nbsp; &nbsp; return Json(result);}public IActionResult Charge(string stripeEmail, string stripeToken, Event obj){&nbsp; &nbsp; //var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();&nbsp; &nbsp; &nbsp;var customers = new Stripe.CustomerService();&nbsp; &nbsp; &nbsp;var charges = new Stripe.ChargeService();&nbsp; &nbsp; &nbsp;var customer = customers.Create(new Stripe.CustomerCreateOptions&nbsp; &nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;Email = stripeEmail,&nbsp; &nbsp; &nbsp; &nbsp;Source = stripeToken&nbsp; &nbsp; &nbsp; }) ;&nbsp; &nbsp; &nbsp; var charge = charges.Create(new Stripe.ChargeCreateOptions&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Amount = 300,&nbsp; &nbsp; &nbsp; &nbsp; Description = "Class Payment",&nbsp; &nbsp; &nbsp; &nbsp; Currency="gbp",&nbsp; &nbsp; &nbsp; &nbsp; Customer= customer.Id,&nbsp; &nbsp; &nbsp; &nbsp; ReceiptEmail= stripeEmail,&nbsp; &nbsp; &nbsp; &nbsp; Metadata = new Dictionary<string, string>()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"OrderId", "123" },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"PostCode", "BT480GY" }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; if(charge.Status == "succeeded")&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string BalanceTransactionId = charge.BalanceTransactionId;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var email = User.FindFirst("sub")?.Value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var customerPaid = charge.Paid;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customerPaid = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction(nameof(Index));&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction(nameof(Index));&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }以下是我的 chtml 文件中的内容:<div id="eventBook" class="text-center">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <form asp-action="Charge" asp-controller="Timetable" method="post">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <article>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Amount: £3.00</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </article>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <script src="//checkout.stripe.com/v2/checkout.js"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; class="stripe-button"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data-key="@Stripe.Value.PublishableKey"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.locale="auto"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data-description="Class Charge">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>我不确定我是否从条带中传递了正确的数据来将付款分配给特定用户,然后他们可以继续查看交易列表。var&nbsp;customerID&nbsp;=&nbsp;"cus_1234xxx...";&nbsp;//&nbsp;Retrieved&nbsp;from&nbsp;session&nbsp;or&nbsp;DBvar&nbsp;options&nbsp;=&nbsp;new&nbsp;ChargeListOptions&nbsp;{&nbsp;Limit&nbsp;=&nbsp;3,&nbsp;Customer&nbsp;=&nbsp;customerID&nbsp;};var&nbsp;service&nbsp;=&nbsp;new&nbsp;ChargeService(); StripeList<Charge>&nbsp;charges&nbsp;=&nbsp;service.List( &nbsp;&nbsp;options );希望这能说明问题!

尚方宝剑之说

理想情况下,您不应依赖 Stripe 客户和系统中的用户之间的 1-1 关联。除非您有固定的付款来源,否则不需要 Stripe 客户。即使您这样做,也不一定要求每个用户都有一个 Stripe 客户。这里更好的方法是记录您端的费用 ID,并将其与用户相关联。然后,您应该有一个用于 Stripe 的 Webhook 端点,以便在收费完成时发出通知。当 webhook 被命中时,您可以查找您这边的付款/用户及其关联的费用 ID,并相应地更新任何内容。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5