#DeadlyData-android
1 messages ยท Page 1 of 1 (latest)
Hi there, can you tell me more about what issue you are running into or what you are confused about?
Well after implementing everything the docs, says to add this server code found here https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/server.js#L74 and i have done this but whenever attempting to run this file via terminal i get an error that reads "ode:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'cors'
Require stack:"
"node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'cors'
Require stack:
"
I am getting a new error that reads " throw new TypeError('root path required')
"
after installing the necessary pacakges.
Hmm that is pretty vague
What line is that error pointing towards?
What is the code that is throwing it?
throw new TypeError('root path required')
^
TypeError: root path required
at Function.serveStatic [as static]
static/index.js:40:11)
What is the code at static/index.js40:11?
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*
Can you share your package.json?
And just to clarify, you ran npm install, right?
yes
It looks like your Stripe version is below the one in the sample (9.2.0)
Can you upgrade to 9.2
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.
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
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,
ah okay wait... why does the error say static/index.js then ๐ค
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
what command are you using to run the server?
and you didn't get any errors when you ran npm install correct?
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
can you run pwd and make sure you're running it in the right directory?
Wait, so i have to navigate to the folder where the json, and node js file is then run npm install there inside terminal?
yes!!
your server directory should look something like this
https://github.com/stripe-samples/accept-a-payment/tree/main/custom-payment-flow/server/node
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
I think the other files are just reading materials
you should be able to run it now
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!
can you comment out this line
app.use(express.static(process.env.STATIC_DIR));
oh wait
you'd need to create a .env file in the same folder with following information
https://github.com/stripe-samples/accept-a-payment/tree/main/custom-payment-flow/server/node#how-to-run
i commented out the line and its running1
!
do i still neeed to create a .env file?
Yes as that file would configure the stripe package
without it, communication to Stripe won't work
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.
You'd need to paste in your own keys ๐
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
ah I think its coming from the / path
https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/server.js#L33
are you able to make a request to a different route?
since you're only using it with an Android app, you can actually comment out that function
so i commented out the function and i am now receiving an error that reads
Cannot GET /
Is this happening when you run npm start?
ah that's because we removed the function.
Your android app will not need that route, right?
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.
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.
Whatever is left from this guide ๐
https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=custom
Okay, i already added those will run the app now and test!
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
yeah that's fine
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();
Hello! Taking over and catching up now...
The paymentIntentClientSecret is the client_secret from the Payment Intent: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret
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.
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?
how do i do this?
Do what specifically?
" log the response you're getting from your server"
You add logging code to your Android app after you receive the response from your server and log details about what you received.
Okay, so next step is to fix that issue. ๐
I get why the error, is happening. I think i am missing something, Based on the docs here https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=custom , i do not see any request being made to the endpoint, i have running locally. So it makes sense as to why it's going as null
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.
The relevant bits would be in this section of the guide: https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=custom#android-create-payment-intent
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?
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.
Sorry, where is your startCheckout code?
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?
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?
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
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.