LoginSignup
1
0

More than 1 year has passed since last update.

Stripeのsubscriptionsで `This customer has no attached payment source or default payment method.` エラーが出て決済処理ができない

Posted at

背景

  • StripeConnectを用いてプラットフォームを構築したかった
     const result = await stripe.subscriptions.create({
          customer: customerId,
          items: [
            {
              price: priceId,
            },
          ],

          application_fee_percent: 10,
          transfer_data: {
            destination: connectAccountId,
          },
      }, {
          idempotencyKey: idempotencyKey,
      });
  • こんな感じでサブスク決済を実行したかったが、決済処理が This customer has no attached payment source or default payment method. とのエラーがでて実行できない。

対応

      const result = await stripe.subscriptions.create({
          customer: customerId,
          items: [
            {
              price: priceId,
            },
          ],
          // consumerのpayment_methodを取得してきて、明示的に指定した。
          default_payment_method: paymentMethodList.data[0].id,
          application_fee_percent: 10,
          transfer_data: {
            destination: connectAccountId,
          },
      }, {
          idempotencyKey: idempotencyKey,
      });
  • 上記の対応で、無事APIが通って、サブスク課金を実装できました。

スクリーンショット 2021-07-30 14.01.58.png

備考

default_payment_method
optional
ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over default_source. If neither are set, invoices will use the customer’s invoice_settings.default_payment_method or default_source.

APIドキュメントに、 customerinvoice_settingsdefault_payment_method に設定しても同様のことができるよと記載があるのでそちらを設定した方がbetterなのかもしれない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0