Closed Yorchi closed 7 years ago
Did you manage to fix this issue. I am still having it?
hi @JosephSmith127, yes still having this issue, what am I doing wrong?
@andradedev Wish I knew! Literally have just been faced with this issue. Will make sure I post a solution when I find one!
@andradedev I managed to fix. Make sure in your config > services.php you also include the key as well as the secret:
'stripe' => [ 'model' => App\User::class, 'key' => env('STRIPE_KEY'), 'secret' => env('STRIPE_SECRET'), ],
hi @JosephSmith127, I already have the API SECRET, but where do I find the API KEY?
sorry, but im new with cashier and stripe :(
@andradedev if you go to stipe.com and open up your settings, under API keys
Publishable key = API KEY Secret Key = API SECRET
Hope this helps :)
+1
I am having the same issue with fresh install of latest stable release even with both KEY and SECRET set.
The issue is only in live mode, in test its ok!
@paulocastellano You mean the Stripe modes test/live? I have Stripe in Test mode and am experiencing this issue.
For me issue is only in live mode, in test its ok.
But i using laravel 5.2, cashier 6.0
@paulocastellano Hmm, I have the same setup but it's not working in either mode. Which Stripe API version are you using?
@staticwave "laravel/cashier": "~6.0"
@paulocastellano I was asking about your Stripe API version. Mine is '2015-10-16 (latest)' in Stripe account settings.
@staticwave me too!
@paulocastellano Thanks for the info. Hope to get this resolved soon.
@staticwave i finding on web the solution and trying find the core code
@staticwave i found the solution, set us key in .env!
if u set in services not work
@paulocastellano That did it! Thanks.
@paulocastellano @staticwave i having the same trouble, i have set the STRIPE_API_SECRET in .env and call it in services.php, now its giving me error like "The second argument to Stripe API method calls is an optional per-request apiKey". any help??
@MicroDreamIT Make sure you have both stripe key and stripe secret in .env
@staticwave i dont understand the difference, between stripe key and stripe secret. I have only "test secret key" and "test publishable key". Please help me... :)
@MicroDreamIT stripe key = publishable key and stripe secret = secret key. Make sure they're both set in .env and use them in services config
@staticwave my services.php is look like this brother,
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_PUBLISHABLE_KEY'),
'secret' => env('STRIPE_API_SECRET'),
],
I am using cashier 6.0 in laravel 5.2
@MicroDreamIT That looks right. In Stripe dashboard where the API keys are, there's a publishable key and a secret key. Set them accordingly in .env
@MicroDreamIT Here's what mine look like .env
STRIPE_KEY=pk_test_....
STRIPE_SECRET=sk_test_...
config/services.php
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'), //publishable key
'secret' => env('STRIPE_SECRET'), //secret key
],
@staticwave lets see brother, you are helping me a lot to develop this things, its really helping me a lot... :+1:
@staticwave Brother, almost there, now in my stripe account,
in my app,
***but subscriptions table is not updated in DB, now its telling me
InvalidRequest in ApiRequestor.php line 103: No such plan: small; one exists with a name of small, but its ID is 1.
here code in my controller
$creditCardToken=$request->input('stripe-token');
Auth::user()->newSubscription('main', $request->input('plan'))->create($creditCardToken);
return "done";
@staticwave I have done every thing stated above but it isn't working. My .env file looks like
STRIPE_API_KEY=sk_test_mytestkey
STRIPE_API_PUBLISHABLE=pk_test_mypublish_key
And my services.php file looks like
'stripe' => [
'model' => 'User',
'key' => env('STRIPE_API_PUBLISHABLE'),
'secret' => env('STRIPE_API_KEY'),
]
And this is my controller
$user = Sentinel::getUser();
$user->newSubscription('main', 'plan_monthly')->create(Input::get('_token'));
And it is always throwing error
The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string, or per-request options, which must be an array. (HINT: you can set a global apiKey by "Stripe::setApiKey(
One more thing my strip account isn't activated yet. Is it the reason? And second I am using laravel cashier 6.0 of laravel 5.2 in my laravel 5.1
I have also tried
Stripe::setApiKey('sk_test_mytestkey');
by setting in controlller and in appserviceprovider file but every time I am getting same.
@sjaved193 step by step
STRIPE_SECRET = stripe secret key
STRIPE_KEY= stripe publishable key
'stripe' => [
'model' => App\User::class,
'secret' => env('STRIPE_SECRET'),
'key' => env('STRIPE_KEY')
],
Stripe.setPublishableKey('your_stripe_publishable_key');
important two line, make sure you are getting stripe token
form.append($('<input type="hidden" name="stripe-token" value="response.id">').val(token));
form.submit();
$creditCardToken=$request->input('stripe-token');
Auth::user()->newSubscription('main', $request->input('plan'))->create($creditCardToken, ['email'=>Auth::user()->email]);
let us know how you are doing, if you would it better ways, please share with us. Thank you
The problem back with me, and i dont make nothing :/
@paulocastellano where is the problem?
The problem is:
The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string, or per-request options, which must be an array. (HINT: you can set a global apiKey by "Stripe::setApiKey(
The problem back but i have keys in .env!
The problem is only in live mode, in testing its ok!
publishable key has to be on scripts as well
like
Stripe.setPublishableKey('pk_test_****);
In my view i have:
Stripe.setPublishableKey('pk_live_MYKEY');
And in controller i receive this token!
strange !!!
Much bro!
I thinking in remove cashier and use pure -> https://github.com/stripe/stripe-php
@paulocastellano that will be great
@MicroDreamIT, using stripe-php pure, and same error! WTF?
Thanks @MicroDreamIT , setting up my .env was the missing link. The 5.2 documentation doesn't seem to reference configuring .env at all. It's a little confusing because it says setup services.php with 'secret' => env('STRIPE_API_SECRET') and doesn't reference a key.
On top of that, when (Billable)::newSubscription(str, str)->create(stripeToken) makes a new customer to auto sync this information with a subscriptions database, it uses \Laravel\Cashier\Billable::getStripeKey which is actually looking for getenv('STRIPE_SECRET') not STRIPE_API_SECRET.
services.php
'stripe' => [
'model' => App\Account::class,
'secret' => env('STRIPE_SECRET'),
'key' => env('STRIPE_KEY')
],
Note: I'm using App\Account as my Billable.
.env
STRIPE_SECRET=sk_test_(blah)
STRIPE_KEY=pk_test_(blah)
.js (handling credit card stripe token generator) via https://stripe.com/docs/tutorials/forms with validation support from https://github.com/stripe/jquery.payment
With the subscription table intact, I ran
$account->newSubscription($data['name'], $data['package'])->create($creditCardToken, [
'description' => $data['description']
]);
And it successfully added a record to my subscriptions table, and the desired POST request showed up on my stripe logs. I'm no where near done, but it's progress. I hope some of this information helps, good luck!
For me the issue was I was manually setting the key in the services.php file while the method getStripeKey
requires it to be set as an ENV variable or set manually using setStripeKey
.
This function getStripeKey
should really just use the Laravel Config
facade to get the details from services.php.
I just tweaked my .env keys to match what @westcrosby suggested and this fixed it for me. Annoying.
Well, not exactly. Now in my seeder I get a step further. With the exact same code above I get:
Could not determine which URL to request: Stripe\Token instance has invalid ID:
I agree with @dubcanada. The Billable trait should primarily reference the Laravel config file. The solution for me was to override the getStripeKey() function in my Billable model.
I began receiving the following error after migration a development site to production The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string, or per-request options, which must be an array.
I read through this issue, and did some manual testing. What I found, is that getenv('STRIPE_SECRET')
and env('STRIPE_SECRET')
both returned null, while config('services.stripe.secret')
would return my key.
Given that the Cashier method getStripeKey()
uses getenv('STRIPE_SECRET')
I decided to overwrite it directly on my User model to instead use config('services.stripe.secret')
. After doing such, I stopped receiving the aforementioned error message and stripe went back to working as intended.
A simple php artisan config:clear
should fix your problem.
@cklmercer Really surprised that isn't the default behavior. Using the getenv() function when using the built in Laravel route caching seems to break Cashier. Disabling route caching fixes it right away.
Having the same problem in Stripe test. Everything used to work in test, when I created a new plan in Stripe, now I get the error.
Error
No such plan: monthly; one exists with a name of monthly, but its ID is primary.
Controller
$user->newSubscription('primary', 'monthly')->create($token, [ ]);
Plan details
ID: primary
Name: monthly
Price: $19.99 USD/month
Trial period: No trial
php artisan config:clear doesn't help
@cvcv01 Use this : $user->newSubscription('primary', 'primary')->create($token, [ ]);
I having this error at try to use this.