#krazy-dirt-payment link

1 messages · Page 1 of 1 (latest)

graceful grove
#

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

uneven schooner
#

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

graceful grove
#

could you please share the code you're using?

#

or could you share the error you're getting

uneven schooner
#

i am not getting an error

#

you want me to share with you the sample zip?

graceful grove
#

no a snippet would be fine

uneven schooner
#
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
graceful grove
#

so I see you're creating a checkout session

uneven schooner
#

yes 100%

#
      <button type="submit">
        Checkout
      </button>
    </form>``` this is the button i used
#

also by the sample

uneven schooner
graceful grove
#

yes I see

uneven schooner
#

in my code, i am using it in a different page

graceful grove
#

but I still don't get what the actual issue is for you

uneven schooner
#

it's not working

#

without any error

graceful grove
#

what do you mean by it's not working? the redirect isn't happening?

uneven schooner
#

when i use the require("stripe")("apikey") i get errors for webpack 5 and so

#

the polyfill

uneven schooner
graceful grove
#

I see you're using webpack for the server side code which is not a good practice

uneven schooner
#

it came automatically

#

i don't know why to be honest

graceful grove
#

with our sample?

uneven schooner
#

no with my code

#

i have uninstalled webpack and did every practice

#

but it is still showing up

graceful grove
#

this might help you setting up your startup code

uneven schooner
#

okay deal

#

thank youu