#ak_api

1 messages ¡ Page 1 of 1 (latest)

vestal shoalBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1263097251878670399

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

fair wedgeBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

  • ak_code, 16 hours ago, 50 messages
cosmic jacinth
#

I can't visit your URL as its localhost

#

But the message you shared it just warning and shouldn't prevent Checkout from loading really

vast lintel
cosmic jacinth
#

The error is beneath: Unexpected token

vast lintel
#

You're right, But I am stuck for hours now

cosmic jacinth
#

Can you paste the exact code you're using, particularly what you're passing to fetchClientSecret and the corresponding code that creates the session

vast lintel
#

Sure

#

// Create a Checkout Session
async function initialize() {
const fetchClientSecret = async () => {
const response = await fetch("/create-checkout-session", {
method: "POST",
});
const { clientSecret } = await response.json();
return clientSecret;
};

const checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});

// Mount Checkout
checkout.mount('#checkout');
}

cosmic jacinth
#

What does the /create-checkout-session endpoint look like?

vast lintel
#

// This is your test secret API key.
const stripe = require('stripe')('it has my STRIPE_PUBLISHABLE_KEY');
const express = require('express');
const app = express();
app.use(express.static('public'));

const YOUR_DOMAIN = 'http://localhost:4242';

app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
ui_mode: 'embedded',
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'price_1PcXUlSEhVjYU2OjEdpddTgH',
quantity: 1,
},
],
mode: 'payment',
return_url: ${YOUR_DOMAIN}/return.html?session_id={CHECKOUT_SESSION_ID},
});

res.send({clientSecret: session.client_secret});
});

app.get('/session-status', async (req, res) => {
const session = await stripe.checkout.sessions.retrieve(req.query.session_id);

res.send({
status: session.status,
customer_email: session.customer_details.email
});
});

app.listen(4242, () => console.log('Running on port 4242'));

#

server.js file

cosmic jacinth
#

Can you add some logging to your /create-checkout-session endpoint to ensure the sessions is actually created?

vast lintel
#

Is this code fine for creating session : // This is your test secret API key.
const stripe = require('stripe')('STRIPE_PUBLISHABLE_KEY');
const express = require('express');
const app = express();
app.use(express.static('public'));

const YOUR_DOMAIN = 'http://localhost:4242';

app.post('/create-checkout-session', async (req, res) => {
try {
console.log('Creating checkout session...');

const session = await stripe.checkout.sessions.create({
  ui_mode: 'embedded',
  line_items: [
    {
      // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
      price: 'price_1PcXUlSEhVjYU2OjEdpddTgH',
      quantity: 1,
    },
  ],
  mode: 'payment',
  return_url: `${YOUR_DOMAIN}/return.html?session_id={CHECKOUT_SESSION_ID}`,
});

console.log('Checkout session created:', session);

res.send({ clientSecret: session.client_secret });

} catch (error) {
console.error('Error creating checkout session:', error.message);
res.status(500).json({ error: error.message });
}
});

app.get('/session-status', async (req, res) => {
const session = await stripe.checkout.sessions.retrieve(req.query.session_id);

res.send({
status: session.status,
customer_email: session.customer_details.email
});
});

app.listen(4242, () => console.log('Running on port 4242'));

cosmic jacinth
vast lintel
cosmic jacinth
#

OK, then the error is at the top:
This API call cannot be made with a publishable API key. Please use a secret API key. You can find a list of your API keys at https://dashboard.stripe.com/account/apikeys.

#
const stripe = require('stripe')('it has my STRIPE_PUBLISHABLE_KEY');
#

You need to use your secret key here (sk_test_xxx)

vast lintel
#

Ohhhhhhhhh

#

Thank God !!!!!!

#

Finally I have fixing this for since morning 10:30

#

Brother Thanks a lot

#

Just one thing now

#

How do I fix the error stated in the image

gilded viper
#

hi! I'm taking over this thread.

vast lintel
#

Hello

gilded viper
#

the error is pretty clear: you need to collect both a shipping and a billing address

vast lintel
#

What do I do to fix It

vast lintel
#

Will this code fix it : <?php

require_once '../vendor/autoload.php';
require_once '../secrets.php';

$stripe = new \Stripe\StripeClient($stripeSecretKey);
header('Content-Type: application/json');

$YOUR_DOMAIN = 'http://localhost:4242';

$checkout_session = $stripe->checkout->sessions->create([
'ui_mode' => 'embedded',
'customer_email' => 'customer@example.com',
'submit_type' => 'donate',
'billing_address_collection' => 'required',
'shipping_address_collection' => [
'allowed_countries' => ['US', 'CA'],
],
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => '{{PRICE_ID}}',
'quantity' => 1,
]],
'mode' => 'payment',
'return_url' => $YOUR_DOMAIN . '/return.html?session_id={CHECKOUT_SESSION_ID}',
]);

echo json_encode(array('clientSecret' => $checkout_session->client_secret));

gilded viper
#

best way to find out is to try this in test mode

vast lintel
#

Well It didn't Fix

cosmic jacinth
#

Do you intend to charge in currencies other than INR?

#

The issue is because you're trying to process USD as an IN merchant

vast lintel
#

Soma, Can you help me what line exactly should I be pasting this code : {
"id": "cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 2198,
"amount_total": 2198,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": null,
"cancel_url": null,
"client_reference_id": null,
"consent": null,
"consent_collection": null,
"created": 1679600215,
"currency": "usd",
"custom_fields": [],
"custom_text": {
"shipping_address": null,
"submit": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": null,
"customer_email": null,
"expires_at": 1679686615,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {},
"rendering_options": null
}
},
"livemode": false,
"locale": null,
"metadata": {},
"mode": "payment",
"payment_intent": null,
"payment_link": null,
"payment_method_collection": "always",
"payment_method_options": {},
"payment_method_types": [
"card"
],
"payment_status": "unpaid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [],
"status": "open",
"submit_type": null,
"subscription": null,
"success_url": "https://example.com/success",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"url": "https://checkout.stripe.com/c/pay/cs_test_a11YYufWQzNY63zpQ..

vast lintel
vast lintel
gilded viper
#

sorry for the delay

#

Well It didn't Fix
what error message did you see? the exact same as before?

vast lintel
#

Okay, So there are few things that need to be fixed

#

We'll go one by one

#
  1. When i click on card or Full name on card it says : automatic credit card filling it disabled because this form does not support secure connection.
gilded viper
#

can you share a screenshot of this error?

vast lintel
#
  1. Need More payment methods, Like Apply, Gpay, Amazon Pay, Link, Etc on the embedded form
#

Sure

gilded viper
#

is this the embeded Checkout Session? does the URL use httpS or not?

vast lintel
#

Nop : It's http

gilded viper
#

then yes that's expected

#

as mentioned in the error message, you need to use a secure connection, so using httpS

#

also that error is not from Stripe, but most likely from your browser or a browser extension.

gilded viper
#

this question is unrelated to Stripe, and depend on your server configuration. so we can't really help with this.

vestal shoalBOT
vast lintel
#

So, Do you khave any idea on fixing this type of issues

gilded viper
#

which issue?

vast lintel
#

Do i need to get an SSL certificate

gilded viper
#

I explained it to you: this is not a Stripe error. but to remove it you need to be using httpS

pulsar moss
#

Hello
As soma mentioned, we can't help much with this error. I've typically seen folks use ngrok or similar tunneling services that serve the site over HTTPS

vast lintel
#

I see, How do i use https instead of http

pulsar moss
#

I'd recommend searching the web for more resources

pulsar moss
#

For live mode, you'll want to buy an SSL certificate and configure HTTPS on your server

vast lintel
#

Okay, But, As of now I am testing on test mode it should show the payment methods ?

#

Following these will fix the error right : if you are embedding a Stripe payment form directly on your website using HTML, it's recommended to have an SSL certificate (HTTPS) for secure transactions. This ensures that sensitive information, such as credit card details, is encrypted during transmission between your users and your server. Without HTTPS, modern browsers may block certain features, like automatic credit card filling, and may show warnings to users about insecure connections.

To secure your website with HTTPS:

Obtain an SSL Certificate: You can get an SSL certificate from a trusted certificate authority (CA) or through your web hosting provider.

Install the SSL Certificate: Follow your web hosting provider's instructions to install the SSL certificate on your server. This typically involves generating a CSR (Certificate Signing Request) and applying the issued certificate to your domain.

Update Your Website Settings: Once the certificate is installed, update your website settings to force HTTPS. This ensures that all traffic to your site is encrypted.

Update Links and References: Make sure all references to resources (like CSS, JavaScript files, and API endpoints) on your website are using HTTPS URLs.

After implementing HTTPS, ensure to test your Stripe integration thoroughly to verify that all payment methods, including Apple Pay, Google Pay, and others, function correctly without any browser warnings.

pulsar moss
#

Some restrictions are enforced by the wallet providers.. There's nothing Stripe can do to workaround those.

For test mode, you can use tunneling services as I mentioned above: #1263097251878670399 message

For live mode, you'd need to configure SSL certificate on your server

vast lintel
#

I see

#

I will get the SSL certification, After making the http < https, How do I add payment methods to my embedded form ?