Stripe js 未显示选定的主题样式 - Angular 12
这是我第一次将 Stripe.js 集成到 Angular 项目中。 我已经阅读了文档并实现了它(条纹卡元素方法)。 Stripe 已实现,并在一个输入字段中向我显示卡片元素。 我不需要单个输入字段,我正在寻找条纹元素的预构建主题。 我添加了外观和客户端密钥,但没有选择主题。
付款组件.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-payment',
templateUrl: './payment.component.html',
styleUrls: ['./payment.component.css']
})
export class PaymentComponent implements OnInit {
constructor() {
}
ngOnInit(): void {
const clientSecret = 'seti_1KawGlBBpoL4ww8PpzEwfTAU_secret_LHVHt3qcV8Cznw8b00vvFUVaaCFbLnc';
const appearance = {
theme: 'flat'
};
var stripe = Stripe('pk_test_51JkpiuBBpoL4ww8PpO2UfKSTE7M84aESVyaKUCWBqkxwQ3LRgOpQ2fh7hH4hxb2V9sA3e8DwvVIWoHurhryqdAHp00HVNutZkg');
var elements = stripe.elements({ clientSecret, appearance});
var cardElement = elements.create('card');
cardElement.mount('#card-element');
}
}
付款组件.html
<form action="/charge" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">Credit or debit card</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
</div>
<button>Add payment source</button>
</form>
我得到的输出 条纹输出
我需要的主题看起来很相似 主题输出
This is my First time that I am integrating Stripe.js in angular project.
I have gone through documentation and implement it (Stripe Card Element Method).
Stripe implemented and showing me card element in one input field.
I don't required single input field, I am looking for pre built themes for stripe element.
I added Appearance and client secret but does not picking the theme.
payment-component.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-payment',
templateUrl: './payment.component.html',
styleUrls: ['./payment.component.css']
})
export class PaymentComponent implements OnInit {
constructor() {
}
ngOnInit(): void {
const clientSecret = 'seti_1KawGlBBpoL4ww8PpzEwfTAU_secret_LHVHt3qcV8Cznw8b00vvFUVaaCFbLnc';
const appearance = {
theme: 'flat'
};
var stripe = Stripe('pk_test_51JkpiuBBpoL4ww8PpO2UfKSTE7M84aESVyaKUCWBqkxwQ3LRgOpQ2fh7hH4hxb2V9sA3e8DwvVIWoHurhryqdAHp00HVNutZkg');
var elements = stripe.elements({ clientSecret, appearance});
var cardElement = elements.create('card');
cardElement.mount('#card-element');
}
}
payment-component.html
<form action="/charge" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">Credit or debit card</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
</div>
<button>Add payment source</button>
</form>
Output I got
Stripe Output
Theme I required looks alike
Theme output
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您显示的示例是
payment 元素,但您在代码中使用
card 元素。
Elements Appearance API 不支持单独的付款方式 Elements(例如 CardElement)您应该使用
elements.create(' payment')
(API) 创建payment
元素。the example you showed is
payment
element but you are usingcard
element in your code.The Elements Appearance API doesn’t support individual payment method Elements (such as CardElement) You should use
elements.create('payment')
(API) to create apayment
element.