#krazy-dirt-payment link
1 messages · Page 1 of 1 (latest)
hi, a payment link is a public url so I don't think so
but what is your use case, maybe we could find a better suited solution that payment links
i need to add promotion codeto my checkout, so i have to create a client-server integration
i am using reactjs
but the problem is that it isn't working with me
the server.js isn't setting up with me, and when it does, it can't redirect to the store page
if i follow tutorials and adapt the path to my website, the stroe link is not working
but if i manually add a product to the homepage, it is working
could you please share the code you're using?
or could you share the error you're getting
no a snippet would be fine
const stripe = require("stripe")(
"sk_test_51KPZisGgPZMQdnTZjObemHhydbbj3DtUTlzpTp1xEeT9SRSclGdfQT7ibcn9EXEOLosr4bCnJot5zDk59DeREVff0049o7k5UO"
);
const express = require("express");
const app = express();
app.use(express.static("public"));
const YOUR_DOMAIN = "http://localhost:3001";
app.post("/create-checkout-session", async (req, res) => {
// const session = await stripe.checkout.sessions.create({
// line_items: [
// {
// // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
// price: "price_1Ko158GgPZMQdnTZcbiISc9k",
// quantity: 1,
// },
// ],
// mode: "payment",
// allow_promotion_codes: true,
// automatic_tax: { enabled: true },
// });
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: "price_1Ko158GgPZMQdnTZcbiISc9k",
quantity: 1,
},
],
mode: "payment",
allow_promotion_codes: true,
success_url: `${YOUR_DOMAIN}?success=true`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,
});
res.redirect(303, session.url);
});
app.listen(3001, () => console.log("Running on port 3001"));
``` this is the server.js
so I see you're creating a checkout session
yes 100%
<button type="submit">
Checkout
</button>
</form>``` this is the button i used
also by the sample
in the sample this is in the App.js
yes I see
in my code, i am using it in a different page
but I still don't get what the actual issue is for you
what do you mean by it's not working? the redirect isn't happening?
when i use the require("stripe")("apikey") i get errors for webpack 5 and so
the polyfill
when i implement it, i can only access the home page, but when i route to where this code is in, the page is just white
I see you're using webpack for the server side code which is not a good practice
with our sample?
no with my code
i have uninstalled webpack and did every practice
but it is still showing up
if you want you could download our sample app from https://stripe.com/docs/payments/quickstart
this might help you setting up your startup code