#Ludderz
1 messages ยท Page 1 of 1 (latest)
sooooo i need to run an ecom website for a business i work for, they buy sell phones, so stock changes every hour and i wanna add stripe to a custom website ive coded, BUT heres the problem, it says this on the setup
" // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: '{{PRICE_ID}}',
quantity: 1,
},
],"
any way round that as people i work for wont be able to do this when they get new stock
like kinda just a simple buy button that pulls all the stuff from basket if that makes sense not price id and stuff kinda like how paypal has done it
Yeah that's totally possible. You can use price_data instead of price if you want to create the price inline instead of ahead of the Checkout Session
So you would basically send the cart info to your server endpoint and translate that cart info into the necessary line_items for Checkout and then create the Checkout Session and redirect
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data is what I'm talking about specifically with price_data
Yep take a look and let me know if you have any follow up questions!
{price_data: {
unit_amount: 100,
currency: 'usd',
product: 'prod_123'
}
}]```
That's an example
In this case you would pull the product ID from one that you had already created
You could also create it inline just like the above using product_data
i dont want to have 'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
because people i work for wont understand it, I have it all in a database with phpmyadmin can i just pull it from there instead of typing every product
Yep that would be the idea
like there will be alot of products in and out
I'm just telling you how our API works
So yeah, you would want to match up your database with the information that our API needs
Then you query your database based on the cart info that is passed from the client and then submit the corresponding information to our API
Sorry I can't audit your code line by line. It looks fine based on a glance, but really the best thing to do is to test it out and then work from there!
okay can we keep this open for like half hour just while i see if this works?
Sure
hi are ya there? ๐
๐
So i think i have it working, how can i see if one of the test cards went though?
You can look in your Dashboard at https://dashboard.stripe.com/test/payments
Hello! I'm taking over and catching up...
Looks like you tried to create a Charge with the amount set to zero, which is not allowed.
Have a look at the request log in your Dashboard: https://dashboard.stripe.com/test/logs/req_Y5g2J6yybDvhid
okay 1 second
oh, so its working but the amount isnt connect to my db?
Yep.
Well, I don't know if it's correct in your DB or not, all I can see is that you passed 0 for the amount from your PHP code.
I can't say where the 0 came from beyond that.
AHHH
its not even connected...
hang on lol
would it be worth making a new db with these :
saves me some headaches then if so
That's up to you. ๐
okay give me 10 mins and ill get back to you ๐
it still no work ๐ญ can i come back to this tomorrow? its to late for my brain ill send u all errors i got right now
is it possible to keep this one open or is it automatic close?
Looks like you're still sending us an amount of 0 though.
This thread will be closed, but you can still view it.
You can bookmark the link or search for it.
i think its my db not picking up the total price ๐ญ
if i was to youtube it. what would i search because all the videos i get is the one where i have to manually enter the product i wanna avoid that
I'm not sure what you're trying to do or what exactly is blocking you.
are we allowed to talk in dm? if i give u a dm tomorrow about it and i can explain what i need
No, please do not DM people for help with Stripe. I won't be around tomorrow, but someone else should be. You can ask more questions in #dev-help tomorrow, or I can help you more here now.
okay no problem give me a min to type what im looking for
so, im making an ecom website for a buy and sell company (mobile phones) so stock changes everyday.
I want a payment gateway like paypal where it just gets whats in ur cart and pay that
everyone i work with isnt all computer smart lol so i dont want to have manual input, i just want it to get the total price of the cart and items in the cart
Okay. Is there a reason you're trying to create a Charge directly? That's a legacy approach we do not recommend.
tbh its there to help people i work with aswell to keep it simple, i just dont want to have to manually input the products and prices because there is alot of products and they wont know what to do
When you say you don't want to manually input the products and prices are you talking about your customers (the people paying) or people on your staff? Or someone else?
this bit, i want that to get it from my phpmyadmin database
Okay, so that's for Stripe Checkout, which is completely different from the request we were talking about earlier.
The request you made earlier was to create a Charge directly (not recommended).
Do you want to use Stripe Checkout or are you trying to build a custom payment form on your site?
Are you sure?
I'm never sure anymore lol, ok sure lets do stripe checkout
Well, you should make sure you know what you want before we continue. A custom payment form gives you more control, but is more difficult to build and maintain. Stripe Checkout is easier to use and maintain, but you have less control over the payment experience. Which of those sounds like the right fit for what you want to do?
lets do stripe checkout, looks more like what im looking for, is this where i input all my products to the server.js?
Stripe Checkout is designed to work with Products and Prices you define in Stripe, but you don't have to use it that way. You can set Product and Price data on the fly when you create a Checkout Session without setting it up ahead of time.
When you create a Checkout Session you can set arbitrary Price and Product data inside price_data: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
so would "price_data" pull it from my cart
You can put whatever you want in there from wherever you want, yeah.
Can you provide more details about what exactly you mean when you say "pull it from my cart"?
1 sec ill explain it
so i want it to take this price and automatically have that on stripe without doing
"const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
payment_method_types: ['card'],
});"
so it just pops up with the name of product and the price that they pay
Okay, it's important to understand that if you're using Stripe Checkout you will not be creating Payment Intents or Charges. The only thing you're going to create are Checkout Sessions.
Stripe Checkout will create a Payment Intent for you, and the Payment Intent will create the Charge.
So you need to create a Checkout Session and specify the information above inside price_data (as linked above).
Then once the Checkout Session is created it will have a url property. You send your customer to that URL and they see Stripe Checkout and pay you.
For example:
$checkoutSession = $stripe->checkout->sessions->create([
'success_url' => 'https://example.com/?success&session_id={CHECKOUT_SESSION_ID}',
'mode' => 'payment',
'line_items' => [
[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'Example Product',
],
'unit_amount' => 4200,
],
'quantity' => 1,
],
],
]);
You can add in other details as documented at the link I shared above, but that's a minimal example.
You do that, you get a Checkout Session back, you send your customer to the Checkout Session's url.