#xarvoit

1 messages · Page 1 of 1 (latest)

pearl yokeBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

tender dirge
#
async function initPayment(data, isProd) {
 try {
   const stripe = new stripeModule.Stripe(secretKey(isProd), {
     apiVersion: "2020-08-27",
   });

  //  const customers = await stripe.customers.list({
  //    email: data.email,
  //    limit: 1,
  //  });
  //  var customer = customers.data[0];
  //  if (!customer) {
  //    customer = await stripe.customers.create({
  //      email: data.email,
  //      ...(data.name && { name: data.name }),
  //    }, {
  //     stripeAccount: data.vendorAccountId,
  //    });
  //  }

  const customer = await stripe.customers.create();

  const ephemeralKey = await stripe.ephemeralKeys.create(
    {customer: customer.id},
    {apiVersion: "2023-08-16"}
  );

   // Create a token to clone the payment method
   const token = await stripe.tokens.create({
     customer: customer.id,
   }, {
     stripeAccount: data.vendorAccountId,
   });

   // Attach the token to a customer on the connected account
   const customerOnHostAccount = await stripe.customers.create({
     source: token.id,
   }, {
     stripeAccount: data.vendorAccountId,
   });
   const paymentMethod = await stripe.paymentMethods.create({
    customer: customer.id,
    payment_method: customerOnHostAccount.pay
   })

   const paymentIntent = await stripe.paymentIntents.create(
     {
       amount: data.amount,
       currency: 'usd',
       customer: customerOnHostAccount.id,
       description: data.description ?? "Empty", 
       application_fee_amount: data.amount * 0.02,
       automatic_payment_methods: {
        enabled: true,
       }
     },{
       stripeAccount: data.vendorAccountId
     }
   );

   return {
     paymentId: paymentIntent.id,
     paymentIntent: paymentIntent.client_secret,
     ephemeralKey: ephemeralKey.id,
     customer: customer.id,
     success: true,
   };
 } catch (error) {
   console.log(`Error: ${error}`);
   return { success: false, error: userFacingMessage(error) };
 }
}
summer flax
#

you're not setting stripeAccount ID here

    customer: customer.id,
    payment_method: customerOnHostAccount.pay
   })```
#

is there a specific guide you're following for this?

tender dirge
#

It’s been pretty all over the place

pearl yokeBOT
tender dirge
#

so after creating the payment method object do I need to do anything else?

summer flax
#

I mean we don't know what flow you're building so can't tell if you need to do anything else or not.

Can you provide context on what you're trying to build?

tender dirge
#

Donation platform for multiple non-profits

#

So similar to Indiegogo

ionic pagoda
#

Hi there

tender dirge
#

Hi

ionic pagoda
#

do I need to do anything else?
Do anything else to achieve what?

#

I don't understand

tender dirge
#

So I've been trying to process donations for my host accounts on my platform. I want to send the money while taking a fee. I believe direct charges is the correct way to do that in Stripe Connect.

#

for some time now I've been stuck at the Error: The customer must have an active payment source attached with no progress

ionic pagoda
#

Yeah so how are you collecting payment method details from them?

tender dirge
#

IDK

ionic pagoda
#

How can you create a payment method if you don't collect details from them?

tender dirge
#

Hold on I'm seriously not understanding the flow. Does the process start with a server request? The data that I'm sending to the server is: users, is email, name, currency, description, amount and the connectedAccountId. Which if succesful can be used to generate the client side payment window

ionic pagoda
#

Your code above is really strange

#

It's not what we recommend in our docs really

#

First of all, do you want a stripe-hosted payment page or do you plan on using the payment element on your page?

tender dirge
#

stripe-hosted payment page

ionic pagoda
#

So yeah you'd never create a payment intent or payment method explicitly if you want that flow

#

That can be used with direct charges too

tender dirge
#

Are those requirements the same for Mobile as well?

I try to keep my questions lean but I'll just say that I'm using a low code Flutter tool and that most of the code comes from their stock implementation of payments. Which only handles naive Stripe use cases and nothing with Stripe Connect. So I'm building my own

ionic pagoda
#

So how do you want to implement a stripe-hosted flow?

#

Is this going to be in a webview?

tender dirge
ionic pagoda
#

Yeah that's a 3rd party library so I can't comment on it

#

Nor can I support its use

#

We just help with our official libraries

tender dirge
ionic pagoda
#

Ok but why do you say you want a stripe-hosted page then?

#

That's a flow that uses mobile components in app

#

But if you do want to do it that way, you should just be able to copy that code

#

What you're doing in the above snippet at the top of this thread is completely different

tender dirge
#

Yeah I think I've realized that now

#

It might just be as simple at this:

  const stripe = require('stripe')(secretKey, {
    stripeAccount: data['vendorAccountId'],
  });

   const paymentIntent = await stripe.paymentIntents.create(
     {
       amount: data.amount,
       currency: 'usd',
      //  customer: customerOnHostAccount.id,
       description: data.description ?? "Empty", 
       application_fee_amount: data.amount * 0.02,
       payment_method_types: ['card'],
     },{
       stripeAccount: data.vendorAccountId
     }
   );

   return {
     paymentId: paymentIntent.id,
     paymentIntent: paymentIntent.client_secret,
     customer: customer.id,
   };
ionic pagoda
#

You said you needed customer and ephemeral key