#RSS1N2 - PaymentMethod error

1 messages · Page 1 of 1 (latest)

dry fiber
#

So you are getting that error message because each Stripe object "lives" on some account. That PaymentMethod is on the platform account but you are trying to use it with the connected account.

To use this PaymentMethod you can clone the PaymentMethod down to the connected account. You can use the new PaymentMethod from the cloning process in the call you were just doing. https://stripe.com/docs/payments/payment-methods/connect

winter oar
#

I see. Is the cloning process intended to be done on the server? Or can it be done in the client following my existing CreatePaymentMethod() call?

dry fiber
#

Yes, it should be done on the server.

#

Our client side libraries don't have the functionality and a public key would not have the permissions to do this

#

So you will need to use it with your server-side library and a secret key

winter oar
#

Got it. That leaves me with one last point of confusion: I collect the card info on the client, and pass in the info to CreatePaymentMethod: const {error, paymentMethod} = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement)
})

#

Do I continue to do this and just do the clone on the server, or should I create the PaymentMethod on the server as well?

stoic sky
#

Hey @winter oar! Jumping in here for @dry fiber as he needs to step away.

#

You are fine to create the PaymentMethod on the client but then pass that ID to the server (or use Webhooks) to then clone from the server.

#

You don't want to create the PaymentMethod on the server, as that would involve handling sensitive card data from your end.

winter oar
#

Awesome. Thanks for the clarification. I'll give it a try.

#

This cloning call appears to require a field (customer) I don't have. Is it required? I'm already supplying the connected account id.

#

const paymentMethod = await stripe.paymentMethods.create({
customer: '{{CUSTOMER_ID}}',
payment_method: '{{PAYMENT_METHOD_ID}}',
}, {
stripeAccount: '{{CONNECTED_ACCOUNT_ID}}',
});

stoic sky
#

Let's back up for just a second here to make sure you are going down the correct path... you are switching to Direct Charges, correct?

winter oar
#

Yes, I believe so. My old code currently makes a charge to the customer's card and sends it to my Stripe account. I am upgrading the code so that the customer's charged money goes to a member of my 'platform', and I receive a fee.

stoic sky
#

Got it and currently you make a transfer from your Platform to the Connected Account?

#

What type of Connected Accounts are you using?

winter oar
#

No, my old code has no integration with Connect. I am doing the conversion now. Background: My website hosts tournaments created on my website by other people (my customers?). People sign up and pay the creator of the tournament to participate in the creator's tournament. In the past, I would change my Stripe bank settings to point to the tournament creator's account (crude I know). Now I am integrating with Connect with the hopes of sending tournament participant payments directly to the tournament creators, with my small fee sent to my account.

stoic sky
#

Thanks for the details!

#

Okay last question: are you planning on using the customer's PaymentMethod across multiple Connected Accounts?

#

Or is it just that the customer would only be paying the one Connected Account?

winter oar
#

Just 1:1

stoic sky
#

Okay in that case no need to clone at all!

winter oar
#

Fascinating....do you mean something like this on the client?

#

const {error, paymentMethod} = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement)
}, {
stripeAcount: 'acct_1IqNF*****'
})

stoic sky
#

Exactly!

#

Woops actually sorry

#

You would do this when you initialize your publishable key

#

What you did above is how you would pass it on your Server

#

But you can't do per-request on your Client

#

So it would be var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx', { stripeAccount: '{{CONNECTED_ACCOUNT_ID}}', });

winter oar
#

Ok, I think I'm getting it. But need further clarification. Currently I initialize the stripe variable at the top of my app (in app.js) and then use it globally via useStripe() hook. If I understand you, I should now initialize another local stripe instance for this createPaymentMethod method call since its custom to the connected account. Is that correct?

stoic sky
#

You would initialize your stripePromise for each customer with the correct Stripe Account based on who they are attempting to pay, then that would cause your Element to render accordingly. I don't think you need a local instance unless the customer is also taking actions on your platform at the same time, which it doesn't sound like they are?

#

Is the issue that you won't know initially who your customer is going to pay so you don't know which account to initialize Stripe for?

winter oar
#

Correct on the last part....do I just initialize the promise globally as I do now (with just my key), then re-init with customer Stripe Account info added when I'm creating a customer PaymentMethod?

stoic sky
#

One sec, checking with a colleague who is more familiar with React for what the best way to handle this situation is.

#

Okay so yeah, what you suggested is a fine way to handle it, you just have to take into account that when you re-initialize your Components will re-mount and you just need to take that into account.

#

Alternatively, you can defer initialization until you know the Connected Account