#liam_api

1 messages ยท Page 1 of 1 (latest)

short tapirBOT
#

๐Ÿ‘‹ 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/1315673101778030626

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

austere trout
#

const stripe = require('../utils/StripeClient');
const { ModelsGetAddress } = require('./stripe.Models.addCustomerDetails.userinfo');
const { addStripeCustomerId } = require('./stripe.Models.addCustomerDetails.patchid');
const checkAuthKey = require("../utils/checkAuthKey");

exports.addCustomerDetails = async (req, res) =>
{

//does initial security check.
const checkKey = checkAuthKey(req.headers['key'])

if(checkKey == false)
{
    return res.status(403).send("access denied");
}


//get inital data needed. 
const uid = req.headers['uid'];
const customerData = (await ModelsGetAddress(uid))[0]
const customerFullname = customerData.firstName + ' ' + customerData.lastName;
const customerEmail = customerData.email;
let stripeCustomerId = customerData.stripeCustomerId;


//Only call if customer does not have Stripe account. 
if(stripeCustomerId === null)
{
    //call stripe and create a new customer
    try{
        const stripeCustomerObj = await stripe.customers.create({
            email: customerEmail,
            name: customerEmail,
            description: uid, 
        });

        stripeCustomerId = stripeCustomerObj.id; 
    }
    catch(error)
    {
        return res.status(500).send('stripe API error')
    }

  //put the new customer ID into the data base. 
  const patchresponse = await addStripeCustomerId(uid, stripeCustomerId)

  if(patchresponse === 'error')
  {
    return
  }
}


 //create checkout session id for website.  
const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    customer: stripeCustomerId,
    mode: 'setup',
    success_url: 'https://oceangenesis.co.uk/payment-success',
    cancel_url: 'https://oceangenesis.co.uk/payment-cancel',
});

return res.status(200).send(session.id)

}

#

Hi,
I have this endpoint here in JAvascript whcih calls stripe for a session ID. When i type this into a bowser it shows me this page:

#

Do you know why it doesnt show the checkout page.

robust stream
#

What does the front-end code that redirects them to the page look like?

#

Also, what's the cs_xxx ID of a session you're creating?

austere trout
#

Front end code isn't really developed yet i was just about to start developing it. But I wanted to check to see if the sesion Id's would work with the url first.

#

Here is an example of a session ID: "cs_test_c1fbTQQmHt2u6IA1xqPRB9dhFeKVj83ajMPldRDjEIOivobzbRJHSIfYYf"

robust stream
#

No, you use the url field on the session object that is returned on creation. Not the id

#

I don't really know what URL you're trying to open in the browser as it's truncated

austere trout
robust stream
#

No that won't work. Redirect to the url field

austere trout
#

ahh ok. Thanks for your help I will give it ago now,

robust stream
#

You can just do a redirect server-side in your Node code instead of sending it to your front-end

austere trout
#

OK thanks for your help i just tried to go to the session.url url and it took me to a Stripe checkout page so i think this i sorted. You are a legend javascript developer ๐Ÿ˜†