#empress-testing
1 messages · Page 1 of 1 (latest)
thats a code on your end not ours
?
This is a Stripe partner challenge, so that lessons_courses.js is from the stripe programmed testing suite
not sure I follow. You say 'Stripes Cypress test' but I don't know what that is.
hmm ok. I'm not familiar with the details of that program
no worries lol, it seems like the left foot doesn't talk to the right foot at stripe lol
I suggest reaching out to your contacts involved with that.
yeah I will, just wanted to see if there was something wrong with the data we're sending in lol
the error implies the backend code is trying to access something like a PaymentMethod that's unexpectedly undefined. Don't have more context than that.
this is whats in the testing suite at that line:
it('Should set Name and Email on both the Customer and the Payment Method Objects:3.29', () => {
expect(retrieveCustomerResponse.status).to.eq(200);
expect(retrieveCustomerResponse.statusText).to.eq('OK');
expect(retrieveCustomerResponse.isOkStatusCode).to.be.true;
expect(retrieveCustomerResponse.body.name).to.exist;
expect(retrieveCustomerResponse.body.email).to.exist;
expect(retrieveCustomerResponse.body.name).to.not.be.null;
expect(retrieveCustomerResponse.body.email).to.not.be.null;
expect(retrieveCustomerResponse.body.name).to.eq(name);
expect(retrieveCustomerResponse.body.email).to.eq(email);
expect(paymentMethodResponse.body.data[0].billing_details.name).to.exist;
expect(paymentMethodResponse.body.data[0].billing_details.email).to.exist;
expect(paymentMethodResponse.body.data[0].billing_details.name).to.not.be.null;
expect(paymentMethodResponse.body.data[0].billing_details.email).to.not.be.null;
expect(paymentMethodResponse.body.data[0].billing_details.name).to.eq(name);
expect(paymentMethodResponse.body.data[0].billing_details.email).to.eq(email);
});
sounds like paymentMethodResponse.body.data[0] is undefined.
hmmm so weird, alright i'll look around there. thanks karllekko
Does stripe.confirmCardSetup save the card method?
which the documentation seems to indicate it does but it oddly isn't ?
When you confirm a SetupIntent, it needs to have an attached PaymentMethod. In addition to confirming the SetupIntent, this method can automatically create and attach a new PaymentMethod for you.
👋 taking over for my colleague. Let me catch up.
thanks tarzan
but it oddly isn't ?
what do you mean by that?
It seems like thats what's causing this, it's doing everything but saving the payment method
could you please share a request id? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
req_o1jnsXt35SQzJs
it's weird because it still returns the last 4 digits of the card lol
you're creating a setup intent in that request but you're not passing the client_secret to the front-end to be used with Stripe Elements
I gave the wrong ID, that was my bad
req_99PZKdPoVwBsS8
it makes a paymentintent on every page load but that is an actual post
usually SetupIntents are meant to be used with customers
yeah, it does a SetupIntent on page load, once form is submitted it makes a Customer and then makes a confirmcardsetup call
your request req_aJsLwZczwCI0FX created a SetupIntent that is not attached to a customer thus when you confirm it, it doesn't get attached to a customer
you need to set the customer id for that setup intent before confirmCardSetup
interesting okay
thanks for the help i'll try that
so it should go:
Create Customer - > Create SetupIntent -> Create Payment
yes
sweeeet
or even create customer -> create payment (with setup_future_usage)
oh sweeet thats a good catch, thanks tarzan
@narrow lark Thanks again for the help. I think i'm getting close but now I have a weird error :v
{
"error": "Invalid string: {:invoice_prefix=>\"9BF446E5\", :description=>\"\", :delinquent=>\"false\", :metadata=>{:first_lesson=>\"12 Sept 4:00 p.m.\"}, :id=>\"cus_MKmbbaDkb9hgDe\", :object=>\"customer\", :default_currency=>\"\", :discount=>\"\", :balance=>\"0\", :test_clock=>\"\", :invoice_settings=>{:custom_fields=>\"\", :footer=>\"\", :default_payment_method=>\"\", :rendering_options=>\"\"}, :name=>\"br k\", :livemode=>\"false\", :next_invoice_sequence=>\"1\", :phone=>\"\", :currency=>\"\", :tax_exempt=>\"none\", :address=>\"\", :created=>\"1661775959\", :default_source=>\"\", :email=>\"brksdf@brk.com\", :shipping=>\"\"}"
}
how did you get to this? what is the request?
req_CmIPvou4CHRVzn
The server code:
let customer = await stripe.customers.create().then(async (response) => {
let responseid = response.id
let customerdeets = stripe.customers.update(
responseid,
{
email: req.query.email,
name: req.query.name,
metadata: {
first_lesson: `${req.query.lesson}`
}
}
).then(async (response)=>{
try{
let paymentMethod = await stripe.paymentMethods.retrieve(
req.query.pm
).then(async (data) => {
const setupIntent = await stripe.setupIntents.update(req.query.cs, {
customer: response,
payment_method: data.id
}).then((response)=>{
res.send({
paymentMethod: data,
customer: response
})
}).catch((e)=>{
res.status(402).send({error: e.message});
})
}).catch((e)=>{
res.status(402).send({error: e.message})
})
}catch(e){
res.status(402).send({error: e.message})
}
})
customer: response, should be customer: response.id,
embarrasing haha . thanks
no, don't be! no worries this happens
but I would say that since you're using await, why chain with .thens?
there's a lot of things to improve in that code, for instance why are you waiting for the customer to be created to then pass the email, name, etc. these params could be passed in the create method
the payment method shouldn't be collected first
you should create a setupIntent/payment intent
pass the client_secret to the front-end and let that do the rest
the stripe boilerplate is pretty broken so we have to chain thens to make it work with the testing software lol
i guess this is a new thing Stripe is doing and we're one of the guinea pigs lol
I'm not sure what you mean, but this is javascript-related not Stripe related
you can either use .then or await to deal with promises
gotcha
yeah the stripe challenge makes you have to create back end routines for some odd reason but otherwise I agree, it would've been smarter to do this all on the front end
@narrow lark I guess i'm still a little confused. It looks like you can't do anything with creating payments without the setupintent ID. so right now my program goes:
- Create SetupIntent
- ConfirmCardSetup with 1's ID & the card
- Create Customer and then update the setupintents
Which obviously errors out because step 2 confirms the SI. What can I use instead of confirmCardSetup to assign a card to the SetupIntent on the front end?
Hello, tarzan is stepping out but I can help. Catching up on this thread now
no worries, thanks
yeah I think I just need to figure out how to create a payment on without confirming at the same time
Hey apologies but I got sidetracked when catching up. What error are you getting on step 2 there? Is it still the one about the payment method not existing yet?
no worries and yeah
erm
"message": "You cannot update this SetupIntent because it has already succeeded.",
I think I am unclear on the end goal of this process, so you are creating a payment method first and then trying to attach it to a setup intent. Is there a reason you aren't just creating and confirming the setup intent for the customer?
nah, i'm creating a setup intent and I need to then assign a card to that SI on the front end, and then send a POST request on the backend to fill in some additional information
what i'm getting stuck at is how do you add a card to a SI on the front end without using confirmCardSetup
so i guess im also confused as to what the correct order is...is it:
- Create Customer
- Create SetupIntent with id from 1
- ConfirmCardSetup with id from 2
Are those the steps laid out in the partnership test or are these your steps given the end goal?
It's kinda both. THe partnership test has these restrictions:
Complete the Lessons page and implement a POST /lessons endpoint for signing up the student. Our designer prepared some mockups, click to expand:
After the student successfully signs up for a lesson, complete the message in the id="signup-status" div to show the new customer id and the last 4 digits of their card.
Make sure you have only one Customer object per email address. If a student tries to sign up again with the same email address, have the app show them the included error message and provide them with a link to the account-update page where they can update their payment information.
Save the provided name and email address on the billing details for both the Customer and the Payment Method. Make sure the Customer only ever has one saved payment method.
Add a metadata field to the Customer named first_lesson which is set to the lesson date and time they select. We'll use this later to determine when to make the first payment.
Oh wait, those second three steps sound more like what I would expect
this is what i'm attempting to do, blue is front end functions yellow is backend
So yeah, creating the customer then a setupintent for that customer should work here. Then you can directly update the customer or payment method if it doesn't have the proper details