jsrosas
jsrosas

Reputation: 103

Laravel use Stripe\Customer as StripeCustomer in Controller throws Error

I am having an issue trying to use StripeCustomer in a controller. I need to retrieve a customer from Stripe. So I have on my controller : use Stripe\Customer as StripeCustomer; I see in cashier's Billable.php being used this way. But I try to use it in the controller I get

Could not determine which URL to request: Stripe\Customer instance has invalid ID:

Any ideas how to use Stripe\Customer within a controller? Is there a scope of namespace? Thanks in advance.

Upvotes: 0

Views: 1056

Answers (1)

Rik Heywood
Rik Heywood

Reputation: 13972

Looks a little like the code is being found just fine, so there is probably nothing wrong with your use statement.

The error message suggests you are trying to manipulate, or work with, an uninitialised Stripe\Customer object.

Your code should a little like this (taken from Stripes docs)

\Stripe\Stripe::setApiKey("sk_test_KZ3pTiXRPJ1gpqLlKlEGA3bY");
$customer = StripeCustomer::retrieve("cus_8gZXNXuq2kIsQv");
// work with $customer here... (assumes your use statement from the question)

Upvotes: 3

Related Questions