简体   繁体   English

使用已保存的信用卡进行条纹付款

[英]Stripe Payment using saved credit card

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) 如何使用此已保存的信用卡(StripeCard)付款

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. 假设卡已正确保存,则可以使用Create Charge API对其进行计费,并在customer参数中传递客户ID cus_XXXX ,在source参数中card_YYYy卡ID card_YYYy With Stripe.net, the code is documented here and would look like this: 使用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);

It's also important to note that your current code is sending card details through the API directly. 同样重要的是要注意,您当前的代码是直接通过API发送卡的详细信息。 This means that you get the card numbers on your server. 这意味着您可以在服务器上获得卡号。 This is a bad idea and breaks PCI compliance . 这是一个坏主意,破坏了PCI合规性 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. 您应该使用ElementsStripe Checkout客户端将卡详细信息直接发送到Stripe,并获得唯一的卡令牌(tok_XXX),然后将其安全发送到服务器以创建客户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM