This should work
JS code
constructor(paymentInfo) { this.paymentInfo = paymentInfo; this.paymentInfo.amount = 25; this.loadStripe(); } afterLoadingStripe() { this.stripe = Stripe(this.publicKey); var elements = this.stripe.elements(); this.card = elements.create('card', { style: { base: { iconColor: '#666EE8', color: '#31325F', lineHeight: '40px', fontWeight: 300, fontFamily: 'Helvetica Neue', fontSize: '15px', '::placeholder': { color: '#CFD7E0', }, }, } }); this.card.mount('#card-element'); } getToken() { let context = this; this.stripe.createToken(this.card).then(function (result) { if (result.error) { } else { context.paymentInfo.token = result; context.submitPaymentInfo(); } }); } submitPaymentInfo() { //submit here return; } loadStripe() { var script = document.createElement('script'); let context = this; script.onload = function () { context.afterLoadingStripe(); }; script.src = "https://js.stripe.com/v3/"; document.getElementsByTagName('head')[0].appendChild(script); }
}
HTML
<script src="https://js.stripe.com/v3/"></script> <div class="modal-dialog modal-lg"> <require from="../../../css/stylesheet.css"></require> <div class="modal-content"> <div class="modal-header"> <h4>Payment</h4> <button type="button" id="stripe-modal-close" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body"> <form class="stripe-form" submit.delegate="getToken()"> <div class="group"> <label class="stripe-label"> <span>Title</span> <input id="name" class="stripe-field" placeholder="Jane Doe" /> </label> <label class="stripe-label"> <span>Card</span> <div id="card-element" class="stripe-field"></div> </label> </div> <button class="btn btn-outline-dark my-3" type="submit">Pay $25</button> <div class="stripe-outcome"> <div class="stripe-error"></div> </div> </form> </div> </div> </div>
CSS
.group { background: white; box-shadow: 0 7px 14px 0 rgba(49,49,93,0.10), 0 3px 6px 0 rgba(0,0,0,0.08); border-radius: 4px; margin-bottom: 20px; } .stripe-label { position: relative; color: #8898AA; font-weight: 300; height: 40px; line-height: 40px; margin-left: 20px; display: flex; flex-direction: row; } .group label:not(:last-child) { border-bottom: 1px solid #F0F5FA; } .stripe-label > span { width: 80px; text-align: right; margin-right: 30px; } .stripe-field { background: transparent; font-weight: 300; border: 0; color: #31325F; outline: none; flex: 1; padding-right: 10px; padding-left: 10px; cursor: text; } .stripe-field::-webkit-input-placeholder { color: #CFD7E0; } .stripe-field::-moz-placeholder { color: #CFD7E0; } .stripe-button { float: left; display: block; background: #666EE8; color: white; box-shadow: 0 7px 14px 0 rgba(49,49,93,0.10), 0 3px 6px 0 rgba(0,0,0,0.08); border-radius: 4px; border: 0; margin-top: 20px; font-size: 15px; font-weight: 400; width: 100%; height: 40px; line-height: 38px; outline: none; } .stripe-button:focus { background: #555ABF; } .stripe-button:active { background: #43458B; } .stripe-outcome { float: left; width: 100%; padding-top: 8px; min-height: 24px; text-align: center; } .stripe-success, .stripe-error { display: none; font-size: 13px; } .stripe-success.visible, .stripe-error.visible { display: inline; } .stripe-error { color: #E4584C; } .stripe-success { color: #666EE8; } .stripe-success .stripe-token { font-weight: 500; font-size: 13px; }
source share