#commander - Price

1 messages · Page 1 of 1 (latest)

hidden gale
#

👋 Thanks for reaching out

torn geode
#

thanks

#

I tried this already, but seems not working

hidden gale
torn geode
#

req_rfUjrHpwuyQ1rl

hidden gale
torn geode
#

yeah, but any idea whats wrong?

hidden gale
#

Can you share the whole code that is responsible for creating the request ?

torn geode
#

` 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);`
hidden gale
#

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

hard canopy
#

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.

torn geode
#

ok, how can this be fixed?

torn geode
#

I dont think so

#

req_NFfvo2IqE1rbml

hard canopy
#

I'll see what I can find.

torn geode
#

yeah, but here I have a PriceId

#

the question is if I can have a Checkout Session without PriceId and ProductId

hard canopy
#

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).

torn geode
#

I´m wondering why is this so difficult to create a simple checkout with 1...n items, without define a PriceId and ProductId before.

hard canopy
#

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.

torn geode
#

ok, so a Price do I need everytime?

#

will this object stored also in the stripe dashboard?

hard canopy
#

Using either price_data or product_data will result in an a Price or Product object, respectively, being created and visible in your dashboard.

torn geode
#

Received unknown parameter: line_items[0][product_data]

hard canopy
#

Our API spec shows that product_data is nested inside of price_data

torn geode
umbral mortar
#

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

torn geode
#

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);`
umbral mortar
#

Thank you, and where did you get that code from? Do some of our docs show passing in a price object like that?

torn geode
#

but here we have productId

umbral mortar
#

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

torn geode
#

ok, thanks

umbral mortar
#

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?

torn geode
#

where can I find computeApplicationFeeAmount ?

#

ok, but this seems it´s working

#

thanks

umbral mortar
#

Whoops I took that from a sample with connect accounts. Unless you are a platform charging a fee, you can leave out those lines

torn geode
#

and how can I add other payment methods?

umbral mortar
torn geode
#

yeah, but i need from the programm

umbral mortar
#

So you can do

.addPaymentMethodType('us_bank_account')
.addPaymentMethodType('afterpay_clearpay')```
torn geode
#

Great, that works...
Two other question:

  1. In the checkout, do I need always the email?
  2. Instead of webhooks, can I get the answer from the payment also in another way, like return after the successfull URL?
umbral mortar
#
  1. 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?
#
  1. 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

torn geode
#
  1. Yes in the checekout page
umbral mortar
#

Gotcha. checking in to whether you can turn that off

torn geode
#

yea, but my issue is that my application is only local and I have no public uRL

umbral mortar
#

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/