The documentation is up to date for sure, so just share what is not clear to you or how did you try to use it and maybe someone here can explain to you what you are doing wrong and how to use it correctly. And here is a text from the maintainer of Laravel, he will not put a link to the new documentation if it wasn't updated.
How to use Cashier v10 in Laravel 6
Hi
Where can I find a good tutorial on how to use Cashier v10 and Laravel 6
The latest documentation is not very clear and the 'samples' are not working or is not very clear on how to use
Thanks
Sorry, but the link you shared is not even close to explaining how to use Cashier end-2-end
If you start from the top of the documentation and then start to code as you read, there is no clear flow, there are a snippet of 'html' get the card holder name and display a button, and then some JS code that is not complete.
This is a 'example' of how to use Cashier in Laravel 5, and is more what I am looking for https://www.itsolutionstuff.com/post/laravel-5-stripe-example-using-laravel-cashier-from-scratchexample.html
@rabol the documentation is not a place to show you how to do your job step by step. Use a tutorial for it, so if there is none out there yet, use an older version like the one you shared and adopt it based on the documentation for the latest Laravel release. You will easily find the changes, what worked in a previous version and does not works now looking at the upgrade guides.
Please read the subject and the very first line of the post, thanks
@rabol sorry, I didn't read your message and directly responded. Here:
And making fun of people is not nice... Your 'joke' is tasteless and utterly childish
and does not work
@rabol I am sorry. You told me that I haven't read your question when I did and I completely understood what you are asking for. But the forum is here to help you with what you got stuck with, not to help you search on Google.
I will ask you again, what have you tried, from the tutorials that already exist, and what doesn't work for you, so someone here can help, that's what this place is for.
The documentation is also there to showcase the features not to show step by step on how Cashier to be used, as every case is different.
Or you maybe expect that someone will write a full tutorial for you here on how to use cashier with Laravel 6?
@rabol No there are no such tutorial at the current moment. I would suggest either reading older tutorials and trying to update the code to work with cashier 10, or waiting some time. I am sure given time, a tutorial pops up on medium
Thanks, I'm reading old tutorial and comparing with the stripe doc's on the flow and it looks like a lot of things have changed
e.g. that one have to create a 'session' etc. to be SCA compliant in EU
I'm making a lot of notes and when done I'll publish the result
@rabol I'm in the same boat.... I've watched the Laracast video multiple times, read the Cashier docs multiple times, compared to the Laravel 5 tutorial code, and no matter what I try I can't get the Stripe Intent for adding a payment method to work and so have no way to use Cashier without going back to an earlier version (I want to use the latest and be SCA compliant).
In case it helps the mods to feel motivated that this is a legitimate shortcoming of the docs being too sparse on detail: I'm a developer with 20 years experience and some pretty awesome accolades. I'm new to Laravel, and really hoping to stay with it longer term. Hitting walls like this is frustrating (2 days of troubleshooting so far). The tooling and community are otherwise good. Please help :)
More detail in the docs about how to add a payment method would be great. Specifically, what could a Route look like if you want to use HomeController@addPaymentMethod to handle the Stripe Intent? (Of course a SubscriptionController, or perhaps a PaymentMethod controller is better... am just trying to do decent first test using php artisan ui --auth template code.
...one snippet away from joy
@geser now this is straight to the point question. Have you looked at the GitHub issues that were opened for this case
And it seems like this PR was merged
@nakov Re: "now this is straight to the point question." ...just looking for a straight-forward how-to... [nice attitude for a mod. we're all newbs to start with] @nakov Re: "Have you looked at the GitHub issues that were opened for this case" 20 screens & 20mins later... yes... and no clear solution.
The migration guide is the most explicit resource I've found. It's convoluted to have to go from Laravel 5/Cashier9 through the migration guide in order to have something that works with Laravel6/Cashier10.
I'll work through some of the more general L6 best practices and see if I can figure out Cashier 10 later.
OR, if you really want to help. How about correcting me where I'm going wrong.
-
composer create-project --prefer-dist laravel/laravel cashiertest -
cd cashiertest -
composer install -
composer require laravel/ui -
php artisan ui --auth - [edit your .env for DB]
-
php artisan migrate -
npm install && npm run dev - Edit RegisterController.php with
$user->createAsStripeCustomer();in functioncreate() - Create
AddPaymentMethod.blade.phpwith the Stripe payment method form from docs - Update your Routes/web.php and test
- Read tons of stuff and have a rendered form that appears to work but fails silently
- composer require composer require barryvdh/laravel-debugbar --dev and tinker whilst wonder about the meaning of life
- Explore the Laravel5/Composer9 code that works and try to reconcile 1000s of differences
- Ask forum for help and wonder at toxicity of mods
Thanks in advance for any help
@geser sorry that you've got the wrong impression, I am no mod whatsoever, and I am not toxic in anyway, just tried to share some links that I've found. Will apply the steps that you've shared and If I get it right somehow will share it with you.
The OP was asking for a full tutorial, that's why I said your question is straight to the point, as now everyone knows what does not work and try to help.
Anyhow, sorry once again if you've got the wrong impression from me, as I am not trying to be rude here.
@geser I'm using Homestead on a Mac so I have slightly different steps
- Create a new site in Homestead.yaml
- homestead ssh
- cd code
- laravel new cashier
- cd cashier
- composer require laravel/ui --dev
- composer require barryvdh/laravel-debugbar --dev
- php artisan ui vue --auth
- edit your .env for DB
- npm install && npm run dev
- composer require laravel/cashier
- php artisan migrate
- edit env to add strip keys and cashier currency
- add the Billable trait uo the User Model
- Edit RegisterController.php with $user->createAsStripeCustomer(); in function create()
- php artisan make:controller AddPaymentMethodController
- in the index method, check to see if the user have a stripe_id, if not call $user->createAsStripeCustomer();
- Create AddPaymentMethod.blade.php with the Stripe payment method form from docs
- Update your Routes/web.php and test
I have created a github repository : https://github.com/rabol/laravel-cashier-demo There is no code yet, but I will do it tomorrow and continue to update with progress
@nakov Here is some very specific question: This is from the documentation, but it does not work.
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Add payment method</div>
<div class="card-body">
@if($errmsg)
<div class="row">{{ $errmsg }}</div>
@endif
<div class="form-group row">
<input id="card-holder-name" type="text">
</div>
<div class="form-group row">
<!-- Stripe Elements Placeholder -->
<div id="card-element"></div>
<button id="card-button" data-secret="{{ $intent->client_secret }}">Update Payment Method</button>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('after-scripts')
<script>
const stripe = Stripe('{{config('cashier.key')}}');
const elements = stripe.elements();
const cardElement = elements.create('card');
cardElement.mount('#card-element');
const cardHolderName = document.getElementById('card-holder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', async (e) => {
const { setupIntent, error } = await stripe.handleCardSetup(
clientSecret, cardElement, {
payment_method_data: {
billing_details: { name: cardHolderName.value }
}
}
);
if (error) {
// Display "error.message" to the user...
//alert('error');
console.log('error');
} else {
// The card has been verified successfully...
console.log('ok');
}
});
</script>
@endpush
There is no error messages in the console, and the 'input' is not transformed into a 'credit card' entry field
@rabol yup, just tried the same :) and as @geser said it "seems" like it works, but it actually does not. It returns successfully, it returns even a payment id, but it is not attached to the customer. So here is what I did
I am using server side to add a Payment method and it does work for sure :) ofc I am hard-coding the test card there, but you can easily get it from the request.
At the end, it turns out it is more of a Stripe problem then Laravel/Cashier. Because the JS part does not work which is completely Stripe's library as far as I know.
So download my code and try it out, and let me know.
Once again guys, sorry if I sounded very rude, that was not my intention, I just want to help out here.
Here is an important note from the Strip documentation:
"When you use Elements, all payment information is submitted over a secure HTTPS connection. The address of the page that contains Elements must also start with https:// rather than http://. You can test your integration without using HTTPS, and enable it once you’re ready to accept live charges. For more information about getting SSL certificates and integrating them with your server to enable a secure HTTPS connection, see our security documentation."
Could it be that our 'elements' ar not rendered when using http?
@rabol I tested using HTTPS, and as @geser pointed out, the payment returns a successful status, so the request passes through completely. But it is not attached to the account for some reason. But there is something going on in the stripe.js library, has nothing to do with Cashier.
Also SSL is more important as it says in this piece of information that you've shared for the live charges, not for testing purposes I believe.
I got one step closer, I did a self-signed SSL certificate
I now have the 'correct' Credit card input control
@rabol what I did in the JS code, I printed out in the console the response:
if (error) {
console.log(error);
} else {
console.log('Card has been verified', setupIntent.payment_method);
}
So this goes to success, and prints out a payment_method but it was never attached to my Customer when I looked at the Stripe dashboard, nor when I printed the $user->paymentMethods();
For some reason i do not even get anything printed in the console
Does the request happens? Check your Network tab.
hmmm... Nope, nothing happens when I press the pay button
@rabol so it seems like your JS code is not running at all, try debugging before the event, is the click event attached to the button? Any error in the console? Instead of the handleCardSetup request, try printing something to the console to make sure that the click event is fired.
Look at this: https://laracasts.com/discuss/channels/general-discussion/no-such-thing-as-a-dumb-question
Then in my controller i have this:
$paymentMethod = $request->input('stripePaymentMethod');
$user = auth()->user();
$user->addPaymentMethod($paymentMethod);
return redirect(route('home'));
and I had to 'disable' some Vue things
Great :) so again the attachment happens server side. I thought that just using the client side code it should be done. Anyhow this is similar to what I have, except for the fact that I do everything server side with just one call :)
One small problem I see with your version is that the credit card is not validated and you say that it does not show up in the Stripe dashboard. The version i have ensure that the credit card is valid and it shows up on the “customer” in Stripe.
But this part is only a small piece in the puzzle.
I still need to do the actual payment.
And I need to figure why the Vue.js screw up the call to Strip to validate the card
@rabol I still use Stripe element on the front-end that validates the card, and it shows what type it is, ie Visa or Master or whatever.
So what I said that it does not show in the Stripe dashboard is if you used just the front-end code, it shows the payment method, but I thought that it should be automatically attached to the account, I haven't tried with this extra code from the link that you've shared, so I didn't had this one:
$paymentMethod = $request->input('stripePaymentMethod');
$user = auth()->user();
$user->addPaymentMethod($paymentMethod);
return redirect(route('home'));
Without that one, the card under the Customer is not being attached. That's what I understood the problem for @geser is as well.
For the Vue problem, make sure that on your script:
<script src="{{ asset('js/app.js') }}"></script>
You don't have the defer attribute, that might messes it up.
i found the solution:
https://github.com/haimiz/laravel-cashier-stripe/tree/master
Please or to participate in this conversation.