Friend,
I looked at the repository you mentioned, there are 2 classes with the same name called "Pagseguro":
laravel\pagseguro\Platform\Laravel5\Pagseguro
laravel\pagseguro\Facades\Pagseguro
And there’s a "third" that’s the stab wound that you file as an alias on config.app
:
'aliases' => [
...
'PagSeguro' => laravel\pagseguro\Platform\Laravel5\PagSeguro::class,
...
]
You can use both the config.app
as the laravel\pagseguro\Platform\Laravel5\PagSeguro
\\ utilizando o Alias registrado no config.app
use Pagseguro;
\\ou diretamente a Facade
\\use laravel\pagseguro\Platform\Laravel5\PagSeguro;
...
foreach($atualizar as $pagamento){
$transaction = PagSeguro::transaction()->get($pagamento->codigo, $credentials);
$information = $transaction->getInformation();
}
...
I believe you must have misregistered the alias in config.appp or referenced the wrong class there in the header of your script.
It is important that you properly register the Provider service also at config.app
:
'providers' => [
...
laravel\pagseguro\Platform\Laravel5\ServiceProvider::class,
...
]
If you use the class directly laravel\pagseguro\Facades\PagSeguro
this really does not have any static method or magic method to solve.
<?php
namespace laravel\pagseguro\Facades;
/**
* PagSeguro Facade
* @author Isaque de Souza <[email protected]>
*/
class PagSeguro
{
/**
* @return Checkout
*/
public function checkout()
{
return new Checkout();
}
/**
* @return Plan
*/
public function plan()
{
return new Plan();
}
/**
* @return Credentials
*/
public function credentials()
{
return new Credentials();
}
/**
* @return Item
*/
public function item()
{
return new Item();
}
/**
* @return Transaction
*/
public function transaction()
{
return new Transaction();
}
}
I believe you’ve already solved the problem here. From here down is just an explanation of how the Facades work for you to know which class to use and why.
How a Facade Works
It is important to understand the mechanics, the functioning of Facades in the Laravel. I’ll take Pagseguro himself as an example.
1st is registered a service Provider in the config.app
.
'providers' => [
...
laravel\pagseguro\Platform\Laravel5\ServiceProvider::class,
...
]
What the Provider service does?
Let’s see the code snippet:
/**
* Register the service provider.
* @return void
*/
public function register()
{
$this->app->bind('pagseguro', function () {
$platform = new Laravel5();
Config::usePlatform($platform);
$facade = new PagSeguroFacade();
return $facade;
});
}
/**
* Get the services provided by the provider.
* @return array
*/
public function provides()
{
return ['pagseguro'];
}
This excerpt of code from the service Provider is basically registering an alias called "pagseguro" and solving a concrete object "Pagseguro Facades Pagseguro".
So when calling resolve('pagseguro')
or app('pagsegoro)
or $this->app->make('pageguro')
or $this->app['pagseguro']
at some points in the Laravel, the Laravel Container will return the concrete object recorded above.
2nd is registered the Facade also in the app.config
'aliases' => [
...
'PagSeguro' => laravel\pagseguro\Platform\Laravel5\PagSeguro::class,
...
]
What this Facade does?
Let’s see the code snippet:
namespace laravel\pagseguro\Platform\Laravel5;
use Illuminate\Support\Facades\Facade;
/**
* PagSeguro Laravel Facade
* @author Michael Douglas <[email protected]>
*/
class PagSeguro extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'pagseguro';
}
}
Basically it will return the string "pagseguro" which is the alias for the concrete object.
This class extended the Illuminate\Support\Facades\Facade
Finally let’s see how this works:
/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $args
* @return mixed
*
* @throws \RuntimeException
*/
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
The magic method __callStatic
will solve the concrete object and call the method of this object you called statically.
Practically speaking:
laravel\pagseguro\Platform\Laravel5\PagSeguro::transaction()
1-O facade resolve o objeto concreto (laravel\pagseguro\Facades\Pagseguro) devidamente configurado no service provider;
2-Chama o método "transaction" do objeto concreto
By the way, the Second Class repository in question was a little confused, since there are 2 classes facade "Pagseguro", being that one is actually a Facade of Laravel, and another is a service or container of services (despite the namesapace "Facade"). This confused mess must have made your mistake.
I hope I’ve helped and clarified.
Hugs.
I could not but I am consulting now via Curl and is not giving return
– Tulio Vieira
if you can help me updated the question, if you have how to pass me your contact is even easier to ask you better kkk
– Tulio Vieira