我使用以下代码来保存信用卡条纹。
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.
更多推荐
发布评论