#Durrell-source

1 messages ยท Page 1 of 1 (latest)

analog mica
#

๐Ÿ‘‹

#

does this source belong to a connected account?

modern trellis
#

yes

analog mica
#

gotcha, seems like you're passing the connected account ID as part of the body rather than in the header

#

oh wait you're using Stripe.js

modern trellis
#

correct. The call is working on the server. Just not the client

analog mica
modern trellis
#

yes I am. I'm also seeing the connected account's stripe_account in the Headers from the request in my network tab in Chrome.

analog mica
#

can you share the example code?

modern trellis
#
    const stripe = window.Stripe(stripePublishableKey, {
      stripeAccount: 'acct_1LKW3xQsplVDpaCb'
    })
analog mica
#

huh not seeing why this is failing

#

Have you tried logging out the client secret to see if they match?

modern trellis
#

I'm not sure if this will help, but here is the request_id of the call that is working on the server: req_gdF7oqGehgwjvYest_id

#

I'm literally hard coding the client secret in the client for now, for test purposes.

#

sorry, typo. here is the request_id from the server: req_gdF7oqGehgwjvY

analog mica
#

all good. did the hard-coding secret work?

modern trellis
#

no, it was hard coded from the begining

analog mica
#

can you share your complete code?
I wonder if there's something minor that I'm missing here

modern trellis
#
  const getStripeSource = async () => {
    const stripe = window.Stripe(stripePublishableKey, {
      stripeAccount: 'acct_1LKW3xQsplVDpaCb'
    })

    const { error, source } = await stripe.retrieveSource({
      client_secret: 'src_client_secret_eOWvuQtw2PPN6bbPFrPmMwuS',
      id: 'src_1LKWVcQsplVDpaCbQXX7km4G'
    })

    if (error) {
      console.log('error', error)
    }
    if (source) {
      console.log('source', source)
    }
  }

  getStripeSource()
analog mica
#

huh that does look fine ๐Ÿค”
Is there anyway your stripe object is being reinitialized somewhere?

modern trellis
#

I don't think so. Just above the code I pasted above I'm doing this:

  useEffect(() => {
    if (!(window as any).Stripe) {
      loadStripe(stripePublishableKey)
    }
    return null
  }, [])

Since I'm able to get the source from the server side call I can just make a call from the client to get the source from the server instead of going straight to Stripe from the client. The reason why I was trying to make this call from the client is because I was hoping to get the full account number from the client side call. The server side call only returns the last4 digits of the account number.

Does the client side call return the full account number? The source object docs show the full account number. https://stripe.com/docs/api/sources/object
For example: "account_number": "test_52796e3294dc"

I was thinking the server side call only returns the last4 for PCI compliance reasons, but I was hoping the client side call would return the full account number.

analog mica
#

Likely that the useEffect is causing the issue here

modern trellis
#

If I put a console.log in that useEffect I can see it only loads once. For example:

  useEffect(() => {
    if (!(window as any).Stripe) {
      console.log('Loading Stripe.js')
      loadStripe(stripePublishableKey)
    }
    return null
  }, [])

Does the client side call return the full account number?

analog mica
#

I haven't tested this myself unfortunately so I don't know, give me a sec

#

So using loadStripe with useEffect isn't recommended approach here

The stripe instance is tied to a specific account, so there is no way to update the account once created. What you can do however is create another Stripe instance for the other account. Since the Elements provider component can only be tied to a single stripe instance, you'll need to instruct React to create a new component using a key prop. That will force a re-render of all children of Elements.

https://github.com/stripe/react-stripe-js/issues/107#issuecomment-657866413

#

Does the client side call return the full account number?
I'll test this out and let you know

analog mica
#

okay sorry that took a while but client-side retrieval will also just give you the last 4

modern trellis
#

ok. Thank you for your time. I really appreciate it.

analog mica
#

NP! ๐Ÿ™‚ Appreciate you patience

modern trellis
#

when I make that call on the server I get this:

"object": "source",
"ach_debit": {..."last4":"6789"}

but the docs show this:

"object": "source",
  "ach_credit_transfer": {
    "account_number": "test_52796e3294dc", ...}

Am I looking at the wrong object in the docs? I'm using the latest version of the Stripe gem.

latent crest
#

HI ๐Ÿ‘‹ @analog mica needed to step away so I'm stepping in. Can you share the request ID for that request?

modern trellis
#

req_gdF7oqGehgwjvY

latent crest
#

But this source is an ACH debit payment method. So the response makes sense

modern trellis
#

ok. Thank you.