#ahsanetics

1 messages ยท Page 1 of 1 (latest)

strange orchidBOT
pale knot
fiery kestrel
#

Hey.. really , let me quickly check the link

#

So I removed price under line_items and added price_data=>2000. Got error, invalid object

#

So I added is as array price_data=>[ 'unit_amount'=>2000, 'currency'=>'usd"]. It is asking for product_data

#

Not sure what the product data should be?

pale knot
#

Are you trying to create an adhoc Product as well, or are you intending to reuse an existing Product? If the former you use product_data (shown in the API spec):
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-name
for the latter you would pass the ID of an existing Product via the product parameter:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product

fiery kestrel
#

I don't want to create any product. Just wanted to send a price to the stripe to get it charged. Is this a possibility?

pale knot
#

Not with Checkout Sessions, they rely on a line item structure, so you must pass at least enough information to create an adhoc Price and Product.

fiery kestrel
#

Hmm. So other than checkout session, is there any other option where I can do a onetime charge without having to create a product

pale knot
fiery kestrel
#

Just to get some clarity, what do you mean by adhoc product?

pale knot
#

A Product object that you didn't create ahead of time. Checkout Sessions require Price and Product objects to function, so you can either pass in existing objects that you created previously, or you can provide enough data for the Checkout Session creation request to create them on the fly.

fiery kestrel
#

So I passed the product_data and got a session id but when I log on to the dashboard, that product that i passed in product_data is not under Products.

pale knot
#

Is that a concern? We're not as familiar with how the dashboard shows things as we primarily focus on helping with our API in this forum, but if you didn't want to create a Product in the first place then not seeing it in the dashboard sounds ideal.

fiery kestrel
#

It does.. ok so I will keep an eye.. may be make a payment and see if it shows. Thanks for your help. I will check the link as well.. appreciate your help

#

Another question

#

I tried to send a post data to php script that creates session but it was not receiving it

#

Is it blocked by your script?

pale knot
#

I don't know what that means, can you elaborate?

fiery kestrel
#

So I wanted to send the amount that needs to be charged from client side. I send the amount as post request to the create_session.php. however, the script doesn't receives the post data. I have tried all possible ways but none worked. Hence, wondering if it is blocked by stripe

pale knot
#

You should not allow client side code to directly control the amount being charged. Anyone with sufficient javascript knowledge could intercept that and change the amount they're paying.

fiery kestrel
#

That is a good point but then I would have to create create_session.php for each product

#

Since stripe allows product in catalog. Atleast product name could be sent as post data to the script

pale knot
#

I'm still not sure I understand what script you're talking about. I just scanned our php repository and didn't find a create_session.php file. Is that a script that you built or got from a third party?

fiery kestrel
#

Yea it is a script that I built that create session with line_items etc. I

#

<?php

require_once '../vendor/autoload.php';

require_once '../secrets.php';

\Stripe\Stripe::setApiKey($stripeSecretKey);

header('Content-Type: application/json');

$YOUR_DOMAIN = 'http://localhost:4242';

$checkout_session = \Stripe\Checkout\Session::create([

'line_items' => [[

Provide the exact Price ID (e.g. pr_1234) of the product you want to sell

'price' => '{{PRICE_ID}}',

'quantity' => 1,

]],

'mode' => 'payment',

'success_url' => $YOUR_DOMAIN . '/success.html',

'cancel_url' => $YOUR_DOMAIN . '/cancel.html',

]);

header("HTTP/1.1 303 See Other");

header("Location: " . $checkout_session->url);

#

It is from this link

silk grove
#

๐Ÿ‘‹ taking over and catching up, Can you give me a summary of your question?

fiery kestrel
#

Hey.. the above mentioned script is provided by stripe to create sessions. I am trying to pass post data to it. E.g product name but the script doesn't get post data. I have tried multiple ways but still nothing. I wanted to find out if passing the post data from front-end blocked?

silk grove
#

No, Stripe SDK wouldn't really block anything.

If you're not seeing the POST data on your server then there must be something wrong with the request OR your server might have a middleware that clears out the POST data from the request

fiery kestrel
#

I tried with postman as well