#kekko7072

1 messages · Page 1 of 1 (latest)

shadow ploverBOT
dawn topaz
#

Hello! Not sure what you mean by "cart" in this context. Can you provide more details?

shadow ploverBOT
storm kraken
#

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;
}

});

cobalt pier
#

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?

storm kraken
#

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,
});

cobalt pier
#

How was it not working? Did you get an error when you tried to re-use the saved payment method?

shadow ploverBOT
cobalt pier
#

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

storm kraken
#

this is the id

#

seti_1MmMjCA94JJJ3znbqzMBbLAh

#

cs_test_c1A9ZSBxz3JbgU7VAlhFQtfIDQPOoBMX90viaxXOuqlEtoUKu9dFWBZe4Y

cobalt pier
#

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?

storm kraken
#

i completed sucessfully cs_test_c1Ki58UnpiBCrOqajjBKxQV1T8sLwG5DvwTVWdtRlrI0VXzxWYOuDmgzhm

#

but no card is saved on customer

turbid dock
#

Hello 👋
Give me a moment to take a look

storm kraken
#

sorry my fault

#

i will retry now passing customer

#

should i also add this:

#

payment_intent_data: {setup_future_usage: "off_session"},

#

?

turbid dock
#

With setup mode, I don't think you need that

storm kraken
#

ok

storm kraken
#

Success i successfully registered the card

#

thank you!