#tarunmv30

1 messages ยท Page 1 of 1 (latest)

dusk marshBOT
lapis osprey
#

Does that get you oriented in the right direction?

dark elbow
#

I dont think so @lapis osprey

#

My use case is for users who already purchased food from my restaurant

#

if they already have bought something I want to set it up to where they can save their details so next time they coe they dont have to imput their card details

wet ledge
#

๐Ÿ‘‹ stepping in for my teammate! If a PaymentMethod was created and used to create a charge before being attached to a customer object, it's not possible to re-use that PaymentMethod for future charges

dark elbow
#

let me follow the documentation and see what I did wrong

#

i will be back in a few!\

dark elbow
#

does this code work with a swiftui application, its in UIKIt / obj c?

wet ledge
#

I believe so, yes. You can click on the 'iOS' tab below the header, which will also update the client-side examples for Swift

dusk marshBOT
dark elbow
#

Based off the article i can successfully make payments and store the customer as a customer object

#

but you can see theres no payment method attached so in the app its not able to remeber the payment method

pallid canopy
#

๐Ÿ‘‹ taking over here. Are you sure you were following the Doc above? ie. setupFutureUsage when created the first PaymentIntent

dark elbow
#
  const items = req.body;
  const { total, fee } = calculateOrderAmount(items);
  // Create a PaymentIntent with the order amount and currency
  const paymentIntent = await stripe.paymentIntents.create({
    amount: total,
    currency: 'usd',
    application_fee_amount: fee,
    setup_future_usage: 'off_session',
    automatic_payment_methods: {
      enabled: true,
    },
  }, {
    stripeAccount: 'acct_1MsyJPCWAlRghLO7',
  });

  // Generate an ephemeral key for the customer
  const customer = await stripe.customers.create({
    email: 'nessmajors@gmail.com'
  }, {
    stripeAccount: 'acct_1MsyJPCWAlRghLO7',
  });
  const ephemeralKey = await stripe.ephemeralKeys.create(
    { customer: customer.id },
    { apiVersion: '2020-08-27', stripeAccount: 'acct_1MsyJPCWAlRghLO7' }
  );
  // Return the necessary information to the client
  res.send({
    customer: customer.id,
    ephemeralKey: ephemeralKey.secret,
    paymentIntent: paymentIntent.client_secret,
    publishableKey: 'pk_test_51MSCbfJMYkCh6QmLjYSQLK5gPtmLvaUMn0KrXsbFVnqVROCRere3kLrAQnKOT2Uepb5fRqv34vjgNAArl8wzPwWd00OoOZlDFj' // replace with your own publishable key
  });
});```
#

How does this code look

pallid canopy
#

That looks good to me. Do you have the example payment intent Id for your Dashboard customer above?

pallid canopy
dark elbow
#

what would I do with it?

#

Would i have to write some logic to first check if the user is a stripe customer and then fetch the customer.id?

#

becuase thats my how my code is currently written^

pallid canopy
#

Yes, you would need some logic to fetch the saved customer id first. Your code above is simply creating new Customer and it's for the first time

dark elbow
#

Okay let me try

#

be back in a few

#
  const items = req.body;
  const { total, fee } = calculateOrderAmount(items);

  // Check if customer already exists
  const existingCustomer = await stripe.customers.list({ email: req.body.email });
  let customer;
  if (existingCustomer.data.length > 0) {
    // If customer exists, retrieve their ID
    customer = existingCustomer.data[0].id;
  } else {
    // If customer does not exist, create a new customer
    customer = (await stripe.customers.create({ email: req.body.email })).id;
  }

  // Generate an ephemeral key for the customer
  const ephemeralKey = await stripe.ephemeralKeys.create(
    { customer: customer },
    { apiVersion: '2020-08-27', stripeAccount: 'acct_1MsyJPCWAlRghLO7' }
  );

  // Create a PaymentIntent with the order amount and currency
  const paymentIntent = await stripe.paymentIntents.create({
    amount: total,
    currency: 'usd',
    application_fee_amount: fee,
    setup_future_usage: 'off_session',
    customer: customer,
    payment_method_types: ['card'],
  }, {
    stripeAccount: 'acct_1MsyJPCWAlRghLO7',
  });

  // Return the necessary information to the client
  res.send({
    customer: customer,
    ephemeralKey: ephemeralKey.secret,
    paymentIntent: paymentIntent.client_secret,
    publishableKey: 'pk_test_51MSCbfJMYkCh6QmLjYSQLK5gPtmLvaUMn0KrXsbFVnqVROCRere3kLrAQnKOT2Uepb5fRqv34vjgNAArl8wzPwWd00OoOZlDFj' // replace with your own publishable key
  });
});
#

how does this code look?

pallid canopy
#

Yeah looks better but please test them

dark elbow
#

Let me test will be back