In your binding you need to do Acme\Billing\StripeBilling and not just Billing\StripeBilling
Nov 29, 2015
3
Level 2
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/"
}
},
Level 9
Just change the second part.
$this->app->bind('Billing\BillingInterface', 'Acme\Billing\StripeBilling');
Please or to participate in this conversation.