angular - 如何在 ngx stripe angular 中获取输入的卡片详细信息
问题描述
嗨,伙计们,我目前正在通过 ngx-stripe 文档使用 angular ngx-stripe,当我通过卡号和 mm/yy cvc 时,我在其中获取令牌。但我想获取输入的卡号,mm/yy cvc。这样我就可以传递到后端。是否可以检索输入的详细信息。请帮助我。
html
<h2>Create Token Example</h2>
<ngx-stripe-card
[options]="cardOptions"
[elementsOptions]="elementsOptions"
></ngx-stripe-card>
<button type="submit" (click)="createToken()">
CREATE TOKEN
</button>
TS
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { StripeService, StripeCardComponent } from 'ngx-stripe';
import {
StripeCardElementOptions,
StripeElementsOptions
} from '@stripe/stripe-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild(StripeCardComponent) card: StripeCardComponent;
cardOptions: StripeCardElementOptions = {
style: {
base: {
iconColor: '#666EE8',
color: '#31325F',
fontWeight: '300',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSize: '18px',
'::placeholder': {
color: '#CFD7E0'
}
}
}
};
elementsOptions: StripeElementsOptions = {
locale: 'en'
};
stripeTest: FormGroup;
constructor(private fb: FormBuilder, private stripeService: StripeService) {}
ngOnInit(): void {
this.stripeTest = this.fb.group({
name: ['', [Validators.required]]
});
}
createToken(): void {
const name = this.stripeTest.get('name').value;
console.log(name);
this.stripeService
.createToken(this.card.element, { name })
.subscribe((result) => {
if (result.token) {
// Use the token
console.log(result.token.id);
} else if (result.error) {
// Error creating the token
console.log(result.error.message);
}
});
}
}
解决方案
我认为这个想法是您永远不会看到卡号,因此不会承担安全责任。
该过程几乎由 Stripe 通过 iframe 处理。您需要做的就是在您的服务器上验证支付意图,这会创建一个安全的密钥/令牌,该密钥/令牌会传回您的客户端,然后发送给 Stripe 进行收费。
我是新手,这个过程最初并不明显。我认为其他支付提供商提供了类似的流程。
推荐阅读
- matlab - 我的 Matlab 的 PSF 代码错过了什么?
- saml-2.0 - 为什么 ITfoxtec 强制执行注销请求以进行签名?
- sql-server - 带条件和计数的 SQL 查询语句
- angular - Angular 9:BehaviorSubject 不适用于远程数据
- javascript - 如何在 react-three-fiber 中初始化 useFrame() 之外的对象
- node.js - 如何使用 URL 连接到 MongoDB 服务器?
- javascript - socketio webapp没有运行
- python - 将 pybind11 绑定标记为已弃用的最佳方法
- android - Android 10:Android Q:NDK:到 /dev 的 opendir 失败并出现 errno 13:权限被拒绝
- kubernetes - Neo4j:Neo.ClientError.Cluster.NotALeader