skip to Main Content

Not sure what’s going on, but when I downloaded a stripe checkout application into my computer and ran it through my terminal, it works. The logs on my stripe dashboard gets multiple events without errors.

php -S localhost:4242

I installed stripe CLI to test out webhooks, but then encountered this problem. Either way, it helped me debug a little.

stripe listen --forward-to=localhost:4242

Stripe logs when I go to localhost:4242/index.html and click on the button that’s supposed to start the "subscription" process:

2021-04-13 14:48:24   --> checkout.session.completed [evt_1Ifg2uLgiL5uZZPEFUQPX5UY]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2uLgiL5uZZPEFUQPX5UY]
2021-04-13 14:48:24   --> payment_method.attached [evt_1Ifg2uLgiL5uZZPEovIMBDrU]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2uLgiL5uZZPEovIMBDrU]
2021-04-13 14:48:24   --> customer.subscription.created [evt_1Ifg2vLgiL5uZZPEeW5I9uuv]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPEeW5I9uuv]
2021-04-13 14:48:25   --> customer.subscription.updated [evt_1Ifg2vLgiL5uZZPET119BTe4]
2021-04-13 14:48:25  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPET119BTe4]
2021-04-13 14:48:25   --> invoice.paid [evt_1Ifg2vLgiL5uZZPERfBA65LF]
2021-04-13 14:48:25  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPERfBA65LF]
2021-04-13 14:48:26   --> invoice.updated [evt_1Ifg2vLgiL5uZZPEe3m7U1wL]
2021-04-13 14:48:26  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPEe3m7U1wL]

Here’s where the problem starts. I created a website with a login system and bunch of stuff, and my intention was to link this stripe checkout application to that login system, so I needed access to $_SESSION variables. Here’s my folder structure by the way:

Root
|── /includes
│   │── login.inc.php
│   └── logout.inc.php
│
|── /stripe_test
|    │── index.html
|    │── createcheckout.php
|    │── config.ini
|    │── config.php
│    └── script.js
│
|── /loginpage.php
|── /editprofile.php
|── /logoutpage.php
|── /index.php
|── /header.php
|── /footer.php
└── .htaccess

I added a simple link in root/index.php that redirects to root/stripe_test/index.html, making it kind of a "pick a plan" page. I should mention that I’m hosting the root directory in xampp, localhost:8080, which is even weirder. Cause opening that stripe html page from localhost:4242 makes it work as intended. In a nutshell:

  • localhost:8080/stripe_test/index.html – doesn’t work (via xampp)
  • localhost:4242/index.html – works (via terminal: php -S localhost:4242)

I checked my apache error logs and here’s what it shows after clicking on the button:

[Tue Apr 13 15:51:35.411737 2021] [core:warn] [pid 8520:tid 588] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Tue Apr 13 15:51:35.432756 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00455: Apache/2.4.46 (Win64) OpenSSL/1.1.1h PHP/8.0.2 configured -- resuming normal operations
[Tue Apr 13 15:51:35.432756 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00456: Apache Lounge VS16 Server built: Oct  2 2020 11:45:39
[Tue Apr 13 15:51:35.432756 2021] [core:notice] [pid 8520:tid 588] AH00094: Command line: 'c:\xampp\apache\bin\httpd.exe -d C:/xampp/apache'
[Tue Apr 13 15:51:35.434758 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00418: Parent: Created child process 11816
[Tue Apr 13 15:51:35.724020 2021] [mpm_winnt:notice] [pid 11816:tid 700] AH00354: Child: Starting 150 worker threads.
[Tue Apr 13 15:51:44.120877 2021] [php:warn] [pid 11816:tid 1840] [client ::1:58891] PHP Warning:  require_once(shared.php): Failed to open stream: No such file or directory in C:\xampp\root\config.php on line 3, referer: http://localhost:8080/stripe_test/index.html
[Tue Apr 13 15:51:44.120877 2021] [php:error] [pid 11816:tid 1840] [client ::1:58891] PHP Fatal error:  Uncaught Error: Failed opening required 'shared.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\root\config.php:3nStack trace:n#0 {main}n  thrown in C:\xampp\root\config.php on line 3, referer: http://localhost:8080/stripe_test/index.html

I have no idea why the directory has two "backslashes", but it probably has something to do with the .htaccess file and the in my header. Here’s the htaccess directives:

Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^profile/([w-]+)/?$ profile.php?userid=$1 [L,QSA,NC]
RewriteRule ^([w-]+)/([w-]+)/?$ city_page.php?state=$1&city=$2 [L,QSA]

Can someone explain what’s going on here? I reckon the main issue is the htaccess and the base href, since it works when I target the actual folder stripe_test in my terminal and run a server directly from that directory. When I run a server using my xampp, which then uses those .htaccess directives and that base href, that’s when the error.log shows weird paths.

2

Answers


  1. Chosen as BEST ANSWER

    I figured it out. Apparently it was caused by 2 things:

    1. Incorrect dir target
    2. Chrome storing JS cache that had an incorrect dir target

    I opened the chrome console and checked which part it was messing up and I started playing around with the file name, ie from config.php to asdffwefconfig.php and adding invalid code in the file itself, like dfianfininf;

    In the console, as it turns out, it was still getting resolved to root/config.php from the cache. So I tried going through the whole process in an incognito window:

    1. Starting xampp with root dir at localhost:8080
    2. Clicking a bunch of links in my local site to arrive at localhost:8080/stripe_test/index.html
    3. Clicked a "subscribe" button to fire up the create-session in stripe

    I was previously stopped at #3, but with incognito, it's pushing through and is sending logs to my stripe dashboard. So I cleared my browser cache, and what do you know, it works on my regular browser window.

    To everyone who tried looking into this, appreciate you guys taking the time. Marking this as the solution.


  2. There is no file at C:\xampp\root\config.php. It’s at C:\xampp\root\stripe_test\config.php.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search