#james-checkout-php
1 messages · Page 1 of 1 (latest)
Hello james_35976, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
• james_35976, 3 days ago, 18 messages
@novel river the 500 is likely from your own code really in PHP. You're getting an API error (expected) and not handling that error in the code you shared
i just use the sample code , not anything else
First carefully read https://stripe.com/docs/error-handling to understand how to handle all expected errors returned by our API and display a useful error message instead of displaying a crash
require_once('stripe/init.php');
$stripe = new \Stripe\StripeClient("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
'mode' => 'payment',
]);
Second: you're mixing up ids and API keys here. The API key is the default one when not logged into your account but the Price id is from a different Stripe account,
Ultimately: clean up the code, add error handling, use your real API key with a real Price id from your own account
james-checkout-php
OK. I see .i thought it should return a error message.
it does
For the check out session . I need to create a price Id first . Right ?
but Now it return 500 HTTP Error instead a error msg
Our API returns a clear error message, just your code is not handling any error so it completely crashes like any code would
OK. Let me try see if it can get the error msg
I do not think so. The problem is coding issue . Error code is HTTP500
http 500 internal server error
means it can not find the coding or coding error
I'm certain of it. This is 100% your bug!
You have to catch errors. You write the PHP code here, you're the developer controlling the full behaviour. It's on you to write safe code that handles errors which we raise as exceptions. I shared the exact documentation page to read and follow https://stripe.com/docs/error-handling
I can create the price code successed.
no idea what those words mean I'm sorry
function example_function($args) {
try {
$stripe->paymentIntents->create($args);
error_log("No error.");
} catch(\Stripe\Exception\CardException $e) {
error_log("A payment error occurred: {$e->getError()->message}");
} catch (\Stripe\Exception\InvalidRequestException $e) {
error_log("An invalid request occurred.");
} catch (Exception $e) {
error_log("Another problem occurred, maybe unrelated to Stripe.");
}
}
I tried above , the page is blank
that's a completely different big of code creating a PaymentIntent which has nothing to do with what you were doing
I'm sorry you're going way too fast without taking the time to understand. You're the developer here, you're accepting payments from real customers, you have to be really careful about what you are doing. You're just throwing random lines of PHP code at me right now
Please take a step back, breathe and think about the code
so I am thinking if downloaded wrong SDK
Now I am using require_once('stripe/init.php');
can not find vendor/autoload.php file
in the SDK
did you check this image ?
It's just a random picture of your IDE on your own
but yes that's stripe-php as far as I can tell
It depends how you installed the librar, whether you use Composer or not. It's all documented. Most experienced PHP developers would be using Composer for example but it is not a requirement
I do not use composer
i have loaded it manually with cod below
require_once('stripe/init.php');
Yep I'm just explaining the difference between the two. Once. you load that file it loads the library as expected.
$stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
$customer = $stripe->customers->create([
'description' => 'example customer',
'email' => 'email@example.com',
'payment_method' => 'pm_card_visa',
]);
echo $customer;
This code works perfect
but not the check out session one
I mean same answer as the first line I gave you. You are rushing through things and copy-pasting tons of stuff. You are not really listening yet to what I am saying unfortunately.
To create a Checkout Session you have to
- Use the right API key (that's the wrong one)
- Use a Price id from your own account (you were using the wrong one)
- Properly use try/catch to catch an exception, which is needed for most modern PHP code overall
even there has a error ,but should not use code 500
use code 500 means the coding issue in my opinion.
I'm sorry, I will pause for now. You are not reading anything I say and are just asserting this is our fault over and over. I'm sorry but you're the developer here and you have to understand the 500 is caused by your own bug
no problem
Once you have read carefully what I explained multiple times, read the doc about error handling, and fixed the 3 points I have explained above, your code will work. If it still doesn't, please explain exactly what you did and shared your real code with the real try/catch, all in one message clearly laid out and I should be able to point you towards the issue
I understand fix the 3 lines you mentioned may fix this error, but this is not the way I handle the erorr(samply Throw a 500 error ,instead of the reason cause the error.)
We (Stripe) are not throwing a 500 error at all .We cleanly returned a detailed error with a message, error code, dashboard url and all the required information
You (the developer) are the one ignoring the clear error and not handling errors at all and crashing the server right now. This 500 is 100% from you not Stripe.
Again I did not write any coding now , just run the sample codes.
Sure but you are the developer here, you copy/pasted that code to make it work. It is a really basic and simple PHP example. It does no error handling
even the API key is wrong ,and price id not exist . I am expect receive a error msg , not crashed.
anyway I will try fix it with your instruction.
All you have to do is add a try catch around that code example and you'd get a clear error instead of a crash. The crash is your own doing
If we put a try/catch around every single example, most junior developers would be completely lost
ok.
I have successed created the session.
The problem was caused by wrong key and price ID
Glad to hear you were able to figure it out!
BUT I still think it should not handle the error by developer .
what I except i got a blank page so I know I need to find out the error
If your sdk throw 500 error. I thought my coding has error
Like koopajah explained before - this was an error coming from your own server because it wasn't handling potential API errors correctly. It was not our SDK that was throwing the 500 error, our API did throw an error which you, as the developer are expected to handle
you guys offer a sdk to make customer easy to use your api , not make the confusions
Erorr handling is something that you have to deal with in almost any API you integrate with
I have always used the API with my own coding, not use the SDK
I know i need to handle the error , but your file through the 500 error makes me confustion.
I do not think every code I need to use Try catch...
what I expect is when I use wrong KEY and PriceId , I got a blank data/page
anyway .the problem is fixed. thank you for your help
one more questin, can I see the sessions created on your website ?
We don't have a dashboard UI for Checkout Sessions (you'd have to use the API to list them)
ok
How many price/product I can create?
is that requires with session payment?
because sometime we need to change the product.
There's no limit to the number of prices/products
price
You can create as many as you want
it measn I can create one time use product.
only for that session payment.
becase we may offer different customer different price.
we for this api for phone call order.
We added the product in our winform app and create a payment link , and text the link to the customer.
then we need to collect the customer's shipping address after he /she successed paid and add to our system.
Yes, you can create a one-time price for just that Checkout sessino
You'd do that by specifying price_data (https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data) instead of creating the Price up front
is there a notification available after paid ?
You'll want the checkout.session.completed event (which gets sent when checkout is complete)
We talk about it more here: https://stripe.com/docs/payments/checkout/fulfill-orders