#DeadlyData-android

1 messages ยท Page 1 of 1 (latest)

obtuse knot
#

Hi there, can you tell me more about what issue you are running into or what you are confused about?

sacred dew
#

"node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'cors'
Require stack:
"

obtuse knot
#

Sorry, server is busy

#

Looks like you haven't installed the cors package?

sacred dew
#

I am getting a new error that reads " throw new TypeError('root path required')
"

#

after installing the necessary pacakges.

obtuse knot
#

Hmm that is pretty vague

#

What line is that error pointing towards?

#

What is the code that is throwing it?

sacred dew
#

throw new TypeError('root path required')
^

TypeError: root path required
at Function.serveStatic [as static]

#

static/index.js:40:11)

obtuse knot
#

What is the code at static/index.js40:11?

sacred dew
#

I'm not sure it does not really show much details to go with. It's a bit nuts. but that's all the details i got. I simply just copied and pasted the code on the developer website

#

stripe docs*

obtuse knot
#

Can you share your package.json?

sacred dew
obtuse knot
#

And just to clarify, you ran npm install, right?

sacred dew
#

yes

obtuse knot
#

It looks like your Stripe version is below the one in the sample (9.2.0)

#

Can you upgrade to 9.2

sacred dew
#

I've done that, still does not run. maybe i am missing something or not doing something right. In my approach, so i will walk you through the steps precisely that i took so far.

lone flame
#

Hello ๐Ÿ‘‹
Taking over for @obtuse knot here as they need to step away

#

what's the exact code on line no 40 in your index.js file?
It may be different from the repo

sacred dew
#

I downloaded and configured node js, and ran a sample code to make sure everything is configure correctly this was successful. I then ran npm install --save stripe inside my terminal, after this i simply copied the java code provided from the docs inside Android Studio, then copied and pasted the xml code. I think where i am messing up is the server part.. Not sure, if this was the correct approach but i created a folder, and added the package.json file inside of it, along with the server.js code. Then i attempted to run the server code using terminal. And this is where i am getting the error.

#

I do not hae an index.js file, i have a server.js file

#

have*

#

the code on line 40 is

#

publishableKey: process.env.STRIPE_PUBLISHABLE_KEY,

lone flame
#

ah okay wait... why does the error say static/index.js then ๐Ÿค”

sacred dew
#

oh, so the path that it's trying to locate for the json file is not correct

#

because mine is titled server.js, i will try changing the name of my file to index.js and see

#

okay never mind, i am not sure why it says index.js my file name is server.js and the json file is package.json

lone flame
#

what command are you using to run the server?

#

and you didn't get any errors when you ran npm install correct?

sacred dew
#

When i ran npm install i got this

#

up to date, audited 180 packages in 964ms

23 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

lone flame
#

can you run pwd and make sure you're running it in the right directory?

sacred dew
#

Wait, so i have to navigate to the folder where the json, and node js file is then run npm install there inside terminal?

lone flame
#

yes!!

sacred dew
#

wow shocking! idk how i missed that. i will do that now

#

this is how my folder looks

#

i think i am still missing some files? based on the url u shared

lone flame
#

I think the other files are just reading materials
you should be able to run it now

sacred dew
#

throw new TypeError('root path required')
^

TypeError: root path required
at Function.serveStatic [as static] modules/serve-static/index.js:40:11

#

i am getting the same error!

lone flame
#

can you comment out this line
app.use(express.static(process.env.STATIC_DIR));

#

oh wait

sacred dew
#

i commented out the line and its running1

#

!

#

do i still neeed to create a .env file?

lone flame
#

Yes as that file would configure the stripe package

#

without it, communication to Stripe won't work

sacred dew
#

Okay, i added the env file, and copied the pasted the code from the url you sent me with the example test keys, provided from the docs.

lone flame
#

You'd need to paste in your own keys ๐Ÿ™‚

sacred dew
#

Okay, so i got my test key, and secret key from the dashboard and used it inside the env file and i am getting an error that reads "undefined/index.html" I am using this only on android so i dont have an index.html file

lone flame
#

since you're only using it with an Android app, you can actually comment out that function

sacred dew
#

so i commented out the function and i am now receiving an error that reads

#

Cannot GET /

lone flame
#

Is this happening when you run npm start?

sacred dew
#

The server is running, but if try to test it by going on

#

it reads cannot get/

lone flame
#

ah that's because we removed the function.
Your android app will not need that route, right?

sacred dew
#

I don't think so i am actually not a programmer, i am just building an app for a shelter, using documentations and some basic java i learnt from youtube. So far the app is like any ecommerce, the only thing i need now is checkout, like users have items in cart, proeeed to checkout.

#

and pay.

lone flame
#

Okay. No worries.
You should be able to follow the guide you were using before though.
The server should work as intended with your android app.

sacred dew
#

Okay, so what would be the next step?

#

since that function was removed.

lone flame
sacred dew
#

Okay, i already added those will run the app now and test!

sacred dew
#

Since i am not using webhook or html is it safe to delete these 2 files from the env file?

#

STRIPE_WEBHOOK_SECRET=whsec_...

Path to front-end implementation. Note: PHP has it's own front end implementation.

STATIC_DIR=../../client/html

lone flame
#

yeah that's fine

sacred dew
#

for the paymentIntentClientSercret key from the docs here do i need to put my secret key? or are we just creating the variable, i don't see it being populated anywhere

#

because i am getting a null pointer exeception from line 28 from the docs

#

this methood

#

final PaymentMethodCreateParams params = cardInputWidget.getPaymentMethodCreateParams();

acoustic escarp
#

Hello! Taking over and catching up now...

sacred dew
#

I am getting an error when the payment button is tapped that reads " java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter clientSecret"

#

this is what my code looks like.

acoustic escarp
#

You should be getting the client secret from your server. Can you log the response you're getting from your server and see if it contains the information you expect?

sacred dew
#

how do i do this?

acoustic escarp
#

Do what specifically?

sacred dew
#

" log the response you're getting from your server"

acoustic escarp
#

You add logging code to your Android app after you receive the response from your server and log details about what you received.

sacred dew
#

Nothing comes up it says that it's null

#

so its not getting the key from the server

acoustic escarp
#

Okay, so next step is to fix that issue. ๐Ÿ™‚

sacred dew
#

coming*

#

this is basically what i copied from the docs

#

final PaymentConfiguration paymentConfiguration
= PaymentConfiguration.getInstance(getApplicationContext());
paymentLauncher = PaymentLauncher.Companion.create(
this,
paymentConfiguration.getPublishableKey(),
paymentConfiguration.getStripeAccountId(),
this::onPaymentResult
);

    paymentButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Log.i("Payment button tapped", "Payment button taped");
            //test to see if payment button is detecting taps results is successful...

            //tested to see if card widget is successfully linked and detecting taps. results is successful..
            cardInputWidget.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i("cardwigettapped", "Card widget tapped");
                }
            });

            final PaymentMethodCreateParams params = cardInputWidget.getPaymentMethodCreateParams();
            if (params != null) {
                final ConfirmPaymentIntentParams confirmParams =
                        ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams(
                                params,
                                paymentIntentClientSecret
                        );
                paymentLauncher.confirm(confirmParams);
                Log.i("paymentclientsecret", paymentIntentClientSecret);
            }


        }
    });

}
#

as well as the onPaymentResul method

#

I don't see a request being made to the end point tho.

acoustic escarp
#
  private fun startCheckout() {
      // Request a PaymentIntent from your server and store its client secret in paymentIntentClientSecret
      // Click Open on GitHub to see a full implementation
  }
#

Do you have that implemented?

sacred dew
#

Yes the start checkout method is what is ran when my button is tapped

#

i just copied the code from the startCheckOut method and put it inside the onClickListner for the payButton method.

#

i linked the widget, and the button in my onCreateMethod.

acoustic escarp
#

Sorry, where is your startCheckout code?

sacred dew
#

inside my payment button its ran when the button is clicked

#

i added a screenshot

acoustic escarp
#

But where's the code inside startCheckout?

#

I'm not seeing it in any of the code you shared so far. Am I missing it?

sacred dew
#

lines 27 to 35 from the docs right?

#

is there more to it?

acoustic escarp
#

Let's back up.

#

Your code that you've shared here. I literally do not see startCheckout anywhere.

#

This is from the docs you just linked.

#

That's what I want to see.

#

What does your startCheckout() function look like?

sacred dew
#

Yeah, i don't have that method. The code that goes inside startcheckout such as the linking the payButtonWidget by its ID as well as the inputWidget By it's ID. I did in my oncreate method. So all the widgets are linked up by their ids successfully inside the oncreate method.

#

now the

#

final PaymentMethodCreateParams params = cardInputWidget.getPaymentMethodCreateParams();
if (params != null) {
final ConfirmPaymentIntentParams confirmParams =
ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams(
params,
paymentIntentClientSecret
);
paymentLauncher.confirm(confirmParams);
}

#

This code from the accept a payment method is under my button when its tapped

acoustic escarp
#

Yeah, i don't have that method.

You can't just not have this method. That's a key piece to making all of this work.

#

You're focused on code that's not related to the problem you're experiencing.

#

The problem is that you're skipping critical steps.

#

You need to go back and implement that.

sacred dew
#

okay so i added that method, as well as the

#

onPAymenyResult method.

#

is their more code that needs to be added or is this it?