#empress-testing

1 messages · Page 1 of 1 (latest)

wraith cloak
#

what's the exact code at lessons_courses.js:333:47 for example?

dense breach
#

thats a code on your end not ours

wraith cloak
#

?

dense breach
#

This is a Stripe partner challenge, so that lessons_courses.js is from the stripe programmed testing suite

wraith cloak
#

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

dense breach
#

no worries lol, it seems like the left foot doesn't talk to the right foot at stripe lol

wraith cloak
#

I suggest reaching out to your contacts involved with that.

dense breach
#

yeah I will, just wanted to see if there was something wrong with the data we're sending in lol

wraith cloak
#

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.

dense breach
#

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

    });
wraith cloak
#

sounds like paymentMethodResponse.body.data[0] is undefined.

dense breach
#

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. 
narrow lark
#

👋 taking over for my colleague. Let me catch up.

dense breach
#

thanks tarzan

narrow lark
#

but it oddly isn't ?
what do you mean by that?

dense breach
#

It seems like thats what's causing this, it's doing everything but saving the payment method

narrow lark
dense breach
#

req_o1jnsXt35SQzJs

#

it's weird because it still returns the last 4 digits of the card lol

narrow lark
#

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

dense breach
#

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

narrow lark
#

usually SetupIntents are meant to be used with customers

dense breach
#

yeah, it does a SetupIntent on page load, once form is submitted it makes a Customer and then makes a confirmcardsetup call

narrow lark
#

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

dense breach
#

interesting okay

#

thanks for the help i'll try that

#

so it should go:

Create Customer - > Create SetupIntent -> Create Payment

narrow lark
#

yes

dense breach
#

sweeeet

narrow lark
#

or even create customer -> create payment (with setup_future_usage)

dense breach
#

oh sweeet thats a good catch, thanks tarzan

dense breach
#

@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=>\"\"}"
}
narrow lark
#

how did you get to this? what is the request?

dense breach
#

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

            })
narrow lark
dense breach
#

embarrasing haha . thanks

narrow lark
#

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

dense breach
#

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

narrow lark
#

you can either use .then or await to deal with promises

dense breach
#

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

dense breach
#

@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:

  1. Create SetupIntent
  2. ConfirmCardSetup with 1's ID & the card
  3. 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?

solid solstice
#

Hello, tarzan is stepping out but I can help. Catching up on this thread now

dense breach
#

no worries, thanks

dense breach
#

yeah I think I just need to figure out how to create a payment on without confirming at the same time

solid solstice
#

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?

dense breach
#

no worries and yeah

#

erm

#

"message": "You cannot update this SetupIntent because it has already succeeded.",

solid solstice
#

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?

dense breach
#

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:

  1. Create Customer
  2. Create SetupIntent with id from 1
  3. ConfirmCardSetup with id from 2
solid solstice
#

Are those the steps laid out in the partnership test or are these your steps given the end goal?

dense breach
#

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.
solid solstice
#

Oh wait, those second three steps sound more like what I would expect

dense breach
#

this is what i'm attempting to do, blue is front end functions yellow is backend

solid solstice
#

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