#kekko7072
1 messages · Page 1 of 1 (latest)
Hello! Not sure what you mean by "cart" in this context. Can you provide more details?
Yes let me give more details and context
I have a webiste for renting powerbank i use flutter web and firebase functions
i have the possibility to rent for free the powerbank but i want the payment info of the user in case it's missing or never returned. So i need to collect the payment details (Card or Apple Pay/GooglePay) and be able to use them off session to charge the user.
at the moment i have created this function
import * as functions from "firebase-functions";
import { amperryGoDomain, stripe, userCollection } from "../constants";
export const WebCreateCustomer = functions
.region("europe-west3")
.https.onCall(async (req: any, context: any) => {
// Value passed
const uid = context.auth?.uid || null;
const phoneNumber = req.phoneNumber;
if (uid == null) {
throw new functions.https.HttpsError(
"unauthenticated",
`Il uid passato non è vaildo ${uid}`
);
} else {
// Create customer
const customer = await stripe.customers.create({
description: context.auth?.uid,
phone: phoneNumber,
});
await userCollection
.doc(uid)
.update({
"billing.configured": true,
"billing.customerId": customer.id,
})
.catch((error) => {
throw new functions.https.HttpsError("invalid-argument", error);
});
// Create session to register card
const session = await stripe.checkout.sessions.create({
mode: "setup",
payment_method_types: ["card"],
customer: req.customerId,
//payment_method_collection: "always",
// https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#save-payment-method-details
// payment_intent_data: {setup_future_usage: "off_session"},
currency: "eur",
success_url: `${amperryGoDomain}/success`,
cancel_url: `${amperryGoDomain}/cancel`,
metadata: {
uid: req.uid,
stationId: req.stationId,
orderId: req.orderId,
},
});
// return session.url;
return session.id;
}
});
That payment_intent_data: {setup_future_usage: "off_session"}, argument that you have should set the Checkout Session up to save the payment method like that
Was that not working for you? Or are you having trouble finding the saved payment method ID so that you can re-use it?
yes that was not working so i removed
i'd like to know if it works saving the payment
method to user
this is the session create code
const session = await stripe.checkout.sessions.create({
mode: "setup",
payment_method_types: ["card"],
customer: req.customerId,
currency: "eur",
success_url: ${amperryGoDomain}/success,
cancel_url: ${amperryGoDomain}/cancel,
});
How was it not working? Did you get an error when you tried to re-use the saved payment method?
With those settings, the payment method would not be saved. I think you do need to set setup_future_usage in the payment intent data
this is the id
seti_1MmMjCA94JJJ3znbqzMBbLAh
cs_test_c1A9ZSBxz3JbgU7VAlhFQtfIDQPOoBMX90viaxXOuqlEtoUKu9dFWBZe4Y
Oh I am sorry I did not realize that you were using Checking in setup mode. That should be able to save the payment method once you submit the page
What was the issue that you were seeing when you were trying this in payment mode?
i completed sucessfully cs_test_c1Ki58UnpiBCrOqajjBKxQV1T8sLwG5DvwTVWdtRlrI0VXzxWYOuDmgzhm
but no card is saved on customer
Hello 👋
Give me a moment to take a look
It doesn't look like a customer ID was passed in to the request body
https://dashboard.stripe.com/test/logs/req_N30nFzeNsPCpHY
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
sorry my fault
i will retry now passing customer
should i also add this:
payment_intent_data: {setup_future_usage: "off_session"},
?
With setup mode, I don't think you need that
ok