#eztaxi-checkout-php
1 messages · Page 1 of 1 (latest)
Hi thank you for your reply
PHP Fatal error: Uncaught (Status 400) (Request req_cR755gFGJHJ2HW) Received unknown parameters: price, quantity
thrown in /home/if_eztaxi/myezadmin/tickets/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
Thanks, checking
Hmm, are you sure that's the code that's triggering that API request? The payload we're receiving doesn't match up
let me try again
For example , that API request (req_cR755gFGJHJ2HW) has a price_data parameter:
price_data: {
price: "price_1KYx8bAd2Vi4ueDPhm5XgYC2",
quantity: "1"
},
quantity: "1"
That API shape is invalid (you can't pass price and price_data)
But the code you shared doesn't have that, hence my confusion!
Oh sorry, I'm confused too
It seems working now! Yay!
$checkout_session = \Stripe\Checkout\Session::create([ 'line_items' => [ [ # TODO: replace this with the priceof the product you want to sell 'price' => $price_id, 'quantity' => $adult_qty, ], [ # TODO: replace this with thepriceof the product you want to sell 'price' => $price_id_child, 'quantity' => $child_qty, ],], /* 'line_items' => [[ # TODO: replace this with theprice of the product you want to sell 'price' => $price_id, 'quantity' => $max_qty, ],], */ 'payment_method_types' => [ 'card', ], 'metadata' => ["driver_id" => $driverid, "driver_name" => $driver], 'mode' => 'payment', 'billing_address_collection' => "auto", 'success_url' => $YOUR_DOMAIN . "/success.php?session_id={CHECKOUT_SESSION_ID}".$locid.$pmode, 'cancel_url' => $YOUR_DOMAIN . '/cancel.html', ]);
Excellent!
regarding price_data can I add multiple price_id ?
You wouldn't pass the ID of an existing Price object no. The purpose of price_data is to create an ad-hoc Price object at the same time as the Checkout Session
What are you trying to do?
$checkout_session = \Stripe\Checkout\Session::create([ 'line_items' => [ [ 'price_data' => [ 'currency' => 'aed', 'unit_amount' => $adult_amt, //'price' => $price_id, 'product_data' => [ 'name' => 'Adult - '.$prod_name, ], ], 'quantity' => $adult_qty, ], [ 'price_data' => [ 'currency' => 'aed', //'price' => $price_id_child, 'unit_amount' => $child_amt, 'product_data' => [ 'name' => 'Child - ' .$prod_name, ], ], 'quantity' => $child_qty, ], ], /* 'line_items' => [[ # TODO: replace this with the price of the product you want to sell 'price' => $price_id, 'quantity' => $max_qty, ],], */ 'payment_method_types' => [ 'card', ], 'metadata' => ["driver_id" => $driverid, "driver_name" => $driver], 'mode' => 'payment', 'billing_address_collection' => "auto", 'success_url' => $YOUR_DOMAIN . "/success.php?session_id={CHECKOUT_SESSION_ID}".$locid.$pmode, 'cancel_url' => $YOUR_DOMAIN . '/cancel.html', ]);
if you see in this code I commented out 'price_id' because it throws error
this code works good but it creates new price_id after every transactions
Yeah, that's the whole point of price_data. See: https://stripe.com/docs/products-prices/manage-prices#ad-hoc-prices
Learn how to manage products and prices.
So you can create a 'custom' price without having to create the Price object prior to using it with Checkout
great! this is what I want
If you need to persist that $price_id variable somewhere, you could use the metadata parameter: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yeah you're right, I'm already using metadata for driver_id hope it works too
It's done! Thank you so much for your help
Sure. np!