PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] Passing Stripe Payment Methods to Laravel View

 January 20, 2022     laravel, laravel-5, stripe-payments     No comments   

Issue

I am trying to load previously used cards using the Stripe API using Laravel using this link from Stripe https://stripe.com/docs/api/payment_methods/list?lang=php

Here is the snippet of code from my controller:

 $stripe = new \Stripe\StripeClient(
            'sk_test_51GueZuLq4MEy
          );


    $customer_id = "cus_HhnBT9fpjxW3hn";
    
    $paymentMethods = $stripe->paymentMethods->all([
            'customer' => $customer_id,
            'type' => 'card',
          ]);
    
    $pm = ($paymentMethods->data);
    
    return view('payment.details', $pm);

However when I am trying to pass the card data into my view I am unable to do so. The variable I am passing in views is:

{{ $pm }}

The error message I get is that my variable is not recognised. The data I am trying to access is $paymentmethods->-data->card->last4

Any help is always appreciated


Solution

$stripe->paymentMethods->all returns an object with a data attribute, where the data is an array of PaymentMethods, in this case, you'll likely want to access the first element of data.

Try updating to:

$pm = $paymentMethods->data[0];


Answered By - cjav_dev
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing