#tarunmv30
1 messages ยท Page 1 of 1 (latest)
You could setup future payments so that the payment method can be reused without re-adding the payment method details: https://stripe.com/docs/payments/save-and-reuse?platform=ios&ui=payment-sheet
Does that get you oriented in the right direction?
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
๐ 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
The next time this customer returns to your restaurant and completes a purchase, you'll want to attach their payment details to a customer object first: https://stripe.com/docs/payments/save-during-payment
does this code work with a swiftui application, its in UIKIt / obj c?
I believe so, yes. You can click on the 'iOS' tab below the header, which will also update the client-side examples for Swift
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
๐ taking over here. Are you sure you were following the Doc above? ie. setupFutureUsage when created the first PaymentIntent
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
That looks good to me. Do you have the example payment intent Id for your Dashboard customer above?
This one
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^
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
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?
Yeah looks better but please test them
Let me test will be back