I’m at the very last stages of testing a webapp before making it live but am having problems with the app using the Stripe API.
When the app is run standalone:
plackup -p 5000 bin/app.psgi
it does everything fine as expected. It goes through it’s paces, successfully completes the Stripe test payment and there are no unexpected log messages. When I try to run it with the perl server Starman:
plackup -s Starman -a bin/app.psgi -l localhost:5000
everything is fine until I get to the Stripe payment portion. It usually goes through the process (but occasionally fails at other JSON calls) but after the payment is completed it fails to retrive the checkout session with the supplied session id:
Stripe API: GET /v1/checkout/sessions/:id
In this case I’m using the perl module Business::Stripe, this is where it fails:
# my $session = $stripe->api( 'get', 'checkout/sessions', $session_id );
my $session = $stripe->api( 'get', 'checkout/sessions', 'id' => $session_id );
Error log:
[HWCal:82368] error @2024-05-15 16:54:08> Route exception: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/vendor_perl/Business/Stripe.pm line 587. in /usr/local/share/perl5/5.36/Dancer2/Core/App.pm l. 1516
The stripe object and session_id are valid but it dies there with nothing happening afterward. The commented out line worked just fine when run without Starman. I just changed it because the docs say it wants a hash there. The plackup/Starman version doesn’t work with either. Interestingly the app had to earlier create a checkout session object using post which it did successfully. I think the problem has to do with Starman’s way of working with JSON but I can’t find anything on it. I’m at a loss and would appreciate any ideas for troubleshooting this issue.
I tried double checking the JSON code to omit trailing commas and other things mentioned in the browser console at:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse
Nothing seemed to help.