Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe searches Throwable.php in the spl_autoload_register directory and gives a non-blocking error #813

Closed
Raf-sns opened this issue Nov 29, 2019 · 8 comments · Fixed by #816

Comments

@Raf-sns
Copy link

Raf-sns commented Nov 29, 2019

Hi,
Hello, I am experiencing a non-blocking error when including Stripe.php -> init.php.

I have a controller that loads php classes from my API, they are all root Api.com/PHP/.

To avoid any conflict and since I had the following error: PHP Warning: include (PHP / Throwable.php): failed to open stream: No such file or directory

  • When including Stripe.php in my code:

include './STRIPE/init.php';
\ Stripe \ Stripe :: setApiKey (pay :: SK_PAY);

So I placed all Stripe.php in a separate folder it is in Api.com/STRIPE/

but the error continues.

I had to make a hack to no longer have error messages in my error_log: I created an empty Throwable.php file in the root that is loaded by the autoloader -> / PHP / and there more mistake ...

This is not a very good way to counter the error, but I did not find any Throwable.php files in Stripe.php.

Aside from that, the error that is thrown is non-blocking because the API is working fine and the test payments are accepted. I wanted to point it out here to understand
1 / Is this a bug?
2 / Is it me the bug?

Thank you for your answers,
Regards,
Raf

@remi-stripe
Copy link
Contributor

@Raf-sns Throwable is something pre-built in PHP and it's not specific to our library. I tried to repro on PHP 7.1 and PHP 5.6 but couldn't cause this error to be thrown.

This seems specific to your current configuration instead. Which exact version of PHP are you running?

@Raf-sns
Copy link
Author

Raf-sns commented Dec 3, 2019

Hi,
I just try again by renaming the file Throwable.php in
OLD_Throwable.php and I still get the error.
On this server I am under PHP 5.6, I determined that the error
occurred when I call Stripe.php in this function:

  /*
  *  pay::call_secret_client();
  */
  public static function call_secret_client(){
 
      // FETCH PAYMENT
      $id = intval($_POST['id'], 10);
 
      $ARR_pdo = array('id' => $id);
 
      $sql = 'SELECT * FROM payments WHERE id=:id';
      $response = 'one';
      $last_id = false;
       
       // PDO API FUNCTION
      $FETCH_PAYMENT = db::server($ARR_pdo, $sql, $response, $last_id);
 
      if( boolval($FETCH_PAYMENT) == false ){
 
             $tab = array('error' => 'Erreur : Paiement introuvable ...');
             echo json_encode($tab);
             exit;
      }
 
      // PAYMENT - if payment, call for a secret client and return it   
      // - HERE, IT GIVE THIS ERROR see error message next 
      include './STRIPE/init.php';
      \Stripe\Stripe::setApiKey( pay::get_private_key() );
 
 
      // $intent return an array
      $intent = \Stripe\PaymentIntent::create([
          'amount' => intval($FETCH_PAYMENT['amount'], 10),
          'currency' => 'eur',
      ]);
 
      // SECRET CLIENT WAS INITALIZED ?
      if( count($intent) != 0 ){
 
          // success
          $tab = array( 'client_secret' => $intent['client_secret'],
                        'stripe_id' => $intent['id'] ); // id -> str !!
 
          echo json_encode($tab);
          exit;
 
      }
      else{
 
          // error
          $tab = array('error' => 'Erreur : Le paiement n\'a pas pu être initialisé,
          <br>Videz vos coockies et réessayez s.v.p.');
          echo json_encode($tab);
          exit;
 
      }
 
  }
  /*
  *  pay::call_secret_client();
  */

error_log :

  [03-Dec-2019 09:47:35 Europe/Paris] PHP Warning:  
  include(PHP/Throwable.php): failed to open stream: 
  No such file or directory in
/home/rafcast/med.sns.pm/index.php[1][1][1] on line 17
  [03-Dec-2019 09:47:35 Europe/Paris] PHP Warning:  
  include(PHP/Throwable.php): failed to open stream: No such file or
directory 
  in /home/rafcast/med.sns.pm/index.php[1][1][1] on line 17
  [03-Dec-2019 09:47:35 Europe/Paris] PHP Warning:  
  include(): Failed opening 'PHP/Throwable.php' for inclusion 
 
(include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') 
  in /home/rafcast/med.sns.pm/index.php[1][1][1] on line 17

-> Again, when I include an empty Throwable.php file (, see
next captures),
at that moment the error disappears.

Do you want FTP access from the app to do the test yourself ?

Note :
the file index.php (this is an unic point of entry) 
This file refers to the error.

<?php
/*
* PlACIDO FRAMEWORK - 2019 - Copyright - Castello Raphaël - <[email protected]>
* script name : index.php
*/
session_start();

date_default_timezone_set('Europe/Paris'); // DEFINE TIMEZONE
setlocale(LC_TIME,  array('fr_FR.UTF-8','fr_FR@euro','fr_FR','French')); // SET LOCA.

// include MUSTACHE
include 'Mustache/Autoloader.php';
Mustache_Autoloader::register();

// THIS IS THE LINE 17  WHO GIVE THE ERROR
// CALL YOUR SPECIFICS CLASSES
spl_autoload_register(function ($class) { include 'PHP/' . $class .  '.php'; }); 

// START CONTROLLER
control::start();

?>

When the error occurs in the API : 
Here i just call  before the function pay::call_secret_client(); that
i pass to javascript to init. the payment

Annotation 2019-12-03 09dfds3326

General view of API :

Annotation 2019-12-03 092145

with error : (i renamed Throwable.php in OLD_Throwable.php)

aaaaa

Thank you for your response, do not hesitate to contact me for more details.

Regards,
Raf

@remi-stripe
Copy link
Contributor

@Raf-sns This does look like a problem with your own PHP setup at the moment. I tried that exact version of PHP and don't get the error. Our code also looks at whether Throwable is defined before trying to include it as you can see in our code here.

Getting access to your FTP would not be something safe and I'd recommend against ever sharing production access to your servers.

Can you confirm that the same error happens if you only include Stripe and nothing else in your script?

@remi-stripe
Copy link
Contributor

@Raf-sns Following up on this, @ob-stripe dug into this further and found something that could explain the issue. He pushed a fix in a branch here: #816

Would you be able to try this version (or make the same modification locally) to see if that solves the problem?

@ob-stripe
Copy link
Contributor

Fixed in 7.14.2.

@Raf-sns
Copy link
Author

Raf-sns commented Dec 5, 2019

Hello,
the reason I'm ready to share an FTP is that it's not a production environment of course, this FTP is on a test environment, the database too.

I will do a test with the new version of Stripe.

Yes to access the code and / or modify it, no worries of course.

Thank you for your interest, I will post a last comment to inform you of the disappearance of the bug,
Regards,
Raf

@Raf-sns
Copy link
Author

Raf-sns commented Dec 5, 2019

Hello,
following the update of the program with stripe-php-7.14.2 I confirm that the error has disappeared, thank you for your answers, I wish you a good continuation,
Regards,
Raf

@remi-stripe
Copy link
Contributor

@Raf-sns Thanks for testing and confirming it solved your issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants