mpesa-php-sdk icon indicating copy to clipboard operation
mpesa-php-sdk copied to clipboard

Composer autoload path not working: ../vendor/autoload.php

Open jukwahewa opened this issue 4 years ago • 4 comments

Warning: include_once(../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/mpesa/src/Mpesa.php on line 10

I get this error message whenever I am trying to use your PHP SDK. I think this is a bug for your relative paths to composer autoload file. I have also run composer install but issue is still persistent.

I am using your PHP SDK version 1.0.8. Please help as it does not work out of the box and I am stuck on this error mpesa-autoload-failure .

Thank you.

jukwahewa avatar Jan 20 '20 06:01 jukwahewa

I suspect it should be this on line 10 of Mpesa.php

require 'vendor/autoload.php';

LiamKarlMitchell avatar Mar 16 '22 08:03 LiamKarlMitchell

Or possibly something like Carbon.php does?

$dir = __DIR__.'/..';

if (!file_exists($dir.'/autoload.php')) {
    $dir = __DIR__.'/../vendor';
}

if (!file_exists($dir.'/autoload.php')) {
    $dir = __DIR__.'/../../..';
}

if (!file_exists($dir.'/autoload.php')) {
    echo 'Autoload not found.';
    exit(1);
}

require $dir.'/autoload.php';

Or ../../autoload.php ?

I'm attempting to use this with Laravel.

LiamKarlMitchell avatar Mar 16 '22 08:03 LiamKarlMitchell

Lia

Or possibly something like Carbon.php does?

$dir = __DIR__.'/..';

if (!file_exists($dir.'/autoload.php')) {
    $dir = __DIR__.'/../vendor';
}

if (!file_exists($dir.'/autoload.php')) {
    $dir = __DIR__.'/../../..';
}

if (!file_exists($dir.'/autoload.php')) {
    echo 'Autoload not found.';
    exit(1);
}

require $dir.'/autoload.php';

Or ../../autoload.php ?

I'm attempting to use this with Laravel.

I gave up on this MPESA SDK as the developer(s) never replied to my opened bug request. I ended up writing custom PHP code to interact with the API. Please see MPESA API guiding docs here: https://developer.safaricom.co.ke/APIs

I wish you luck and all the best with your integration.

jukwahewa avatar Mar 17 '22 11:03 jukwahewa

Thanks @jukwahewa , I will probably be forced to do the same as this is not the only issue I have noticed with this code.

  1. The way env variables are loaded does not let us cache the config in Laravel.
  2. Dotenv used in the function similar to laravel, looks like it might not actually load the .env file when used in a Laravel project wrong path?
  3. self::env should be used put all the conditional checks in it.
  4. What if json_decode fails in the TransactionCallback methods?
  5. No confirmation that the response comes from their servers.
  6. No hash in response/headers to verify the message has not been tampered with.

LiamKarlMitchell avatar Mar 18 '22 08:03 LiamKarlMitchell