#commander - Price
1 messages · Page 1 of 1 (latest)
👋 Thanks for reaching out
it depends on how you are accepting Payments, but if you are using Checkout Session, you can use price_data and product_data
when creating the session:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_rfUjrHpwuyQ1rl
It seems like you have an issue in your integration while Serialization the body of the request and sending it to Stripe, you can see in the dashboard what are you sending to Stripe, it must be full Json format
https://dashboard.stripe.com/test/logs/req_rfUjrHpwuyQ1rl
yeah, but any idea whats wrong?
Can you share the whole code that is responsible for creating the request ?
` List<Object> lineItems = new ArrayList<>();
// Produkt
Map<String, Object> params = new HashMap<>();
// Items
Map<String, Object> lineItem1 = new HashMap<>();
lineItem1.put("quantity", 2);
Price price = new Price();
price.setCurrency("eur");
price.setUnitAmount(Long.valueOf(2000));
price.setType("one_time");
Product product = new Product();
product.setDescription("Test");
product.setName("Test");
product.setDefaultPrice("2000");
price.setProductObject(product);
lineItem1.put("price_data", price);
lineItems.add(lineItem1);
params = new HashMap<>();
params.put("success_url", "https://example.com/success");
params.put("cancel_url", "https://example.com/cancel");
params.put("line_items", lineItems);
params.put("mode", "payment");
ArrayList<String> paymentMethodTypes = new ArrayList<>();
paymentMethodTypes.add("card");
paymentMethodTypes.add("sofort");
params.put("payment_method_types", paymentMethodTypes);
Session session = Session.create(params);`
Well, it's not enough because it depnds on your JSON deserializer and how are you configuring it, but I recommend you to use nested POJO Classes instead of Maps
Hi 👋 jumping in as my teammate needs to step away. I believe this line is the problem:
lineItem1.put("price_data", price);
It looks like that is passing the entire Price object that you created rather than deserializing the contents into the appropriate price_data fields.
ok, how can this be fixed?
I believe the price_data is expecting a PriceData object based on this:
https://github.com/stripe/stripe-java/blob/fe51d9d35da97f71906fb6b706d2b7dfcfbdb505/src/main/java/com/stripe/param/SubscriptionItemCreateParams.java#L134
https://github.com/stripe/stripe-java/blob/fe51d9d35da97f71906fb6b706d2b7dfcfbdb505/src/main/java/com/stripe/param/SubscriptionItemCreateParams.java#L510
I'll see what I can find.
This example isn't specifically for Checkout Sessions, but it does show the process for working at the price data level:
https://stripe.com/docs/products-prices/pricing-models#inline-pricing
yeah, but here I have a PriceId
the question is if I can have a Checkout Session without PriceId and ProductId
Yes you can, which is why I linked to the section about inline pricing (the process of dynamically providing price and/or product data instead of providing the ID of a previously created object).
I´m wondering why is this so difficult to create a simple checkout with 1...n items, without define a PriceId and ProductId before.
Our systems require a Price object, so if you don't create a Price ahead of time then we need you to provide enough information to create one dynamically.
ok, so a Price do I need everytime?
will this object stored also in the stripe dashboard?
The line that you circled is regarding the Product object, not the Price object. You do not need to have a Product created ahead of time, and can also create it dynamically via product_data.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data
Using either price_data or product_data will result in an a Price or Product object, respectively, being created and visible in your dashboard.
Our API spec shows that product_data is nested inside of price_data
So from our site, it looks like we are getting the string version of your price object instead of the json hash that we are expecting https://dashboard.stripe.com/test/logs/req_ffqe5jmTEX3zeg
I can look in to the proper syntax. Did passing in an entire price object come from one of our docs? That doesn't seem like what I would think the syntax would be
here is the code for the line item
`// Items
Map<String, Object> lineItem1 = new HashMap<>();
lineItem1.put("quantity", 2);
Price price = new Price();
price.setCurrency("eur");
price.setUnitAmount(Long.valueOf(2000));
price.setType("one_time");
Product product = new Product();
product.setDescription("Test");
product.setName("Test");
product.setDefaultPrice("2000");
price.setProductObject(product);
lineItem1.put("price_data", price);
lineItems.add(lineItem1);`
Thank you, and where did you get that code from? Do some of our docs show passing in a price object like that?
Gotcha. The format of using price data will be very different from how price is used in that doc. The server has been a bit busy but I will able to look again in a minute
ok, thanks
Here we go. I found an example of this in java. Looking to see if we have a good java doc on this somewhere
SessionCreateParams.builder()
.setMode(SessionCreateParams.Mode.PAYMENT)
.setSuccessUrl(domainUrl + "/success.html?session_id={CHECKOUT_SESSION_ID}")
.setCancelUrl(domainUrl + "/canceled.html")
.setPaymentIntentData(
SessionCreateParams.PaymentIntentData.builder()
.setApplicationFeeAmount(computeApplicationFeeAmount(basePrice, quantity))
.build()
)
.addLineItem(
SessionCreateParams.LineItem.builder()
.setQuantity(quantity)
.setPriceData(
SessionCreateParams.LineItem.PriceData.builder()
.setCurrency("usd")
.setUnitAmount(basePrice)
.setProductData(
SessionCreateParams.LineItem.PriceData.ProductData.builder()
.setName("Guitar Lesson")
.addImage("https://i.ibb.co/2PNy7yB/guitar.png")
.build())
.build())
.build())
.build();```
The examples we have in the API reference are a bit outdated. We recommend using this builder syntax now. Is that code snippet helpful enough to show you how to modify your Session creation and define this price with price data?
where can I find computeApplicationFeeAmount ?
ok, but this seems it´s working
thanks
Whoops I took that from a sample with connect accounts. Unless you are a platform charging a fee, you can leave out those lines
and how can I add other payment methods?
In this case, Checkout will show the payment methods that you have enabled in your dashboard https://dashboard.stripe.com/settings/connect/payment_methods
If you leave that out, it will be the ones in your dashboard. With that function you can add the various types defined in this field from our doc https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_method_types
So you can do
.addPaymentMethodType('us_bank_account')
.addPaymentMethodType('afterpay_clearpay')```
Great, that works...
Two other question:
- In the checkout, do I need always the email?
- Instead of webhooks, can I get the answer from the payment also in another way, like return after the successfull URL?
- In the checkout, do I need always the email?
To clarify, are you asking if the Checkout page itself will always ask for email? Or are you asking if you need to provide an email in your code?
- Instead of webhooks, can I get the answer from the payment also in another way, like return after the successfull URL?
We typically recommend listening for both. If you only listen for the user returning to your success URL, you can miss payments if the user loses connection after they pay but before they get back to your website.
So a lot of users mark a payment as paid when they first get a webhook or a return to the success URL
Gotcha. checking in to whether you can turn that off
yea, but my issue is that my application is only local and I have no public uRL
If this is just for testing, you can use a tunneling service like ngrok to get a public URL for testing things like this https://ngrok.com/
Also for testing webhook events you can use the stripe CLI to test without a public URL at all https://stripe.com/docs/webhooks/test