#SamMon-Expo

1 messages ยท Page 1 of 1 (latest)

dense grail
#

Hi there, let me help you

supple dove
#

๐Ÿฅฐ

dense grail
#

Can you send me the detailed error message?

supple dove
#

I cant see any error

#

when i debug into code

dense grail
#

or do you have any information on this undefined error? (e.g., which variable is undefined)

supple dove
#
    if (!resClientSecret) {
      return;
    }
    const { error } = await initPaymentSheet({
      paymentIntentClientSecret: resClientSecret,
    });
    console.log(error);
    if (error) {
      Alert.alert(error);
    }
  };```
#

this initPaymentSheet gives an undefined error

dense grail
#

Did the log tell you which variable is undefined?

supple dove
#

no

dense grail
#

Can you just past the error message here?

supple dove
#

Can u c undefined thats the thing

dense grail
#
const { error } = await initPaymentSheet({
      paymentIntentClientSecret: resClientSecret,
    });
    console.log(error);
#

So the error is undefined, that means there's no error.

supple dove
#

yes

#

then whats the problem

dense grail
#

I don't see a problem here

#

The error object is expected to be undefined if there's no error

supple dove
#

but payment is happening

dense grail
#

? not sure what you mean

#

You mean payment is happening or not happening?

supple dove
#

not happening

dense grail
#

What's the PaymentIntent ID?

supple dove
dense grail
#

Paste the paymentIntent ID here

supple dove
#

did u mean the publishable key?

dense grail
#

No, the PaymentIntent ID, it starts with pi_

supple dove
#

ok

#

pi_3LVnrESEv7JCodBk0tzNVV6r_secret_KnzLRZkVxK9GhL6DJmG12AYOt

#

is this what u asked?

dense grail
#

Yes

supple dove
#

ok

dense grail
#

I don't any requests from your Expo app to confirm the PaymentIntent.

#

When you call presentPaymentSheet(), do you see the PaymentSheet pops up?

supple dove
#

no

#

nothing is comming

dense grail
#
    const { error } = await presentPaymentSheet({ resClientSecret });

is this error object undefined?

supple dove
#

let me check

supple dove
#

initializePaymentSheet is in the useeffect

#

is this with publishable key, I can see that publishable key is not used yet..

dense grail
#

Is your component Basket wrapped inside StripeProvider ?

supple dove
#

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

dense grail
#

Is Basket a child to <RootNavigator> ?

supple dove
#

yes

dense grail
#

Do you mind if I send a post request to your AWS endpoint to create a PaymentIntent?

supple dove
dense grail
#

{"ok": false, "error": "proxy do"}

#

I'm getting this response

supple dove
#

what could be the issue

dense grail
#

I don't know.

#

I can't even reproduce the issue.

supple dove
#
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

dense grail
#

OK. I'm able to create a PaymentIntent by removing the id param

#

did you call onCreateOrder before initializePaymentSheet is invoked?

supple dove
dense grail
#

This only means that the PaymentIntent is created

supple dove
#

yes

dense grail
#

Can you add a log in initializePaymentSheet and print out a message when the initialization is compelted successfully

supple dove
#

ok sir

dense grail
#

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

supple dove
supple dove
supple dove
dense grail
#

What is this error about?

#

The error right after the Payment initiated

supple dove
#

thats hardcoded

dense grail
#

Can you share with me the latest code? I want to see what you passed to the console.log

supple dove
dense grail
#

Is the error still undefined from the response of initializePaymentSheet ?

supple dove
#

yes

#

also now app is crashing

#

i am getting like this too

dense grail
#

That's what your server responded, you should check your server code.

supple dove
#

now i am getting like this

#

when i press pay button

supple dove
dense grail
#

OK, you should pass merchantDisplayName and merchantCountryCode to initPaymentSheet

supple dove
#

example

#

?

dense grail
#
      paymentIntentClientSecret: paymentIntent.secret,
      customFlow: false,
      merchantDisplayName: 'Example merchant',
      merchantCountryCode: 'IN',
    })```
supple dove
#

ok

#

I is for india?

dense grail
#

IN for India

supple dove
#

Indisa?

#

Payment is successfull but now app is redirecting to a browser

#

and closing

dense grail
#

What test card are you using?

supple dove
#

4242 one

dense grail
#

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

supple dove
#

ok

supple dove
#

Hi

#

Thank You

#

Some issues are there

#

but now payment is happening

dense grail
#

No problem!

supple dove
#

after 3DS now app is crashing

dense grail
#

Do you have the stack trace log?

supple dove
#

I modified code like this

#

if you have any suggestion please let me know

dense grail
#

I need the crash log, not the code.

supple dove
#

ok

supple dove
#

I am not understanding the logs

#

instead i recorded the video of whats happening

#

I have to press multiple times

errant arrow
#

๐Ÿ‘‹ stepping in. Have you obtained the crash log? Would be helpful If you can share the crash log

supple dove
#

I am not able to find the crash log

#

where can I find that

errant arrow
#

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

supple dove
supple dove
#

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!

errant arrow
supple dove
#

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

errant arrow
#

Is that part going to the screen "Expo go"?

supple dove
#

yes

errant arrow
#

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:

  1. Debug why Alert is unable to find
  2. After getting Alert working, check its error.code and error.message
supple dove
#

Ok Let Me check

supple dove
errant arrow
#

Yes, from your code, isn't it?

supple dove
#

yes,but still after that 3d thing its closing the app

#

then showing payment is successfull

spare mist
#

yep because your app crashed because your code uses "Alert" which was not found.

supple dove
#

no still it crashes

#

let me show you

spare mist
#

what's wrong with that exactly?

supple dove
#

I dont know why its happening like this

supple dove
#

then the app crashes

#

when i open it back it shows payment is successfull

spare mist
#

I think it does complete.

supple dove
spare mist
#

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.

spare mist
#

well before that at least look at the logs yourself first and see if you can debug why it crashes!

supple dove
#

I was checking from morning!

spare mist
#

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

supple dove
#

๐Ÿ˜“

supple dove
#

pi_3LVtFRSEv7JCodBk1LIXFCJE_secret_sqXERV49qcD9Np0psKsV1UVvL

spare mist
#

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?

supple dove
#

Hm

#

thank you

#

you were so helpfull

supple dove