Create a subscription with Vue stripe and Laravel - 07
We are going to test using the Vue Stripe plugin to make a subscription
We are going to do an interesting test using the Vue Stripe plugin here, which I think is a very interesting way to do different operations
Remember that, or I don't know if you remember, that at the beginning when we were testing the plugin, we also tested a recurring payment that I think was left by mistake
Perfect, now we have nothing, what do we have to change? Let's remember a little bit here in the plugin, the first thing would be that by default here we have payment, in this case it would be subscription:
app\Http\Controllers\Api\StripeController.php
function createSession(string $priceId, string $successURL = 'http://laravelbaseapi.test/vue/stripe/success', string $cancelUrl = 'http://laravelbaseapi.test/vue/stripe/cancel')
{
$session = Checkout::guest()->create($priceId, [
// 'mode' => 'payment',
'mode' => 'subscription',
'success_url' => $successURL . '?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $cancelUrl
]);
return $session->id;
}
And in the plugin, remember to set a recurring price type:
lineItems: [ { price: <PRICE_ID_RECURRENT> }] // recurrent
So I'm going to duplicate this here I'm going to comment on it I think it's pretty well understood that it's a subscription and here we would comply with this the following would be the price ID that we are also passing it I don't even really remember it would be one of these I don't know if we are using this here we have it perfect we are passing the first one let's see where I have them exposed correct they would be these it would be this one then I'm going to comment on this so that it doesn't generate noise this good I'm going to duplicate this I'm going to comment on this this is going to be the recurring one that I shouldn't leave commented on either but we have the recurring one here it would be the one we used before for the subscription this is the one we had to expand you create another one it doesn't matter but I'm going to put it there in summary since it jumps a little bit here we put the subscription mode since remember that we are using the session on the server here or we are generating the session that can only be generated on the server and that we are calling here from the One payment plugin just as we implemented before in the course then here we configure it to be of the subscription type and automatically We have to pass the price or the PR ID what we are going to buy also of the subscription type I'm going to put it here in one to keep everything simple
And remember that this list is the one we are passing in the create section that is already lost again or I am going to select this one to see here to create the session that we then use and everything else in principle should do that
Advantages of this modality
What advantages do we have here? I think we have a huge advantage. And it's that, at least for me, it bothered me a little to be handling this custom user in the Arab cashier that if we register the payment ID or the payments that he has to create through the plugin that we configured here before the stripe one, the one that we have to put together a box here so that he can put his card and everything else. Let's see, this is excellent. I'm not going to criticize it, but but, but the problem that I see is that for small or medium applications, if for example it were a website like Amazon that decides to ally with them, that is to say, a well-known website, I think that the client would not have much of a problem. Since, for example, I put my card in Amazon without problems and I know that they are not going to play any tricks on me, but let's see, in small applications that are not as well-known that they are asking you for the card, I think that anyone is going to be suspicious, which we know that it is very difficult, so to speak, because you can perfectly place a Kid down event here so that every time you write the user you also register it behind then in principle you could obtain it like this I have never done it but in principle you could obtain it like this but to me it seems like a lot of risk that or a lot of risk in the sense that I do not believe that a normal user who does not know what the hell this is as a final client is formed so to speak he is going to trust placing his card, that is to say the management of his card with the automatic payments that we saw before and everything else from an application that he does not know. So I believe I believe I believe that it is much better and so we also, as who says we take care of our health a little, implement systems like the one you saw a few moments ago that you see that it redirects to another page and therefore an end client who should already understand this a little that we are not on the same URL since those are protection measures for any website, any website, especially banks, tells you to be very careful with the URL that is https that is the website of your bank and everything else and that all operations come out locally. So when another website passes, at least let's suppose that he knows the stripe website and therefore you see that the operation is being carried out there something similar to what happens with PayPal because it would be an approach a little similar to what we do with PayPal and therefore I consider it much safer for the client from that point of view seeing it from the client's point of view so I would prefer it there 1 times apart from the above that already for us that we simply want to have is a Bend a blessed subscription and nothing else also for us It would be much simpler since we do not have to implement what was mentioned that if we implement here the box to add your card or directly send you the link to add Stripe then the user has to create an account in strike because if you click here it will ask you to authenticate the strike account in my case Well notice that even if it is authenticated you are asking me for it again So you have to implement a lot of things to simply make a subscription of x thing in your service I consider that this way it is much more pleasant so nothing a little what I wanted to comment here so nothing Now you have another way to make the subscriptions again For me this is the recommended one and without further ado, with this I think we cover everything, at least what I had initially conceived for Stripe with Laravel Cashier.
- Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter