#darkknight-_code

1 messages ยท Page 1 of 1 (latest)

upbeat grottoBOT
hallow flareBOT
#

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.

upbeat grottoBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1229521630112387193

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

hallow flareBOT
harsh pasture
gritty agate
#

Does any exception get thrown when you call intentCreationCallback({ error })?

harsh pasture
#

nope. crashes just like that

harsh pasture
gritty agate
#

Interesting, and nothing shows up in your dev console, and none of your error handling stuff sees anything?

harsh pasture
#

this is the handler code:

const confirmHandler = async (
  paymentMethod: PaymentMethod.Result,
  _shouldSavePaymentMethod: boolean,
  intentCreationCallback: (
    result: IntentCreationCallbackParams,
  ) => void,
) => {
  try {
    const { client_secret, error } = await createConfirmIntent(
      stripeCustomerId,
      paymentMethod.id,
    );
    if (client_secret) {
      intentCreationCallback({ clientSecret: client_secret });
    } else {
      intentCreationCallback({ error });
    }
  } catch (err) {
    console.log({ err }, 'from handler');
  }
};
#

api call code:

const createConfirmIntent = async (
  customerId: string,
  paymentMethodId: string,
): Promise<ConfirmIntentData> => {
  try {
    const { data } = await axios.post(
      `${CUSTOM_STRIPE_SERVER_URL}/create-confirm-intent`,
      { customerId, paymentMethodId },
      {
        headers: {
          'Content-Type': 'application/json',
        },
      },
    );
    return data as ConfirmIntentData;
  } catch (err) {
    return { error: err } as ConfirmIntentData;
  }
};

type ConfirmIntentData = {
  client_secret: string;
  error: string;
};
#

api endpoint handler:

app.post('/create-confirm-intent', async (req, res) => {
  try {
    const { customerId, paymentMethodId } = req.body;

    const stripe = new Stripe(STRIPE_SECRET_KEY, {
      apiVersion: '2024-04-10',
      typescript: true
    });

    const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodId);

    if (paymentMethod.type !== "card") {
      return res.status(400).json("Only credit cards can be saved");
    }
    if (paymentMethod.card?.funding !== "credit") {
      return res.status(400).json("Only credit cards can be saved");
    }
    if (paymentMethod.card.fingerprint === "vxOxUrmdfHx3dY7M") {
      return res.status(400).json("The card has already been saved");
    }

    const setupCreateParams: Stripe.SetupIntentCreateParams = {
      customer: customerId,
      payment_method: paymentMethod.id,
      confirm: true,
      mandate_data: {
        customer_acceptance: {
          type: "online",
          online: {
            ip_address: req.ip || "",
            user_agent: req.get("user-agent") || "",
          }
        }
      },
    };
    const { client_secret } = await stripe.setupIntents.create(setupCreateParams);

    return res.status(200).json({ client_secret });
  } catch (err) {
    return res.status(500).json({ error: err.message });
  }
});
lost solar
#

๐Ÿ‘‹ hey again

#

First, what version of the SDK are you using?

harsh pasture
#

client - "@stripe/stripe-react-native": "^0.37.2"

#

server - "stripe": "^15.1.0"

lost solar
#

Thanks. Can you add a log for data right before return data as ConfirmIntentData;

#

And see if that spits out in metro?

harsh pasture
#

nothing came, the app just crashed ๐Ÿ˜ข

lost solar
#

If you replace that axios request with just an abritrary log can you make sure that log is hit?

harsh pasture
#

I can't get what ur saying. currently its like this


    console.log({ data }, '@confirm intent');
    return data as ConfirmIntentData;
  } catch (err) {
    return { error: err } as ConfirmIntentData;
  }
lost solar
#

If you put a log prior to the axios request I'm saying

#

So just put a log in the line before const { data } = await axios.post(

harsh pasture
#

ok

#

nothing came

lost solar
#

Alright so it seems like the crash is before the backend request then. Does this code work for successfully saving a PaymentMethod?

#

Have you tested that yet?

harsh pasture
#

yes it works perfect on the sucess sceanrios when trying to save a credit card that has not yet been saved

lost solar
#

Interesting

harsh pasture
#

ok let me share that as well

upbeat grottoBOT
lost solar
#

Okay one minute, let me spin up a repro

harsh pasture
#

I need to go get some sleep ๐Ÿ˜ด . It's 2 am here, my bed time is 11. This issues pushed that time โฒ๏ธ

#

Will catch up in the morning