#eztaxi-retrieve-charge
1 messages ยท Page 1 of 1 (latest)
Thanks for the info, looking in to it
So the first thing I am noticing is that cs_test_123 is not the format of a charge id
That should be Checkout Session, if you retrieve the Session it will have a PaymentIntent with a list of charges
this my checkout php :
`require 'vendor/autoload.php';
\Stripe\Stripe::setApiKey('sk_test_..........');
header('Content-Type: application/json');
$YOUR_DOMAIN = 'https://myezadmin.com/tickets/public';
$price_id = $_POST['price_id'];
//$successpage = '/success.php?orderid='.$checkout_session;
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# TODO: replace this with the price of the product you want to sell
'price' => $price_id,
'adjustable_quantity' => [
'enabled' => true,
'minimum' => 1,
'maximum' => 10,
],
'quantity' => 1,
]],
'payment_method_types' => [
'card',
],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . "/success.php?session_id={CHECKOUT_SESSION_ID}",
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);`
I think I have error above?
I don't think that error is coming from that snippet
The request Id is from a charges->retrieve call and I don't see one in that snipped
Do you see where you are making a call like that in your code?
no it's in my success.php
success.php:
`require '../vendor/autoload.php';
$orderid = $_GET['session_id'];
$stripe = new \Stripe\StripeClient(
'sk_test_.............'
);
$stripe->charges->retrieve(
$orderid,
[]
);
$amount = $stripe->amount;
$qty = $stripe->quantity;
?>
<!doctype html>
<html>
<head>
<title>Thanks for your order!</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section>
<h1>Thank You</h1>
<p>You order ID: <?php echo $orderid; ?>
<br>
Amount Paid: <?php echo $amount ?>
<br>
Quantity: <?php echo $qty; ?>
</p>
<p>
We appreciate your business! If you have any questions, please email
<a href="mailto:orders@example.com">myeztaxi@gmail.com</a>.
</p>
</section>
</body>
</html>`
Ah there we go
...
$stripe->charges->retrieve(
$orderid,
[]
);```
You will want to use sessions->retrieve https://stripe.com/docs/api/checkout/sessions/retrieve
Instead of charges->retrieve
Yes, and the Session still has an amount but getting the quantity will be a bit different
Quantity is really important for me, should I create charge session instead?
You can still get quantity, one moment as I look in to the best way to get that from a PaymentIntent
Also as a small note, you will want to look at amount_received instead of amount if you want the amount of money the customer was charged
That won't actually be different you are charging for the full amount, it is just the field that is more directly what you are looking for
So actually the best place to get the quantity here is to check out the line_items on the Session object that you get back
So use line_items for quantity and expand the payment_intent property to get the amount that you received
amount_received very good point, I didn't realize that
Indeed amount is showing actual product price but not total
[24-Sep-2021 13:24:21 America/Los_Angeles] PHP Notice: Undefined property: Stripe\Service\CoreServiceFactory::$amount_received
I added amount_received in line_items inside payment_intent
I'm almost there...
amount is deprecated?
Where says amount is deprecated?
php log says undefined,
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-amount
It's not retrieving any data from that session, but HTTP status 200 OK
Can you send me the request_id for that? (it will look like req_123)
@lime glacier we're happy to help you debug your code, but we can't do all those steps for you
it's important that you add logs to your own code to understand which step you're at and what is blocking you
[24-Sep-2021 13:43:33 America/Los_Angeles] PHP Notice: Undefined property: Stripe\Service\CoreServiceFactory::$amount_total in /home/tickets/vendor/stripe/stripe-php/lib/Service/AbstractServiceFactory.php on line 55
this what I'm getting in logs
Okay, that;'s one small log, what is the code that goes with it? Did you log the entire Session object to see what was returned?
checkout session works like charm without errors as expected, but not sure where else I should look. Anyway thanks for help, in that case we must hire one of your recommended partner
@lime glacier you code must be retrieving the Session before accessing that property right?
So can you log the entire object to look at it?
you seem to expect something that is null, maybe the session is not in the state you think
yeah I'm sorry this doesn't help
I'm really trying to teach you how it works and how to debug
this call is not something your code does at all, it's just the confirm on the hosted Checkout page
After that step, what does your code do exactly, can you share that part? The part that happens after success
Sorry, my bad
Stripe\StripeClient Object ( [coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object ( [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object RECURSION [services:Stripe\Service\AbstractServiceFactory:private] => Array ( [checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object ( [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object RECURSION [services:Stripe\Service\AbstractServiceFactory:private] => Array ( [sessions] => Stripe\Service\Checkout\SessionService Object ( [client:protected] => Stripe\StripeClient Object RECURSION [streamingClient:protected] => Stripe\StripeClient Object RECURSION ) ) ) ) ) [config:Stripe\BaseStripeClient:private] => Array ( [api_key] => sk_test_..... [client_id] => [stripe_account] => [stripe_version] => [api_base] => https://api.stripe.com [connect_base] => https://connect.stripe.com [files_base] => https://files.stripe.com ) [defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object ( [apiKey] => [headers] => Array ( [Stripe-Account] => [Stripe-Version] => ) [apiBase] => ) )
you just leaked your key
please be careful
this also has only 1% of the information
You're still not sharing your code either, can you share the php code and then I can help you tweak it
I shared my php code above, just a sec:
yeah the code above seemed unrelated since it's about a charge and you're doing checkout and I worry you mix up a lot of the concepts together
`header('Content-Type: application/json');
$YOUR_DOMAIN = 'https://myezadmin.com/tickets/public';
$price_id = $_POST['price_id'];
//$successpage = '/success.php?orderid='.$checkout_session;
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# TODO: replace this with the price of the product you want to sell
'price' => $price_id,
'adjustable_quantity' => [
'enabled' => true,
'minimum' => 1,
'maximum' => 10,
],
'quantity' => 1,
]],
'payment_method_types' => [
'card',
],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . "/success.php?session_id={CHECKOUT_SESSION_ID}",
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);`
Yeah, another admin mentioned that, so I fixed that to checkout session
yeah that doesn't really make sense
the call you shared is the Checkout creation call, it happens at the beginning
at that step it's not paid, you redirect to Checkout where the customer pays and then the customer comes back to your app/website (the success_url) and there you run new code that will look at the session
`require '../vendor/autoload.php';
$session_id = $_GET['session_id'];
$stripe = new \Stripe\StripeClient(
''
);
$stripe->checkout->sessions->retrieve(
$session_id,
[]
);
$amount = $stripe->amount_total;
$qty = $stripe->quantity;
$status = $stripe->status;
?>
<!doctype html>
<html>
<head>
<title>Thanks for your order!</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section>
<h1>Thank You</h1>
<p>Order ID: <?php echo $session_id; ?>
<br>
Amount Paid: <?php echo $amount ?>
<br>
Quantity: <?php echo $qty; ?>
<br>
Status: <?php echo $status; ?>
</p>
<p>
We appreciate your business! If you have any questions, please email
<a href="mailto:myeztaxi@gmail.com">myeztaxi@gmail.com</a>.
</p>
</section>
</body>
</html>`
use three ` instead, easier to read
$session_id,
[]
);
$amount = $stripe->amount_total;```
you see how you code retrieves the session, and then you forget to store it in a variable?
and then you "assume" that $stripe is the session, but it's not, it's the "client" so it just fails
try this
require '../vendor/autoload.php';
// Create a Stripe client to make requ
$stripe = new \Stripe\StripeClient(
'xxxx'
);
// Get the Session id from the URL parameter during the redirect
$session_id = $_GET['session_id'];
// Retrieve the Session from Stripe and store it in a variable
$session = $stripe->checkout->sessions->retrieve(
$session_id,
[]
);
// Now that I have a Session, let me output the entire object to understand it
// This isn't good code, it's just to see the object
echo "<br><pre>\n$session\n</pre><br>";
// Output what is in amount_total
echo "Amount total that I got: " . $session->amount_total . "<br>";
I added comments to each step for you to grasp how it works
Oh thank you so much!! Let me try now
It works finally! You're a genius!!! ๐ ๐ ๐
yeah so you need to understand that part of PHP
all our calls are returning the object
and you have to store it in a variable
I'm sorry, I'm PHP beginner ๐คญ
oh totally fine
I just confused