#noor-bl_code

1 messages ยท Page 1 of 1 (latest)

midnight sluiceBOT
#

๐Ÿ‘‹ 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/1286771231680630814

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

golden glen
#

const handlePayment = async () => {
try {
if (!usdAmount || !crypto || !walletAddress || !paymentMethod) {
Alert.alert('Error', 'Please fill in all fields.');
return;
}

        let customerId = await AsyncStorage.getItem('customerId');
        const paymentIntent = await fetchPaymentSheetParams(customerId, total);
        customerId = paymentIntent.customer; // Update customerId with the one returned from the server
        await AsyncStorage.setItem('customerId', customerId);

        const { error } = await stripe.initPaymentSheet({
            customerId: paymentIntent.customer,
            customerEphemeralKeySecret: paymentIntent.ephemeralKey,
            paymentIntentClientSecret: paymentIntent.paymentIntent,
            merchantDisplayName: 'Your Shop',
            googlePay: {
                merchantCountryCode: 'US',
                testEnv: true,
            },
        });

        if (error) {
            Alert.alert('Payment Error', error.message);
            return; // Exit if thereโ€™s an error
        }

        const { paymentIntent: confirmedPaymentIntent } = await stripe.presentPaymentSheet();
        if (confirmedPaymentIntent) {
            await submitOrder(total);
            Alert.alert('Success', 'Your order has been placed.');
        }
    } catch (error) {
        console.error('Error in handlePayment:', error);
        Alert.alert('Error', 'Failed to process payment: ' + error.message);
    }
};
#

<Button
title="Pay with Stripe"
onPress={handlePayment}
disabled={loading}
color={loading ? 'gray' : 'green'}
/>

#

after click on button i get crash and he close app

bitter reef
#

Hi there. We'll be with you shortly!

golden glen
#

ok

#

are you back?

clear mist
#

Hello
What error are you seeing when the app crashes?

golden glen
#

nothing .... only exit app

clear mist
#

Are you testing on a real device?
I mean there should be an error in your console with the stack trace

#

are you testing on android or iOS?

golden glen
golden glen
clear mist
#

You should check device logcat.. Without any errors or anything, it's near to impossible to say what's causing this.

golden glen
#

i using expo i cant see logcat .......

clear mist
#

The other option is that you start commenting out all the code in handlePayment and uncomment it one line at a time..

that should help you narrow down on what line is causing the crash

golden glen
#

ummm good idea wait .... i will try it and back to you

#

how to set // and all ??? what to press i forget it ๐Ÿคฆ

clear mist
#

Try googling

golden glen
#

i cant understand

clear mist
golden glen
#

ooo you mean google ....

#

ok

clear mist
#

We don't know what system you use ๐Ÿ˜…

golden glen
#

i using windwos / VS code

clear mist
#

use ctrl + /

golden glen
#

ok

#

i found the problem

#

paymentIntentClientSecret: paymentIntent.paymentIntent,

this code have error

#

i dont know what

#

` const handlePayment = async () => {
try {
if (!usdAmount || !crypto || !walletAddress || !paymentMethod) {
Alert.alert('Error', 'Please fill in all fields.');
return;
}

        const paymentIntent = await fetchPaymentSheetParams(total);

        const { error } = await stripe.initPaymentSheet({
            customerEphemeralKeySecret: paymentIntent.ephemeralKey,
            paymentIntentClientSecret: paymentIntent.paymentIntent,
            merchantDisplayName: 'Bits',
            
        });

        if (error) {
            Alert.alert('Payment Error', error.message);
            return; // Exit if thereโ€™s an error
        }

        const { paymentIntent: confirmedPaymentIntent } = await stripe.presentPaymentSheet();
        if (confirmedPaymentIntent) {
            await submitOrder(total);
            Alert.alert('Success', 'Your order has been placed.');
        }
    } catch (error) {
        console.error('Error in handlePayment:', error);
        Alert.alert('Error', 'Failed to process payment: ' + error.message);
    }
};`
#

`const express = require('express');
const cors = require('cors');
const stripe = require('stripe')('mykey');

const app = express();
app.use(cors()); // Enable CORS for all routes
app.use(express.json());

app.post('/paymentsheet', async (req, res) => {
const { amount } = req.body;

if (!amount || amount <= 0.5) {
    return res.status(400).json({ message: "The amount is insufficient: " + amount });
} else if (amount > 10000) {
    return res.status(400).json({ message: "Amount must be at most $10,000.00 USD" });
}

const customer = await stripe.customers.create();
const ephemeralKey = await stripe.ephemeralKeys.create({ customer: customer.id }, { apiVersion: '2024-04-10' });

const paymentIntent = await stripe.paymentIntents.create({
    amount: amount * 100,
    currency: 'usd',
    customer: customer.id,
    automatic_payment_methods: { enabled: true },
});

res.status(200).json({
    paymentIntent: paymentIntent.client_secret,
    ephemeralKey: ephemeralKey.secret,
    customer: customer.id,
    publishableKey: 'mykey'
});

});

const port = process.env.PORT || 3000; // Use environment variable for port or default to 3000
app.listen(port, () => {
console.log(Server listening on port ${port});
});`

code of server

#

what you think?

clear mist
#

You'd need to check if your fetchPaymentSheetParams function is running and returning the right value.. The problem seems quite clear that your client-side code isn't getting the expected value from your server.

Unfortunately, I can't help any further since there are no logs or anything which can suggest that there's something wrong with Stripe APIs/SDKs.. You'd need to figure out how you can debug this.. You should talk to your team if you're unfamiliar with the app structure..

golden glen
#

umm wait i will try and back to you....

golden glen
#

after trying ........

scoure:

if you set any example link of backend for server api ...... and more

its not crash but if i add my link backend to code and click place order ......... its crash

#

i think problems from the back end

#

you can check backend code

clear mist
golden glen
#

okay look and tell me what fix

clear mist
#

I'm not sure what you mean by that. It is clearly an issue within your backend. You haven't shared any logs/errors. It is impossible for me to know what the issue is..

golden glen
#

wtf ๐Ÿ˜‚ i just forget this import/provider in app.tsx

<StripeProvider publishableKey="">

#

sorry

clear mist
#

did that fix the crash?

golden glen
#

yeah

clear mist
#

Great! ๐Ÿ‘

golden glen
#

thnak you for help me ๐Ÿ™‚

#

have a good day

clear mist
#

Happy to help! ๐Ÿ™‚ You too