Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cluel3ss's avatar

Setting up BillingInterface/ServiceProvider - Cannot not found class error

Hey guys, I have been following the Billing with Stripe series to implement payments on my application.

I have created all the relevant files however I have encountered an issue:

ReflectionException in Container.php line 737: Class Billing\StripeBilling does not exist

Could someone help point out what I'm doing wrong? Here is the code I am using...

# app/Acme/Billing/BillingInterface.php
<?php 
namespace Acme\Billing;
interface BillingInterface {
    public function charge(array $data);
}
# app/Acme/Billing/StripeBilling.php
<?php 

namespace Acme\Billing;

use Stripe;
use Stripe_Charge;
use Stripe_Customer;
use Stripe_InvalidRequestError;
use Stripe_CardError;
use Exception;

class StripeBilling implements BillingInterface {

    public function __construct()
    {
        Stripe::setApiKey(env('STRIPE_SECRET_KEY'))
    }

    public function charge(array $data)
    {

        try
        {
            return Stripe_Charge::create([
                'amount' => 1000, // £10
                'currency' => 'gbp',
                'description' => $data['email'],
                'card' => $data['token']
            ]);
        } 

        catch(Stripe_CardError $e)
        {
            dd('card was declined');

        }

    }
}
# app/Providers/BillingServiceProvider.php
class BillingServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind('Billing\BillingInterface', 'Billing\StripeBilling');
    }
}
# app/Http/Controllers/BasketController.php
public function store(Request $request)
{

    $billing = \App::make('Billing\BillingInterface');
    return $billing->charge([
        'email' => $request->email,
        'stripe-token' => $request->token,
    ]);

I have added App\Providers\BillingServiceProvider::class to my app.php file; My autoload array in composer.json is as follows:

"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Acme\\": "app/"
        }
    },
0 likes
3 replies
kreitje's avatar

In your binding you need to do Acme\Billing\StripeBilling and not just Billing\StripeBilling

1 like
cluel3ss's avatar

@kreitje

By changing to $this->app->bind('Acme\Billing\BillingInterface', 'Acme\Billing\StripeBilling');, I get this error:

Class Billing\BillingInterface does not exist

kreitje's avatar
kreitje
Best Answer
Level 9

Just change the second part.

$this->app->bind('Billing\BillingInterface', 'Acme\Billing\StripeBilling');

Please or to participate in this conversation.