pagarme / pagarme-php-sdk

Other
17 stars 10 forks source link

php error #35

Open Ort0x36 opened 9 months ago

Ort0x36 commented 9 months ago

Fatal error: Uncaught Error: Class 'PagarmeApiSDKClientBuilder' not found in /var/www/html/testing_pagarme_client.php:4 Stack trace: #0 {main} thrown in /var/www/html/testing_pagarme_client.php on line 4

<?php
require('vendor/autoload.php');

$client = PagarmeApiSDKClientBuilder::init()
    ->basicAuthUserName('sk_test_*')
    ->basicAuthPassword('')
    ->serviceRefererName('')
    ->build();

$transaction = $client->getTransactionsController();

echo '<pre>';
var_dump($transaction);
ctestonjung commented 9 months ago

I faced the same issue. Here's a solution:

The composer.json file contains the following PSR-4 autoloading configuration:

"autoload": {
  "psr-4": {
    "PagarmeApiSDKLib\\": "src/"
  }
},

This means it will load PagarmeApiSDKLib namespace from the src folder.

Inside the folder that contains src, vendor and the composer.json file, you should run:

composer dump-autoload

In your code, you will then be able to add a use statement including PagarmeApiSDKLib\PagarmeApiSDKClientBuilder symbol or just call it using it's fully qualified class name, like in the following sample:

//use PagarmeApiSDKLib\PagarmeApiSDKClientBuilder;

require_once './vendor/autoload.php';

$client = PagarmeApiSDKLib\PagarmeApiSDKClientBuilder::init()
    ->basicAuthUserName('BasicAuthUserName')
    ->basicAuthPassword('BasicAuthPassword')
    ->serviceRefererName('ServiceRefererName')
    ->build();

I hope this helps.