【发布时间】:2021-09-06 19:58:19
【问题描述】:
我有一个支付系统,用户可以在其中将多张卡添加到应用程序中。现在可以有 4 张 AM Express 卡或 10 张 Visa 卡。但是,我希望当用户尝试添加已添加的卡时,我应该返回已添加的卡,说明您已添加卡,或者我可以更新已添加的卡,然后返回。
我经历了一些线程,它们说要检查指纹值,然后只更新卡,但这没有意义。有没有更明确的方法来做到这一点?
我的卡片是这样添加的
public async addNewCard(customerId: string, newCardRequest: NewCardRequest): Promise<Card> {
const stripeCustomerId = await this.getStripeCustomerId(customerId);
if (!stripeCustomerId) {
const stripeCustomer = await this.createStripeCustomer(customerId, newCardRequest.token, newCardRequest.nameOnCard);
const card = await this.stripeApi.getCard(stripeCustomer.id, stripeCustomer.defaultPaymentMethodId);
return Card.fromStripeCard(card);
} else {
const card = await this.stripeApi.addCard(stripeCustomerId, newCardRequest.token, { nameOnCard: newCardRequest.nameOnCard});
return Card.fromStripeCard(card);
}
}
条带化客户端服务
public async addCard(customerId: string, token: string, metadata?: Stripe.MetadataParam): Promise<Stripe.CustomerSource> {
const sourceCreateParams: Stripe.CustomerSourceCreateParams = {
source: token,
metadata
};
return await this.stripeClient.customers.createSource(customerId, sourceCreateParams);
}
【问题讨论】: