#Gerald - Redfluencer

1 messages · Page 1 of 1 (latest)

fallow flameBOT
orchid badger
#

Hi there,
Could you please give more details about your use case and what are you trying to account?
Are you using PaymentIntent or SetupIntent ?

merry geyser
#

Hi, im using setup intent. I want to save the user card details for later use

#

This is my backend codes

  const stripe = require("stripe")(
    "sk_test_51LjLfwLLeb1xbCSQHQq33bheOppk3aULL3oER9ZEpAQKkgz4gzlCDNwR2OCGjqS6vamJpBlLJ1VTawQB1imhCfUC0024JVrV5F"
  );

  const customer = await stripe.customers.create();
  const ephemeralKey = await stripe.ephemeralKeys.create(
    { customer: customer.id },
    { apiVersion: "2022-08-01" }
  );
  const setupIntent = await stripe.setupIntents.create({
    customer: customer.id,
  });
  res.json({
    setupIntent: setupIntent.client_secret,
    ephemeralKey: ephemeralKey.secret,
    customer: customer.id,
  });
});```
#

this is my frontencodes

  const [loading, setLoading] = useState(false);

  const fetchPaymentSheetParams = async () => {
    const response = await fetch(`${API_URL}/setup`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
    });
    const { setupIntent, ephemeralKey, customer } = await response.json();

    return {
      setupIntent,
      ephemeralKey,
      customer,
    };
  };

  const initializePaymentSheet = async () => {
    const { setupIntent, ephemeralKey, customer } =
      await fetchPaymentSheetParams();
    console.log(setupIntent, ephemeralKey, customer);
    const { error } = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      setupIntentClientSecret: setupIntent,
    });
    if (!error) {
      setLoading(true);
    }
  };

  const openPaymentSheet = async () => {
    const { error } = await presentPaymentSheet();

    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert(
        "Success",
        "Your payment method is successfully set up for future payments!"
      );
    }
  };

  useEffect(() => {
    initializePaymentSheet();
  }, []);

  return (
    <StripeProvider publishableKey="pk_test_51LjLfwLLeb1xbCSQyrBCUMuDh8mE6OKvmt1gVza8Iu7fqd1iLDVCwLdwi4LVn4R547iC6o80yyg45LSxTiOhEhhZ00EXBjPgaz">
      <SafeAreaView style={styles.container}>
        <Button
          variant="primary"
          // disabled={!loading}
          title="Set up"
          onPress={openPaymentSheet}
        />
      </SafeAreaView>
    </StripeProvider>
  );
};```
#

i followed exactly what was documented. It returned setupIntent, ephemeralKey, customer but theres no intent

orchid badger
merry geyser
#

hi @orchid badger any idea?

orchid badger
#

Yes, when creating the SetupIntent you are passing a customerId, when confirming the SetupIntent the resulting PaymentMethod, will be attached to that customer

#

You need to fetch the customer's PaymentMethods, in your backend:

const paymentMethods = await stripe.paymentMethods.list({
  customer: '{{CUSTOMER_ID}}',
  type: 'card',
});

And use it for future payments

merry geyser
#

@orchid badger I think you got it wrong. The thing is that there is no intent popping up for me to save my card details

#

its not retrieving my card details. there is no pop up modal for me to input my card details

orchid badger
#

Ah sorry, I mis understood so, you mean the mobile app is not showing the PaymentSheet popup ?

merry geyser
#

yes

#

its not showing

orchid badger
#

At runtime, your app is reaching this method openPaymentSheet or not ? if yes did you added some logs to debug the functions call ?
like what is the response of this const { error } = await presentPaymentSheet(); ?

merry geyser
#

no error

#

it returned setupIntent, ephemeralKey, customer

orchid badger
#

the fetchPaymentSheetParams function is the one returning the setupIntent, ephemeralKey, customer. But I'm talking about openPaymentSheet and presentPaymentSheet functions in your code

merry geyser
#

yes it does

#

working absolutely fine

#

but the intent is not coming up

orchid badger
#

If openPaymentSheet is working fine, then you should have a response for const { error } = await presentPaymentSheet();
what is the value of the error here ?

#

Are you having the popup?

Alert.alert(
        "Success",
        "Your payment method is successfully set up for future payments!"
      );
merry geyser
#

nope after pressing the button

#

nothing comes up

orchid badger
#

Did you add some logs in the openPaymentSheet function ?

merry geyser
#

yes

#

everything is fine but nothing comes up

#

no error no nothing

orchid badger
#

in openPaymentSheet if there is no exception in your react native console app, then one of these two alerts must popup:

if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert(
        "Success",
        "Your payment method is successfully set up for future payments!"
      );
    }
merry geyser
#

before this

#

this is no intent at all

#

    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert(
        "Success",
        "Your payment method is successfully set up for future payments!"
      );
    }```
#

in btween await presentPaymentSheet() and if(error)

#

nothing happends

orchid badger
#

Yeah there is no intent, you justshow the PaymentSheet const { error } = await presentPaymentSheet();

merry geyser
#

thats the problem im facing

#

yes

orchid badger
#

That mean either the presentPaymentSheet is not called, or there is an expection thrown

merry geyser
#

there should be a pop up right?

orchid badger
orchid badger
merry geyser
#

hi @orchid badger I have checked the codes

#

they are the same

#

I still do not understand why there's no popup

#

could we do a video call?

orchid badger
#

Sorry we can't do a video call, I invite you to run the sample example and see how the popup is shown

tall imp
#

👋 taking over for my colleague. Let me know if there's any follow-up Qs I can answer!