#noor-bl_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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
Hi there. We'll be with you shortly!
Hello
What error are you seeing when the app crashes?
nothing .... only exit app
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?
its already app from begin work in real device
android
You should check device logcat.. Without any errors or anything, it's near to impossible to say what's causing this.
i using expo i cant see logcat .......
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
ummm good idea wait .... i will try it and back to you
how to set // and all ??? what to press i forget it ๐คฆ
Try googling
i cant understand
We don't know what system you use ๐
i using windwos / VS code
use ctrl + /
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?
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..
umm wait i will try and back to you....
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
In that case, you'd want to look into your backend server logs to see if there are any errors there..
You could check your Stripe API logs to see if there are any requests failing: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Sorry I can't just look at code and know where the issue lies.
okay look and tell me what fix
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..
wtf ๐ i just forget this import/provider in app.tsx
<StripeProvider publishableKey="">
sorry
did that fix the crash?
yeah
Great! ๐
Happy to help! ๐ You too