1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

laravel cashier hasDefaultPaymentMethod()は使わないほうがいいかも・・?

Last updated at Posted at 2023-12-20

概要

laravel cashierのhasDefaultPaymentMethod()の仕様を調べていたところ若干不安になる仕様だったのでまとめる。

メソッドの仕様

当該のメソッドはvendor/laravel/cashier/src/Concerns/ManagesPaymentMethods.phpに定義されている。

vendor/laravel/cashier/src/Concerns/ManagesPaymentMethods.php
/**
 * Determines if the customer currently has a default payment method.
 *
 * @return bool
 */
public function hasDefaultPaymentMethod()
{
    return (bool) $this->pm_type;
}

ようはpm_typeに値が入っていればtrue、入っていなければfalseが返るっぽい。

じゃあpm_typeの出処はどこなのかというとusersテーブルのpm_typeのカラムっぽい。
ただ、このカラムの値はどうやら「最終支払いの支払い方式を保存する」というものらしい。ようはSetup IntentなどでクレカIDと顧客を紐付ける処理を行ったときにpm_typeは特に更新されないっぽい。

このとき何が問題かというと、下記のようなケースで「true」になって欲しいのに「false」になる。

「Setup Intentを使ってクレカを登録した。支払い前にデフォルト支払い方法が設定されているか確認したくてhasDefaultPaymentMethod()を実行した。

hasDefaultPaymentMethodという名前が誤解を招いている気がする。

所感

hasDefaultPaymentMethod()ではなくhasPaymentMethod()を使ったほうがいいかも。

参考文献

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?