Support the ongoing development of Laravel.io →
Packages Configuration Architecture
Last updated 2 years ago.

rezwan-hossain liked this thread

1

You can use any PHP library in Laravel without a service provider. What the service provider does is simplify it. In case of APIs they mostly require an api_key and api_secret. The provider should take those from the environment/configuration and provide you with a ready to use set of services. From what I see the provider should call

ChargeBee_Environment::configure(config("chargebee.site"), config("chargebee.api_key")); // Create a file called  chargebee.php in the config folder, fetching the values from environment.

After registering the provider you should be able to call the ChargeBee_Customer::all(...) from anywhere in the controller.

The above in unrelated to your problem. What the error is saying is that you are missing a using statement at the top of your controller code. You need to add use ChargeBee_Customer;. This won't work out of the box because PHP doesn't know where to look for this class. It's because the library doesn't comply with PS4 standard, which allows autoloading. You have to handle that yourself. To do so modify your composer.json file


    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "vendor/chargebee/chargebee-php/lib/ChargeBee/Models/Customer.php"
            //Add other files you need here
        ],
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },

After that run composer dump-autoload and see if PHP manages to find the class.

Last updated 4 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

E-Cadima embercadima Joined 22 May 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.