所以我使用条纹元素。这是代码:
<script src="https://js.stripe.com/v3/"></script>
<div action="/charge" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
<!-- a Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors -->
<div id="card-errors" role="alert"></div>
</div>
<asp:Button ID="btnPay" OnClick="btnPay_Click" runat="server" Text="Submit Payment" />
</div>
ate a Stripe client
var stripe = Stripe('pk_test_2ddddddddddr');
// Create an instance of Elements
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base: {
color: '#32325d',
lineHeight: '24px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
// Create an instance of the card Element
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the user if there was an error
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server
stripeTokenHandler(result.token);
}
});
});
仔细观察,我将Form更改为DIV并将按钮更改为ASP.NET类型, 我现在要做的是当我点击Button btnPay时,从代码隐藏中,我想检索卡号,该怎么做?
由于
答案 0 :(得分:2)
你不应该检索卡。让条纹为你做事。但是,如果要检索最后4位数,可以在结果中检索。
result.token.card.last4
如果您想以这种方式通知用户卡号,这很有用**** **** **** 1834。