#pozzworth_error

1 messages ¡ Page 1 of 1 (latest)

torn nightBOT
#

👋 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/1235944239918219286

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

pulsar sand
#

this is code in my backend responsible for getting the setupintent, ephemeral key and customer

const presentPaymentSheet = async (req, res) => {
try {
const { customerId } = req.body;
// Use an existing Customer ID if this is a returning customer.
const customer = customerId;

const ephemeralKey = await stripe.ephemeralKeys.create(
  {customer: customer},
  {apiVersion: '2024-04-10'}
);
const setupIntent = await stripe.setupIntents.create({
  customer: customer,
  payment_method_types: ['card']
});
res.json({
  setupIntent: setupIntent.client_secret,
  ephemeralKey: ephemeralKey.secret,
  customer: customer,
})

} catch (error) {
console.error('Error presenting payment sheet:', error);
res.status(500).json({ error: 'Internal server error' });
}
}

#

and on my front end i have this code

const { initPaymentSheet } = usePaymentSheet();
const { confirmSetupIntent } = useConfirmSetupIntent();

const { email, userId, customerId } = route.params;

const [setupIntentId, setSetupIntentId] = useState('');
const [ephemeralKey, setEphemeralKey] = useState('');

const initializePaymentSheet = async () => {
    try {
    const {setupIntent, customer, ephemeralKey} = 
        await fetchPaymentSheetParams();
        if (!setupIntent || !customer || !ephemeralKey) {
            console.error('Invalid payment sheet params');
            return;
        }
            const { error } = await initPaymentSheet({
                customerId: customer,
                setupIntentClientSecret: setupIntent,
                customerEphemeralKeySecret: ephemeralKey,
                allowsDelayedPaymentMethods: true,
                merchantDisplayName: 'Yogamatt, Inc.'
            });
            if (error) {
                console.error('Error initializing Payment Sheet:', error);
                return;
            }
            setLoading(true);
            setSetupIntentId(setupIntent);
            setEphemeralKey(ephemeralKey);
            console.log('Setup Intent:', setupIntent)
            console.log('Ephemeral Key:', ephemeralKey)
             
    } catch (error) {
        console.error('Error initializing Payment Sheet:', error);
      }
  };
#

// Fetch the SetupIntent and Customer ID when the component mounts
const fetchPaymentSheetParams = async () => {

    // Replace these with actual API calls to fetch the SetupIntent and Customer ID
    const response = await fetch(`${config.apiUrl}/payment/payment-sheet`, requestOptionsforCustomerIntent);    
    const { setupIntent, customer, ephemeralKey } = await response.json();

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

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

const handleAttachPaymentMethod = async () => {

// Gather the customer's billing information (for example, email)
const billingDetails = {
  email: email,
};
// Create a setup intent on the backend
const { error } = await confirmSetupIntent(setupIntentId, {
  paymentMethodType: 'Card',
  paymentMethodData: {
    billingDetails,
}});

if (error) {
  alert('There was an error attaching payment method to your account.  Please try again later.')
  console.error('there was an error', error)
} else {
    alert('Success', 'Your payment method is successfully set up for future payments!'); 
    // await getPaymentMethodId(customerId);
    navigation.navigate('ProfileSettings');
}

return;

};

lucid socket
#

Do you have multiple stripe accounts by chance?

pulsar sand
#

i had to change from one to another due to a misunderstanding with the original one and i can't use it anymore

#

i created a customer in this current account and have the setupIntent created, but it doesn't add the payment method because it says "no such setupintent"

lucid socket
#

Yeah usually you get this error when you mix api keys

#

Like if you use the public key of one account client side and the secret key of another server side

#

I'd double check you're using all the information for 1 account

pulsar sand
#

is there a way to specify in the front end that it would be used for a specific public key?

#

i'm importing these:

import { useStripe, usePaymentSheet, useConfirmSetupIntent, CardField } from '@stripe/stripe-react-native';

and variables like this

const { initPaymentSheet } = usePaymentSheet();
const { confirmSetupIntent } = useConfirmSetupIntent();

#

ok hang on i might have found it

#

so i did change it in my app.js where the public key was kept and it gives me thiss error now

ERROR there was an error {"code": "Failed", "declineCode": "generic_decline", "localizedMessage": "Your card was declined.", "message": "Your card was declined.", "stripeErrorCode": "card_declined", "type": "card_error"}

lucid socket
#

Can you share that setupintent id?

pulsar sand
#

seti_1PCMPdLLl7pmgkVlumv2DdOe

lucid socket
#

Are you testing rn?

#

If so you shouldn't be testing in live mode

pulsar sand
#

for now i'm testing

lucid socket
#

Yeah you should be using test mode here

#

With test cards

#

In live mode when you get a decline, you need to just contact the bank to see why they declined the transaction

#

But since you're testing you should not be in live mode with real cards

#

That's a TOS violation

pulsar sand
#

ok

#

i appreciate your help

#

i eventually got it to work