#kawuss
1 messages · Page 1 of 1 (latest)
have you confirmed that the api key you're passing in when initializing stripe is correct?
that would be the first step
You'd log it in your client-side code to make sure it's correct
When I try to log my publishableKey is nothing nothing happens
it's udefined
undefined
Then that's your issue - you need to make sure it's being set correctly
so how I can do it ?
I create a payment on the first time and I don't know how to fix it
What does your code look like that set's it? Where is it getting the publishable key from?
On the js: document.addEventListener("DOMContentLoaded", async () => {
//Fetch the publishable key from the server
const {publishableKey} = await fetch("/config").then(r => r.json);
console.log(publishableKey)
const stripe = Stripe(publishableKey);
//Fetch the client secret property for the payment intent
const {clientSecret} = await fetch("/create-payment-intent", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
}).then(r => r.json);
//Mount elements
const elements = stripe.elements({clientSecret});
const paymentElement = elements.create('payment');
});
On the java: post("/create-payment-intent", (request, response) -> {
response.type("application/json");
PaymentIntentCreateParams params = PaymentIntentCreateParams.builder()
.setAmount(1099L)
.setCurrency("pln")
.setAutomaticPaymentMethods(
PaymentIntentCreateParams.AutomaticPaymentMethods.builder()
.setEnabled(true)
.build()
)
.build();
PaymentIntent intent = PaymentIntent.create(params);
HashMap<String, String> clientSecretResp = new HashMap<>();
clientSecretResp.put("clientSecret", intent.getClientSecret());
return gson.toJson(clientSecretResp);
});
So it looks like you're calilng to your server (the /config endpoint) to get the publishable key?
Your next step then is to debug your server and see why it's not giving you back the response you expect
but my server giving back me my secret client after this command
That's not your issue though - your issue is in line 4 with your publishable key
the payment intent client secret is differnet and unrelated to your current issue
so How I can fix it ?
As I said - you need to debug your own server and integration and see what the specific issue is
I don't know what your server's /config endpoint is doing - so it's up to you to see what the current behavior is and narrow down what the error could be
Ok thank's for help
I have one more question why when I create Stripe Sample I haven't got any CreatePaymentRequest metod ?
Which sample are you looking at?
When I create Sample with stripe vs code extentions
and I haven't got get method on the server which would explain my problem
there's a lot of different samples - I'd expect that some would have CreatePaymentRequest, but probably not all of them need it
so How I can correctly
Are you 100% sure that's the issue? Did you do when I mentioned about debugging your /config endpoint?
Are you a developer? Generally, you should be systematically adding logs or breakpoints to confirm that each step ofyour code is behaving as you expect
No I'm studing develop
I said it is my first time in add every payment method in my project
Is this an integration you intend to put into production? Or is this just you trying things out? If it's something you need to be production ready I'd strongly recommend you look into some of the no-code/low code solutions or hire a developer to help you get it production ready
I extends my skills and I trying things out
Gotcha
Then yeah, you need to do what I mentioned - add logs, breakpoints, look at your server requests (make sure your server is actually being hit), etc
no worries! happy to help
Did you know how catch in Java information about payments with generate payments link ?
in stripe generate payments link