【问题标题】:Stripe do not add duplicate card nodejsStripe 不添加重复卡 nodejs
【发布时间】: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);
  }

【问题讨论】:

    标签: node.js stripe-payments


    【解决方案1】:

    我经历了一些线程,说要检查指纹值,然后只更新卡,但这没有意义。

    检查fingerprint 是解决此问题的正确方法。 Card objects in Stripe have a fingerprint property 正是为了这个目的(强调):

    唯一标识此特定卡号。 例如,您可以使用此属性来检查与您注册的两个客户是否使用相同的卡号。对于将卡信息标记化的支付方式(Apple Pay、Google Pay),可能会提供标记化的号码而不是基础卡号。

    它的工作方式是,如果您在 Stripe 中有两个或多个 Card 对象,您可以比较它们的 fingerprint 值,如果它们匹配,则这些 Card 对象代表同一张实体卡。

    所以,实际上,你会这样做:

    1. 客户提供卡信息
    2. 您根据该信息在 Stripe 中创建一个 Card 对象
    3. 您将该卡的fingerprint 与客户存档的所有其他卡进行比较
    4. 如果任何现有的fingerprint 匹配,请让客户知道您已经将该卡存档,否则您将新卡附加给客户

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 2017-03-13
      • 2013-07-13
      • 2015-05-08
      • 2021-07-15
      • 2017-04-20
      • 2018-03-04
      • 1970-01-01
      • 2020-06-24
      相关资源
      最近更新 更多