#Yousuf

1 messages · Page 1 of 1 (latest)

dapper falconBOT
nova fulcrum
#

@solar obsidian let's chat here. I'm adding your other message from the main channel:


For the server, I am using firebase cloud functions,  I did the following:

1- npm install stripe
2- this my index.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const stripe = require('stripe')('sktest...);

admin.initializeApp();

  exports.createStripeCharge = functions.https.onCall(async (data, context) => {
    const amount = data.amount; // Amount in cents
    // const paymentMethodId = data.paymentMethodId;
    console.log(data.amount)
    console.log("fuckoff 10")
    try {
      const paymentIntent = await stripe.paymentIntents.create({
        amount:1000,
        currency: 'usd',
        automatic_payment_methods: {
          enabled: true,
        },
        // payment_method: paymentMethodId,
        // confirm: true,
      });
      console.log("ssssssss")
      return { clientSecret: paymentIntent.client_secret };
    } catch (error) {
      throw new functions.https.HttpsError('internal', 'Payment failed 4', error.message);
    }
  }); ```
solar obsidian
#

Thanks, I would really appreciate any help

rotund gazelle
#

👋

#

Where do you see the error exactly?

solar obsidian
#

hello, i see the error on both the android and ios emulators whenever the onpay function is triggered.

rotund gazelle
#

Okay and have you added logs client-side to know exactly where the error occurs?

solar obsidian
#

I guess so, it is popping up through this alert:

  Alert.alert('Payment failed 3', error.message);

is there anything else I should do?

rotund gazelle
#

Do you see your "hello" log?

#

My guess is functions.httpsCallable('createStripeCharge') is coming back undefined

#

Firebase is a separate module than just using the Stripe React Native module

#

Did you install what was necessary for Firebase?

solar obsidian
#

Yeah, It everything else is working: firebase authentication, firestore, ...etc

#

I also have another cloud function thats working for push notifications

rotund gazelle
#

Hmm okay instead of alerting the error.message can you alert (or log) the whole error object?

solar obsidian
#

sure

#

i am not getting the log

rotund gazelle
#

Are you using an alert?

#

What does that catch block look like now?

solar obsidian
#

} catch (error) {
console.log(error)
Alert.alert('Payment failed 3', error.message);
}

#

LOG [TypeError: undefined is not a function]

#

thats all am getting

dapper falconBOT
rotund gazelle
#

Ah do you mean to have // const functions = useFunctions(); commented out?

solar obsidian
#

i wasnt sure if i needed it. i tried uncommenting it. I dont think it worked. ill try again though

rotund gazelle
#

That is what defines functions which you use for functions.https.onCall()

#

So yeah if you don't have that then functions will be undefined like the error notes

solar obsidian
#

// import functions from '@react-native-firebase/functions';
//import { useFunctions } from '@react-native-firebase/functions';
I was using the first import statement

rotund gazelle
#

Ah well that is commented out too in what you just provided?

#

You can try logging out functions on your component render as well

#

Which would be telling here

solar obsidian
#

i tried this: const { data } = await firebase.functions.httpsCallable('createStripeCharge')({
I am getting this error: " LOG Cannot read property 'httpsCallable' of undefined"

rotund gazelle
#

Cool so same issue overall. functions is udnefined

solar obsidian
#

yup

#

i added the missing parenthesis after functions. I got back the same error < LOG undefined is not a function>

rotund gazelle
#

Yeah I'm not sure, sorry. This isn't really a Stripe issue... this is strictly a Firebase issue and I'm not really familiar with Firebase.

#

Not sure how much more I can help

solar obsidian
#

hmm ill try and debug it a bit more and if its a stripe issue Ill come back

#

thanks for trying