Inquiry Manually Transaction Secure Pay Checkout

Asked

Viewed 455 times

1

Hello, I am Trying to make a Transaction query manually by following the template passed by the author of the michaeldouglas/Laravel-pagseguro component, but when I try returns the following error:

Non-static method laravel\pagseguro\Facades\PagSeguro::transaction() should not be called statically

Link to the repository:

https://github.com/michaeldouglas/laravel-pagseguro

Follow my consultation code:

 foreach($atualizar as $pagamento){
        $transaction = PagSeguro::transaction()->get($pagamento->codigo, $credentials);
        $information = $transaction->getInformation();
    }

Who can help I am immensely grateful!

******************Did not work using the repository method*********************

I made a query using the following code

    $email = env('PAGSEGURO_EMAIL');
    $token = env('PAGSEGURO_TOKEN');

    $client = new Client;
    $atualizar = Pagamento::whereIn('status',[Pagamento::STATUS_AGUARDANDO_PAGAMENTO,Pagamento::STATUS_ANALISE,Pagamento::STATUS_PAGA])->get()->first();
    return $response = $client->request('GET', 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions', [
        'query' => [
            'reference'   => $atualizar->codigo,
            'email' => $email, 
            'token' => $token,
        ]
    ]);

the query worked but does not return me data: inserir a descrição da imagem aqui

but the transaction exists in the sandbox: inserir a descrição da imagem aqui

however this code that presents in the sandbox is different from the code that I captured when I created the payment so much that it is different from the code of my database:

inserir a descrição da imagem aqui

I already searched both the code of my bank and the generated sandbox and could not return.

2 answers

1

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

  • 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

1

Tulio,

It seems the problem is being the information instead of the right implementation?

You didn’t get results even with the transaction code that was returned when creating it?

Try using this API in Postman with the 32-digit code you received: https://dev.pagseguro.uol.com.br/v1.0/#consulta-dos-detalhes-da-transa%C3%A7%C3%A3o

Remembering that reference code is not transaction code.

Reference code is YOURS and you pass it to them.

Transaction code is THEM and they pass it to you on the return of the transaction creation.

  • Didn’t you get results even with the transaction code that was returned when you created it? : I didn’t get any results, say the code is invalid! Try using this API in Postman with the 32 digit code you received. : I tried and keeps giving the same thing!!! if you can give me your contact to show you the code... @Souza-Souza

  • @Tuliovieira, did you manage to solve the problem? If you did not get by the API via Postman is a problem between the registration and sandbox in Pagseguro. New transactions result in the same problem? If you want you can contact [email protected] Vlw!

  • yes I was able to solve the problem I added the referece code and I searched for it and everything went well @Isaque Souza

Browser other questions tagged

You are not signed in. Login or sign up in order to post.