#zeke_api

1 messages · Page 1 of 1 (latest)

toxic zealotBOT
woeful ridgeBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

toxic zealotBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1259876703602475110

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

thorn parcel
#

Hi Pompey!

torpid citrus
#

Hello 👋

#

Can you tell me more about your usecase? How are you currently charging through Stripe? Checkout? Your own elements page?

thorn parcel
#

Yes! So ive connected stipe via a chekout page Which I belive is the default way to connect stripe. Im new to this so sorry If i word things weird im just learning!

torpid citrus
#

Gotcha, so with Checkout you are either manually setting a price per session or you are using Price objects

#

If you are setting the price via price_data, you can just start passing prices that are 10% higher going forward. If you are using Price objects, you will need to define new ones for your higher prices and then pass those IDs going forward

thorn parcel
#

Price per session seems right because it is a marketplace people can set there own price

torpid citrus
thorn parcel
#

So this allows my company to take 10% of each product sold on my marketplace?

torpid citrus
#

Ah sorry I misunderstood your question. So you are talking about setting your platform fee.

thorn parcel
#

Maybe. let me explain a little more thats my fault!

#

So Im building a ecommerce marketplace which alows sellers and creators to sell digital products like Software, Courses, Templates. When someone signs up and starts selling and one of there products gets bought I would like to take 10% from that order and 90% of the money will get sent to the seller.

#

Just so my business/website can make a profit and not take a loss

torpid citrus
#

Gotcha, and have you looked in to the Connect charge types and decided on which one you want to go with? https://docs.stripe.com/connect/charges

Learn how to create a charge and split payments between your platform and your sellers or service providers when you accept payments.

thorn parcel
#

No but I will right now and let you know!

torpid citrus
#

Sounds good! It is pretty straightforward to apply those to Checkout once you have chosen. Basically there is a payment_intent_data parameter when creating a checkout session. You can set application_fee_amount if you are using the direct charges flow or transfer_data if you are using the destination charges flow
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-payment_intent_data-application_fee_amount

#

And definitely let me know if you run in to any questions about which may be better for your situation

thorn parcel
#

I think im leaning towards Direct

#

That sounds like what Im trying to do

#

Do I need to create a seperate file for the payment_intent_data? Ive created a payment-router.ts and was wondering if I could put the application_fee_amount & transfer_data in it

torpid citrus
#

This should be more of adding lines to the existing file. This will be a part of the same API call that you are already making to create these checkout sessions

thorn parcel
#

Ok Sweet

#

Will I have to add anything to my dashboard via stripe?

#

Does this look right?!

// Calculate the total amount
const totalAmount = filteredProducts.reduce(
(total, product) => total + (product.priceId ? parseInt(product.priceId, 10) : 0),
0
);

    // Calculate the application fee (10% of the total amount)
    const applicationFeeAmount = Math.floor(totalAmount * 0.10);

    // Create the Stripe Checkout Session with application fee and transfer data
    const stripeSession = await stripe.checkout.sessions.create({
      success_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/thank-you?orderId=${order.id}`,
      cancel_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/cart`,
      payment_method_types: ["card"],
      mode: "payment",
      metadata: {
        userId: user.id,
        orderId: order.id,
      },
      line_items,
      payment_intent_data: {
        application_fee_amount: applicationFeeAmount,
        transfer_data: {
          amount: totalAmount - applicationFeeAmount,
          destination: "connected_account_id", // Replace with the actual connected account ID
        },
      },
    });
torpid citrus
#

For direct charges, you will only want to use application_fee_amount, you can remove transfer_data from your code. Both of those are trying to do basically the same thing, but those two parameters are for two different flows, so the API won't know what to do if you pass both. If you remove that and test this call out in test mode, does everything seem to work from there?
And you don't need to change anything in your dashboard, these fees are set on a per payment or per subscription basis, so setting this in your code is all that you need to do.

thorn parcel
torpid citrus
#

That is one way, you also should be able to see a payment for the amount of your application fee in your platform account's dashboard

thorn parcel
#

Were in the dashboard!?

torpid citrus
thorn parcel
#

In collected fees tab it says I have no results

torpid citrus
#

Can you send me the ID of the checkout session that you completed that this should be showing for? (cs_test_123)

thorn parcel
#

cs_test_b18uPnDyAcHQ9HVSJcgL8Jga2OxbA9S1UsYXNuKyDiJZfdHvTB8c7ClI4T

toxic zealotBOT
torpid citrus
#

Is it possible that you ran an older version of the code that didn't have the new application fee stuff that you added?

thorn parcel
#

Hmmm let me show you I do not believe so

#

Here are the two files in which contain stripe

sour crow
#

Hi there 👋 taking over, as my colleague needs to step away

As far as I can tell, there was no application_fee added as a parameter to the request that created that checkout session

thorn parcel
#

Hi! Interesting could you expand a little more! Sorry I’m pretty new to this

#

This is in my payment-router.ts

const stripeSession = await stripe.checkout.sessions.create({
success_url: ${process.env.NEXT_PUBLIC_SERVER_URL}/thank-you?orderId=${order.id},
cancel_url: ${process.env.NEXT_PUBLIC_SERVER_URL}/cart,
payment_method_types: ["card"],
mode: "payment",
metadata: {
userId: user.id,
orderId: order.id,
},
line_items,
payment_intent_data: {
application_fee_amount: applicationFeeAmount,
},
});

#

// Calculate the total amount
const totalAmount = filteredProducts.reduce(
(total, product) =>
total + (product.priceId ? parseInt(product.priceId, 10) : 0),
0
);

    // Calculate the application fee (10% of the total amount)
    const applicationFeeAmount = Math.floor(totalAmount * 0.1);
sour crow
#

Not really. The request you sent to Stripe didn't contain an application_fee. For whatever reason, the code you're posting is not the code that created this Checkout Session: cs_test_b18uPnDyAcHQ9HVSJcgL8Jga2OxbA9S1UsYXNuKyDiJZfdHvTB8c7ClI4T

thorn parcel
#

Ok give me one second! I bet im looing in the wrong place!

#

Found it!

#

is the checkoutsession considered a webhook?

sour crow
#

No, but a webhook might contain a checkout session

thorn parcel
#

Check this one please

#

cs_test_b1DrgI7BkEKAWj5ZwoFsQewI4nlwFtiShl8VuRAMWA2XOPK2RjBGcuz1hE

sour crow
#

Do you know how to view logs in your dashboard? You can check the request's parameters yourself to see what was passed in.

https://support.stripe.com/questions/finding-the-id-for-an-api-request

thorn parcel
#

listen man I cant get it im not sure what im doing wrong here

sour crow
#

You're in your Developer section of the Dashboard looking at the Logs and you can't find the request you just made to create that Checkout Session?

thorn parcel
#

No I know how to see logs 😂 I’m trying to create a 10% deduction from all products sold on my site. It’s a marketplace which allows people to sign up and post products when someone buys the product the seller should get 90% of what they sold I should get 10% because it’s my marketplace.

#

The previous person told me to use application_fee_amount

sour crow
#

Yeah, you're gonna need to figure out why the code you're posting isn't using an application_fee. The Previous person was right. But you still haven't figured out why the code you posted in this thread is different from the code that's running when you create a Checkout Session

thorn parcel
#

Yes and that’s were I’m stuck. What’s should I be looking for code wise to find where the stripe session is being created

sour crow
#

I can't really help you there. You're the developer. You should be able to track down where your code is running from

thorn parcel
#

Kinda brand new to this but I’ll figure it out and get back to you

thorn parcel
#

Yo I have an error I need help with can you close this thread or can you answer it?

I get this in my logs 400 ERR

resource_missing - line_items[1][price]

sour crow
thorn parcel
#

req_utNLlvNZfZaier

sour crow
#

The error message indicates that the Price object you're using doesn't exist on that account. A different account has that Price, but not the one that created the request

thorn parcel
#

I got it thank you!

thorn parcel
# sour crow The error message indicates that the Price object you're using doesn't exist on ...

Heres another one I think I know what it is asked but I just want to double check with you.

ERR:
parameter_invalid_integer - payment_intent_data[application_fee_amount]

ID:
req_s3K0cL3IicgYsL

Its telling me I've put down the amount fee wrong for example I put

// Calculate the total amount
const totalAmount = filteredProducts.reduce(
(total, product) =>
total + (product.priceId ? parseInt(product.priceId, 10) : 0),
0
);

    // Calculate the application fee (10% of the total amount)
    const applicationFeeAmount = Math.floor(totalAmount * 0.1);

    // Create the Stripe Checkout Session with application fee and transfer data
    const stripeSession = await stripe.checkout.sessions.create({
      success_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/thank-you?orderId=${order.id}`,
      cancel_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/cart`,
      payment_method_types: ["card"],
      mode: "payment",
      metadata: {
        userId: user.id,
        orderId: order.id,
      },
      line_items,
      payment_intent_data: {
        application_fee_amount: applicationFeeAmount,
        transfer_data: {
          destination: "connected_account_id", // Replace with the actual connected account ID
        },
      },
    });
sour crow
#

If you look at that Request in the Dashboard, what is the error message?

thorn parcel
#

parameter_invalid_integer - payment_intent_data[application_fee_amount]
Looks like you passed the wrong value for the application_fee_amount field.

The value of this field should be positive integer, in the smallest unit for the given currency.

For example, $10 should be 1000.

For further details on this field see the application fee amount subsection in the API reference.

Was this useful?

Yes

No

#

SO if i wanted to take 10% what should my integer look like? 1.0000? .001? 10 itself?

#

10.0

#

0.1?

#

I bet its 100

sour crow
#

None of those are integers

#

Except 100

#

100 is an integer

thorn parcel
#

@sour crow Heres what I tried

// Calculate the application fee (10% of the total amount in cents)
const applicationFeeAmount = Math.floor(totalAmount * 100);

    // Create the Stripe Checkout Session with application fee and transfer data
    const stripeSession = await stripe.checkout.sessions.create({
      success_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/thank-you?orderId=${order.id}`,
      cancel_url: `${process.env.NEXT_PUBLIC_SERVER_URL}/cart`,
      payment_method_types: ["card"],
      mode: "payment",
      metadata: {
        userId: user.id,
        orderId: order.id,
      },
      line_items,
      payment_intent_data: {
        application_fee_amount: 100,
        transfer_data: {
          destination: "connected_account_id", // Replace with the actual connected account ID
        },
      },
    });
#

it did not work it still tells me:

parameter_invalid_integer - payment_intent_data[application_fee_amount]
Looks like you passed the wrong value for the application_fee_amount field.

The value of this field should be positive integer, in the smallest unit for the given currency.

For example, $10 should be 1000.

For further details on this field see the application fee amount subsection in the API reference.

sour crow
#

That sends $1.00 as an application fee

#

Do you have a request id?

thorn parcel
#

"cancel_url": "http://localhost:3000/cart",
"payment_intent_data": {
"application_fee_amount": "NaN",
"transfer_data": {
"destination": "connected_account_id"
}
},

#

req_4C7dtkYQHcavsd

sour crow
#

yeah, you're not sending a number for some reason

#

NaN means: Not a Number

thorn parcel
#

Yeah

#

Got anything🤔

sour crow
#

I mean, it looks like the code is not what's actually running when you create the Checkout Session. If you were actually passing application_fee_amount: 100 then you wouldn't be getting that error

thorn parcel
#

im confused why this does not work

const applicationFeeAmount = Math.floor(totalAmount * 0.1);

#

because its not an integer?

sour crow
#

math.floor() rounds to the nearest integer, as far as I know, but it doesn't necessarily mean the value of the applicationFeeAmount is an int type. You should do a console log of the value and the type of the value before the checkout session is created to see if it's actually an integer or not

#

Does it work when you just hardcode the 100 value in? Instead of using the applicationFeeAmount variable?

thorn parcel
#

I was just about to do that let me try!

thorn parcel
#

could you explain this a little?

parameter_missing - application_fee_amount
Looks like you are missing the application_fee_amount field. This field allows the platform to take an application fee on direct charges. It can be any positive number up to the amount of the charge.

#

req_Kb5e7LN9LF0SOb

#

welcome back pompey😂

torpid citrus
#

Hello 👋