Ошибка 404 не найдена: экспресс-интеграция пьямента с узлом платежной системы - PullRequest
0 голосов
/ 19 октября 2019

Я пытаюсь установить интеграцию платежей с помощью Stripe на веб-сайт, но я не знаю, как исправить эту ошибку, я следую инструкциям в Интернете, но я вижу, что он мог пропустить эту ошибку, но в моем коде все еще есть ошибка

Я пытался использовать номер тестовой карты, который обслуживает полоса, но он все еще не работал

это конфигурация полоски

Stripe.setPublishableKey("pk_test_mW4eDdrbC3sEPQ0BZip9rFrw00L1zRk3Em");

var $form = $("#checkout-form");

$form.submit(function(event) {
  $("#charge-error").addClass("d-none");
  $form.find("button").prop("disabled", true);
  Stripe.card.createToken(
    {
      number: $("#card-number").val(),
      cvc: $("#card-cvc").val(),
      exp_month: $("#card-expiry-month").val(),
      exp_year: $("#card-expiry-year").val(),
      name: $("#card-name").val()
    },
    stripeResponseHandler
  );
  return false;
});

function stripeResponseHandler(status, response) {
  if (response.error) {
    // Problem!

    // Show the errors on the form
    $("#charge-error").text(response.error.message);
    $("#charge-error").removeClass("d-none");
    $form.find("button").prop("disabled", false); // Re-enable submission
  } else {
    // Token was created!

    // Get the token ID:
    var token = response.id;

    // Insert the token into the form so it gets submitted to the server:
    $form.append($('<input type="hidden" name="stripeToken" />').val(token));

    // Submit the form:
    $form.get(0).submit();
  }
}

и это index.js

router.get("/checkout", function(req, res, next) {
  if (!req.session.cart) {
    return res.redirect("/shopping-cart");
  }
  var cart = new Cart(req.session.cart);
  var errMsg = req.flash("error")[0];
  res.render("shop/checkout", {
    total: cart.totalPrice,
    errMsg: errMsg,
    noErrors: !errMsg
  });
});

router.post("/checkout", function(req, res, next) {
  if (!req.session.cart) {
    return res.redirect("/shopping-cart");
  }
  var cart = new Cart(req.session.cart);

  var stripe = require("stripe")("sk_test_uDIFUkLi6pqMa1M4iG78eAKq004N78CImt");

  // `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/cards/collecting/web#create-token
  stripe.charges.create(
    {
      amount: cart.totalPrice,
      currency: "usd",
      source: req.body.stripeToken,
      description: "Test Charge"
    },
    function(err, charge) {
      // asynchronously called
      if (err) {
        req.flash("error", err.message);
        return res.redirect("/checkout");
      }
      req.flash("success", "Successfully bought product");
      req.session.cart = null;
      res.redirect("/");
    }
  );
});


i want to fix this checkout system problem
this is the error

Not Found
404
NotFoundError: Not Found
    at /home/aldo/Documents/webproject/shopping-cart/app.js:61:8
    at Layer.handle [as handle_request] (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:317:13)
    at /home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:335:12)
    at next (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:275:10)
    at /home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:635:15
    at next (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:174:3)
    at router (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:317:13)
    at /home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:335:12)
    at next (/home/aldo/Documents/webproject/shopping-cart/node_modules/express/lib/router/index.js:275:10)
    at /home/aldo/Documents/webproject/shopping-cart/app.js:53:3
...