【问题标题】:How can I pay Stripe with saved credit card?如何使用保存的信用卡支付 Stripe?
【发布时间】:2020-06-16 06:23:50
【问题描述】:

我使用Intent API(currency, amount only)confirmCardPaymentStripe rendered HTML input 进行结帐。

现在我想实现保存的信用卡,可以保存,但是不知道怎么用传递给confirmCardPayment

我目前工作的confirmCardPayment 代码是这样的

Stripe.confirmCardPayment(intent.client_secret, {
  payment_method: {
    /**
     * I'm using Vue here
     * If I'm using a saved card, what should I pass here?
     **/
    card: this.$refs.stripeCardRef.cardNumberElement,
  },
  setup_future_usage: "off_session",
});

如果我使用的是已保存的卡,我应该将什么传递给 confirmCardPayment,以及 Intent API(我使用的是货币,现在只需要金额)?

所以我可以使用stripe.paymentMethods.list 来获取客户所有保存的信用卡,并将其返回到前端,如下所示:

// Server
export async function listPaymentMethods(userId: string) {
  const customer = await getOrCreateCustomer(userId);

  return stripe.paymentMethods.list({
    customer: customer.id,
    type: "card",
  });
}

然后,我的前端得到这样的响应

{
  "object": "list",
  "data": [
    {
      "id": "pm_1GuBTiICxYQTNr22LwKB6rfy",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": null,
          "country": null,
          "line1": null,
          "line2": null,
          "postal_code": null,
          "state": null
        },
        "email": null,
        "name": null,
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": null,
          "address_postal_code_check": null,
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 1,
        "exp_year": 2023,
        "fingerprint": "riI755UKjfafxa3C",
        "funding": "credit",
        "generated_from": null,
        "last4": "4242",
        "networks": {
          "available": ["visa"],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1592201250,
      "customer": "cus_HPOXLjeqF24rBn",
      "livemode": false,
      "metadata": [],
      "type": "card"
    }
  ],
  "has_more": false,
  "url": "/v1/payment_methods"
}

我如何使用这个回复数据到confirmCardPayment? 我的意图 API 是否也需要更改?

【问题讨论】:

标签: stripe-payments


【解决方案1】:

Stripe 的文档在此处介绍了此流程:https://stripe.com/docs/payments/save-and-reuse#web-create-payment-intent-off-session

这个想法是,当您像这样确认 PaymentIntent 时,您会传递现有的 PaymentMethod id pm_12345 client-side:

stripe.confirmCardPayment(
  intent.client_secret,
  {
    payment_method: intent.last_payment_error.payment_method.id
  }
).then(function(result) {
  if (result.error) {
    // Show error to your customer
    console.log(result.error.message);
  } else {
    if (result.paymentIntent.status === 'succeeded') {
      // The payment is complete!
    }
  }
});

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2017-09-12
    • 2018-01-29
    • 2021-02-23
    • 1970-01-01
    • 2013-04-29
    • 2010-11-29
    • 2018-12-22
    • 2019-06-24
    相关资源
    最近更新 更多