I was wondering what the best or better way in handling service specific functions is. Let’s say I have multiple Stripe functions like createCustomer, updateCustomer, getSubscription etc. I don’t want to handle inside my controller but only call these functions from within a controller.
Coming from an Extbase background, I would create some sort of StripeService.php file. But as far as I see, Service means something different then I expected in Laravel.
Should I just create a new helper file or what would be the best approach?
Just create a class. Service is a bad suffix for the name of the class that most developers inherited from Symfony. I would create a Billing class and inject Stripe adapter to it. That way I would own both of those classes. Makes everything super easy to test and maintain.
@bugsysha Would you be so kind and post a short code example for this approach? I looked at the repository pattern, but it seems to work with simple codebases only and many people report problems when using this approach with Laravel.
@mrmooky
Are we talking about theoretical situation or do you really need to figure out how to do the architecture around Stripe in your app? If it is the later option then I would suggest Laravel Cashier.
@bugsysha I actually have no problems with that. I've used both Cashier and the Stripe PHP API directly in the past. But for this particular project I will only need 3-4 API calls to Stripe so I don't see the need to use Cashier here.
I just wanted to move those 3-4 calls outside of my Controller and put them in some sort of Service "Helper File". I saw this approach in a tweet from the Spatie guys but could not find any more information regarding that.
I you wish to skip adding Cashier to your project then you can use what I've wrote. I do not have any code to show you. You can tell me which part is confusing to you in what I've wrote so I know what needs more details in code sample.