php - Laravel Cashier paymentMethods() 总是返回空对象结果

标签 php laravel-5 stripe-payments laravel-cashier

  • 收银版:^10.5
  • Laravel 版本:^6.0
  • PHP 版本:7.3.5
  • 数据库驱动程序和版本:

描述:

paymentMethods() 始终检索具有空对象的数组。

public function userAllPaymentMethods(Request $request)
    {
        $user = User::find(5);
        $paymentMethod = $user->paymentMethods();
        return response($paymentMethod);
    }

结果: https://www.screencast.com/t/aqenaud77A

也可以使用 Stripe PaymentMethod 库。

public function userAllPaymentMethods(Request $request)
    {
        $user = User::find(5);
        \Stripe\Stripe::setApiKey('{{KEY}}');
        $paymentMethod = \Stripe\PaymentMethod::all([
            'customer' =>  $user->stripe_id,
            'type' => 'card',
        ]);

        return response($paymentMethod);
    }

结果:
https://www.screencast.com/t/X14ane7WyqS

GitHub : here

最佳答案

$paymentMethods = $user->paymentMethods()->map(function($paymentMethod){
        return $paymentMethod->asStripePaymentMethod();
    });

关于php - Laravel Cashier paymentMethods() 总是返回空对象结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58898278/

相关文章:

laravel - 如何使用Laravel 5在Elasticsearch中分页

flutter - stripe 中的 firebase 动态链接抛出 err_unknown_url_scheme

php - LinkedIn API OAuth 刷新 token

php - 来自 BASH 的 Tcpdump

Laravel:webhooks 需要绕过 Laravel 的 CSRF 验证

php - 如何在 laravel 5.1 中检索访问者的 ip 地址

flutter - 如何保存信用卡以供以后使用 Flutter 应用程序和 Firebase 进行 Stripe 支付?

javascript - Stripe 卡元素默认邮政编码

php - 多列的 String_agg

php - Codeigniter 在此服务器上找不到请求的 URL