使用保存的信用卡支付条款(Stripe Payment using saved credit card)

编程入门 行业动态 更新时间:2024-10-22 20:36:11
使用保存的信用卡支付条款(Stripe Payment using saved credit card)

我使用以下代码来保存信用卡条纹。

string stripeKey = ""; var guid = Guid.Parse(userGuid); var systemUser = _systemUserRepository.Get(a => a.UserGuid == guid).FirstOrDefault(); var accountProfile = _accountProfileRepository.Get(a => a.SystemUser == systemUser.ID).FirstOrDefault(); var customer = _clientRepository.Get(a => a.AccountProfile == accountProfile.ID).FirstOrDefault(); var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = customer.AccountProfile1.SystemUser1.Email; myCustomer.Description = customer.AccountProfile1.FirstName + " " + customer.AccountProfile1.LastName; var customerService = new StripeCustomerService(stripeKey); StripeCustomer stripeCustomer = customerService.Create(myCustomer); var myCard = new StripeCardCreateOptions(); // setting up the card myCard.SourceCard = new SourceCard { Number = cardNumber, ExpirationYear = expireYear, ExpirationMonth = expireMonth, }; var cardService = new StripeCardService(stripeKey); StripeCard stripeCard = cardService.Create(stripeCustomer.Id, myCard);

如何使用此保存的信用卡付款(StripeCard)

I use following code to save credit card in stripe.

string stripeKey = ""; var guid = Guid.Parse(userGuid); var systemUser = _systemUserRepository.Get(a => a.UserGuid == guid).FirstOrDefault(); var accountProfile = _accountProfileRepository.Get(a => a.SystemUser == systemUser.ID).FirstOrDefault(); var customer = _clientRepository.Get(a => a.AccountProfile == accountProfile.ID).FirstOrDefault(); var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = customer.AccountProfile1.SystemUser1.Email; myCustomer.Description = customer.AccountProfile1.FirstName + " " + customer.AccountProfile1.LastName; var customerService = new StripeCustomerService(stripeKey); StripeCustomer stripeCustomer = customerService.Create(myCustomer); var myCard = new StripeCardCreateOptions(); // setting up the card myCard.SourceCard = new SourceCard { Number = cardNumber, ExpirationYear = expireYear, ExpirationMonth = expireMonth, }; var cardService = new StripeCardService(stripeKey); StripeCard stripeCard = cardService.Create(stripeCustomer.Id, myCard);

How can I make a payment using this saved credit card(StripeCard)

最满意答案

假设卡已正确保存,您可以使用Create Charge API对其进行充电,并在customer参数中传递客户ID cus_XXXX ,并在source参数中card_YYYy卡ID card_YYYy 。 使用Stripe.net,代码记录在这里 ,看起来像这样:

var myCharge = new StripeChargeCreateOptions(); myCharge.Amount = 5153; myCharge.Currency = "usd"; myCharge.SourceTokenOrExistingSourceId = stripeCard.Id; myCharge.CustomerId = stripeCustomer.Id; var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Create(myCharge);

同样重要的是要注意您当前的代码是直接通过API发送卡详细信息。 这意味着您可以获得服务器上的卡号。 这是一个坏主意,并违反了PCI合规性 。 您应该真正修改您的集成,并始终首先将客户端的卡详细信息标记。

您应该使用Elements或Stripe Checkout客户端将卡详细信息直接发送到Stripe,并获得一个唯一的卡令牌(tok_XXX),然后您可以安全地将其发送到您的服务器以创建客户。

Assuming the card is saved properly, you can charge it using the Create Charge API and passing the customer id cus_XXXX in the customer parameter and the card id card_YYYy in the source parameter. With Stripe.net, the code is documented here and would look like this:

var myCharge = new StripeChargeCreateOptions(); myCharge.Amount = 5153; myCharge.Currency = "usd"; myCharge.SourceTokenOrExistingSourceId = stripeCard.Id; myCharge.CustomerId = stripeCustomer.Id; var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Create(myCharge);

It's also important to note that your current code is sending card details through the API directly. This means that you get the card numbers on your server. This is a bad idea and breaks PCI compliance. You should really modify your integration and always tokenize the card details first client-side.

You should use Elements or Stripe Checkout client-side to send the card details to Stripe directly and get a unique card token (tok_XXX) that you'd then send safely to your server to create the customer.

更多推荐

本文发布于:2023-07-05 06:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信用卡   条款   Stripe   Payment   credit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!