使用保存的信用卡条纹支付
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)进行支付
假设卡已正确保存,您可以使用“创建充值”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对其充值,如下所示:
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 compliance。您真的应该修改您的集成并始终首先在客户端标记卡详细信息。
您应该使用 Elements or Stripe Checkout 客户端将卡的详细信息直接发送到 Stripe 并获得一个唯一的卡令牌 (tok_XXX),然后您将其安全地发送到您的服务器以创建顾客。
我使用以下代码以条带形式保存信用卡。
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)进行支付
假设卡已正确保存,您可以使用“创建充值”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对其充值,如下所示:
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 compliance。您真的应该修改您的集成并始终首先在客户端标记卡详细信息。
您应该使用 Elements or Stripe Checkout 客户端将卡的详细信息直接发送到 Stripe 并获得一个唯一的卡令牌 (tok_XXX),然后您将其安全地发送到您的服务器以创建顾客。