#blackbearftw_docs

1 messages ¡ Page 1 of 1 (latest)

polar crescentBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1227692717950242847

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

real obsidianBOT
sleek kettle
#

Hello

arctic roost
#

Hi

#

I do need help

#

I cannot figure out for the live of me how to implement this

sleek kettle
#

Can you clarify how the guide is outdated? Are you hitting a specific error or confused about something in particular?

arctic roost
#

well react is outdated, it still uses create-react-app, which is no longer recommended

#

even tho the LTS is 8

#

and I still have no clue how this currently works, I just need someone to help me with that

#

but that doesn't show me which parts the system require

#

and where

#

and what they do

sleek kettle
#

Alright well first to clarify, these quickstarts are meant as demos and a place to get you started. They are not meant to be production code snippets that you just drop in.

#

Second, you are expected as the developer to work through problems you have. I am happy to help with specific questions or errors but I can't walk you through the entire thing or write your code for you.

#

So what have you tried so far and are you running into a specific error?

arctic roost
#

I do not have any error, since I don't have any code

#

I am simply trying to figure out what I need

#

to get this setup

sleek kettle
arctic roost
sleek kettle
#

That is for Stripe Checkout specifically. The API is built around surfacing information based on the Products/Prices that are created. But when you create the Checkout Session itself you specify the Price(s) you want to charge

#

You linked the Subscription Quickstart initially

arctic roost
#

That is what I would like to do

sleek kettle
#

Are you trying to create Subscriptions here or take one-time payments?

arctic roost
#

subscriptions

sleek kettle
arctic roost
#

I would allow the user to click one of the subscription options -> redirect them to stripe checkout -> (where to go from here?)

#

what is the lookup key?

sleek kettle
sleek kettle
arctic roost
#

Also do I have to hardcode the price id in the frontend?

<input type="hidden" name="priceId" value="price_G0FvDp6vZvdwRZ" />

sleek kettle
#

No you don't have to. That's up to you really. You can if you want to, or you can map these Price IDs to your own identifier and then look them up based on that identifier in your backend

arctic roost
#

or is that the purpose of the lookup key?

sleek kettle
#

Yep

#

You basically would use that to dictate what is returned to your frontend instead of hard coding text.

#

But once again, not required.

#

I'd recommend not worrying about that to just get up and running here

arctic roost
#

Alright

#

But one thing that I am going to do different from the docs is that I won't redirect, I have a rest api, I am making a fetch request to my backend. So this code block isn't totally accurate at the end.

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
StripeConfiguration.ApiKey = "";

// The price ID passed from the front end.
// You can extract the form value with the following:
//   var priceId = Request.Form["priceId"];
var priceId = "{{PRICE_ID}}";

var options = new SessionCreateOptions
{
  // See https://stripe.com/docs/api/checkout/sessions/create
  // for additional parameters to pass.
  // {CHECKOUT_SESSION_ID} is a string literal; do not change it!
  // the actual Session ID is returned in the query parameter when your customer
  // is redirected to the success page.
  SuccessUrl = "https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}",
  CancelUrl = "https://example.com/canceled.html",
  Mode = "subscription",
  LineItems = new List<SessionLineItemOptions>
  {
    new SessionLineItemOptions
    {
      Price = priceId,
      // For metered billing, do not pass quantity
      Quantity = 1,
    },
  },
};

var service = new SessionService();
var session = await service.CreateAsync(options);

// Redirect to the URL returned on the Checkout Session.
//   Response.Headers.Add("Location", session.Url);
//   return new StatusCodeResult(303);
sleek kettle
#

Please redact your secret key above

#

Even though it is your test key it still gives access to your account

arctic roost
#

alright

sleek kettle
#

And this is a public server

arctic roost
#

Done

#

anyhow

#

I won't redirect the user

#

my api endpoint would just return a response

#

but what would it respond with

#

and what would happen after that?

sleek kettle
#

I'm not sure I understand what you mean by that. You are saying you don't want to use Stripe Checkout? You want to use a custom form in your own site?

arctic roost
#

No

#

this example assumes I have a html form in the frontend

#

that I will submit it, that the post request will redirect the user to the backend and that will redirect them to stripe checkout

sleek kettle
#

Yep

arctic roost
#

but I won't have a form like that, I will have a simple button, which makes a fetch request to my backend and my backend will return a json response

#

it can't redirect the user

sleek kettle
#

That's fine, you can just return the Checkout Session URL to your frontend and redirect client-side

#

That works fine too

arctic roost
#

so you would do that and not the session id?

sleek kettle
#

The session.Url is where the customer is going to get redirected

#

So instead of redirecting to that URL server-side, you respond to your fetch request with that URL and then redirect client-side to that URL

arctic roost
#

okay

#

but the rest then stays the same?

sleek kettle
#

From the code snippet above?

arctic roost
#

yeah

sleek kettle
#

Yeah, the rest of the code there just creates the Checkout Session

arctic roost
#

@sleek kettle I am trying to figure out what property to return, its not session.url

#

sorry

#

it was

#

is it possible to allow the user on the checkout page to decide if they want to pay monthly or yearly?

#

or do I have to do that before creating the session?

sleek kettle
#

No that would have to be decided beforehand

arctic roost
#

alright that redirect url works

#

the question is what do I now do with that session id that was returned?

sleek kettle
arctic roost
#

does that just allow me to customize the success page?

sleek kettle
#

Yes

#

You can retrieve the Checkout Session using that ID to show relevant details to your customer

arctic roost
#

mhm alright

#

Thanks for now, ill continue tommorow

#

Sorry that I was a bit rude in the beginning, but I was just frustrated I have been trying to fix this for the last couple of weeks

sleek kettle
#

All good. We are around 24/5 to help with any specific questions that you have!