#SamMon-Expo
1 messages ยท Page 1 of 1 (latest)
Can you send me the detailed error message?
or do you have any information on this undefined error? (e.g., which variable is undefined)
if (!resClientSecret) {
return;
}
const { error } = await initPaymentSheet({
paymentIntentClientSecret: resClientSecret,
});
console.log(error);
if (error) {
Alert.alert(error);
}
};```
this initPaymentSheet gives an undefined error
Did the log tell you which variable is undefined?
no
Can you just past the error message here?
const { error } = await initPaymentSheet({
paymentIntentClientSecret: resClientSecret,
});
console.log(error);
So the error is undefined, that means there's no error.
I don't see a problem here
The error object is expected to be undefined if there's no error
but payment is happening
not happening
What's the PaymentIntent ID?
Paste the paymentIntent ID here
did u mean the publishable key?
No, the PaymentIntent ID, it starts with pi_
ok
pi_3LVnrESEv7JCodBk0tzNVV6r_secret_KnzLRZkVxK9GhL6DJmG12AYOt
is this what u asked?
Yes
ok
I don't any requests from your Expo app to confirm the PaymentIntent.
When you call presentPaymentSheet(), do you see the PaymentSheet pops up?
const { error } = await presentPaymentSheet({ resClientSecret });
is this error object undefined?
let me check
yes its undefined
initializePaymentSheet is in the useeffect
is this with publishable key, I can see that publishable key is not used yet..
Is your component Basket wrapped inside StripeProvider ?
yes it is
import RootNavigator from "./src/navigation";
import { NavigationContainer } from "@react-navigation/native";
import { Amplify } from "aws-amplify";
import { withAuthenticator } from "aws-amplify-react-native";
import config from "./src/aws-exports";
import AuthContextProvider from "./src/contexts/AuthContext";
import BasketContextProvider from "./src/contexts/BasketContext";
import OrderContextProvider from "./src/contexts/OrderContext";
import { StripeProvider } from "@stripe/stripe-react-native";
Amplify.configure({
...config,
Analytics: {
disabled: true,
},
});
function App() {
return (
<NavigationContainer>
<StripeProvider publishableKey="pk_test_51LNfmKSEv7JCodBkz9Ppyp5dW973XwbCkI1LL2tXjptubAqy1YAHeN2GFGSdoR8GavnQwcmGsxTC8y4kfrbyIz9q00cQGOlsZZ">
<AuthContextProvider>
<BasketContextProvider>
<OrderContextProvider>
<RootNavigator />
</OrderContextProvider>
</BasketContextProvider>
</AuthContextProvider>
</StripeProvider>
<StatusBar style="light" />
</NavigationContainer>
);
}
export default withAuthenticator(App);
is this correct?
<RootNavigator /> is a stack navigator
Is Basket a child to <RootNavigator> ?
yes
Do you mind if I send a post request to your AWS endpoint to create a PaymentIntent?
yes
no problem
what could be the issue
const express = require("express");
const cors = require("cors");
const Stripe = require("stripe");
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();
const PORT = 3000;
app.use("/stripe", express.raw({ type: "*/*" }));
app.use(express.json());
app.use(cors());
app.post("/pay", async (req, res) => {
try {
const { amount, id } = req.body;
if (!amount) return res.status(400).json({ message: "Amount is missing" });
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: "INR",
automatic_payment_methods: {
enabled: true,
},
metadata: { id },
});
const clientSecret = paymentIntent.client_secret;
res.json({ message: "Payment initiated", clientSecret });
} catch (err) {
console.error(err);
res.status(500).json({ message: "Internal server error" });
}
});
// app.post("/stripe", async (req, res) => {
// const sig = req.headers["stripe-signature"];
// let event;
// try {
// event = await stripe.webhooks.constructEvent(
// req.body,
// sig,
// process.env.STRIPE_WEBHOOK_SECRET
// );
// } catch (err) {
// console.error(err);
// res.status(400).json({ message: err.message });
// }
// // Event when a payment is initiated
// if (event.type === "payment_intent.created") {
// console.log(`${event.data.object.metadata.name} initated payment!`);
// }
// // Event when a payment is succeeded
// if (event.type === "payment_intent.succeeded") {
// console.log(`${event.data.object.metadata.name} succeeded payment!`);
// // fulfilment
// }
// res.json({ ok: true });
// });
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
this is the server code
but expo app gives back the clientSecret
OK. I'm able to create a PaymentIntent by removing the id param
did you call onCreateOrder before initializePaymentSheet is invoked?
This only means that the PaymentIntent is created
yes
Can you add a log in initializePaymentSheet and print out a message when the initialization is compelted successfully
ok sir
Then call openPaymentSheet only if the paymentSheet is initialized.
BTW. One concern on your server code. You shouldn't pass the amount from the client, this allows bad users to change the amount via the HTTP request
I am learning Stripe , I dont have much expossure in RN too. I just started practice these things
this what initializePaymentSheet gives
thats hardcoded
Can you share with me the latest code? I want to see what you passed to the console.log
Is the error still undefined from the response of initializePaymentSheet ?
That's what your server responded, you should check your server code.
where to add merchant display name
OK, you should pass merchantDisplayName and merchantCountryCode to initPaymentSheet
paymentIntentClientSecret: paymentIntent.secret,
customFlow: false,
merchantDisplayName: 'Example merchant',
merchantCountryCode: 'IN',
})```
IN for India
Indisa?
Payment is successfull but now app is redirecting to a browser
and closing
What test card are you using?
4242 one
4242 is a US card, and all foreign card requires 3DS as per India local regulation.
Please use an Indian test card instead 4000 0035 6000 0008
ok
No problem!
after 3DS now app is crashing
Do you have the stack trace log?
I need the crash log, not the code.
ok
I am not understanding the logs
instead i recorded the video of whats happening
I have to press multiple times
๐ stepping in. Have you obtained the crash log? Would be helpful If you can share the crash log
Your screen recording doesn't look like a crash. A crash is when your app quit unexpectedly to the home screen
Did you really experienced a crash here?
after 3DS now app is crashing
yes
and finally i found out logcat
not to the home screen , Its going back to expo screen
this is the code for that page!
is the code correct?
If the payment occurs then i have to navigate to Order screen
But bcoz of the 3DS app is crashing
sometimes createOrder Button is also not working!
Where is that action in your video? I see you were opening some warning screen
0:50 here when I click btn for payment
it opens a webpage
then the app crashes
as you can see then, when I open the app it shows payment is successful without verifying
Is that part going to the screen "Expo go"?
yes
I see this on crash log
08-12 12:06:00.696 5054 5184 W ReactNativeJS: Possible Unhandled Promise Rejection (id: 8):
08-12 12:06:00.696 5054 5184 W ReactNativeJS: ReferenceError: Can't find variable: Alert
It looks like it stopped by this line and can't call Alert
if (error) {
Alert.alert(`Error code: ${error.code}`, error.message);
} else {
onCreateOrder();
}
So:
- Debug why Alert is unable to find
- After getting Alert working, check its error.code and error.message
Ok Let Me check
Alert was called from react-native
Yes, from your code, isn't it?
yes,but still after that 3d thing its closing the app
then showing payment is successfull
yep because your app crashed because your code uses "Alert" which was not found.
what's wrong with that exactly?
I dont know why its happening like this
you see payment was not completed!
then the app crashes
when i open it back it shows payment is successfull
I think it does complete.
there is 3ds or something right
you're expecting it to show some specific 3D Secure window right with like a button?
that doesn't always happen, there's a "frictionless" flow where it looks like in that video, where the bank just checks the details automatically and the customer doesn't have to do anything
so that happened, and the customer got redirected back to your app, which is probably crashing
it's quite easy to help if you share the logcat logs for the crash and the PaymentIntent ID pi_xxx.
Ill share now
well before that at least look at the logs yourself first and see if you can debug why it crashes!
Ok
I was checking from morning!
if you're stuck we can try to help but you're the developer of the app and have a much better position to debug it than we do since you're actually writing the code and running the app and have a debugger and such
๐
yes sir i understood
this the log file
pi_3LVtFRSEv7JCodBk1LIXFCJE_secret_sqXERV49qcD9Np0psKsV1UVvL
so are you really sure it's crashing?
like I said, that app doesn't look like it's crashing. After the payment it's supposed to redirect to "stripesdk://payment_return_url/host.exp.exponent" . Are you sure that is not simply what's happening?
i think that stripe consider expo as the host