Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js I';我正在尝试在React应用程序和节点服务器上使用条带支付_Node.js_Reactjs_Express_Stripe Payments_Production Environment - Fatal编程技术网

Node.js I';我正在尝试在React应用程序和节点服务器上使用条带支付

Node.js I';我正在尝试在React应用程序和节点服务器上使用条带支付,node.js,reactjs,express,stripe-payments,production-environment,Node.js,Reactjs,Express,Stripe Payments,Production Environment,我是一个自学成才的程序员,有很多东西要学:) 我正在为我的第一个客户建立一个网站,我正在尝试实现Stripe支付平台。我正在使用React.js express和Node进行构建。我在安装的大部分时间都在使用本文: 在我的测试API上,一切都非常完美。我可以看到测试数据与付款和一切。当我使用live API密钥访问live网站时,不会产生费用。它发布API调用并拥有所有正确的信息,但不向卡收费 在文章的中途,他提到了支付服务器URL,经过我的挖掘,我认为这可能是问题所在。我不是100%理解他所说

我是一个自学成才的程序员,有很多东西要学:)

我正在为我的第一个客户建立一个网站,我正在尝试实现Stripe支付平台。我正在使用React.js express和Node进行构建。我在安装的大部分时间都在使用本文:

在我的测试API上,一切都非常完美。我可以看到测试数据与付款和一切。当我使用live API密钥访问live网站时,不会产生费用。它发布API调用并拥有所有正确的信息,但不向卡收费

在文章的中途,他提到了支付服务器URL,经过我的挖掘,我认为这可能是问题所在。我不是100%理解他所说的“myapidomain”。当我不在生产时,它只是我的本地主机:8080。我不确定在我的生产现场会是什么

如果有帮助的话,我将与HostGator一起主持。我已经花了大约3天的时间试图弄明白这一点,但不知道还能向何处求助

前端条带组件.js

import React, { Component } from 'react'
import StripeCheckout from 'react-stripe-checkout';
import axios from 'axios'
import STRIPE_PUB_KEY from '../../../constants/stripePubKey'
import PAYMENT_SERVER_URL from '../../../constants/stripeServer'
import { clearReduxCart } from '../../../ducks/reducer'


const CURRENCY = 'usd';

const successPayment = (redirectHome, clearReduxCart) => {
  alert('Payment Successful');
  localStorage.clear()
  clearReduxCart()
  return redirectHome(true)
};

const errorPayment = data => {
  alert('Payment Error', data);
};

const onToken = (amount, description, email, redirectHome, clearReduxCart) => token =>
  axios.post(PAYMENT_SERVER_URL,
    {
      description,
      source: token.id,
      currency: CURRENCY,
      amount: amount,
      receipt_email: token.email
    })
    .then(successPayment(redirectHome, clearReduxCart))
    .catch(errorPayment);

const Checkout = ({ name, description, amount, email, redirectHome, clearReduxCart }) =>
  <StripeCheckout
    name={name}
    description={description}
    amount={amount}
    email={email}
    token={onToken(amount, description, email, redirectHome, clearReduxCart)}
    currency={CURRENCY}
    stripeKey={STRIPE_PUB_KEY}
    shippingAddress
    receipt_email
  />



export default Checkout
server/server.js

const cors = require('cors');
const bodyParser = require('body-parser');

const CORS_WHITELIST = require('./const/frontend');

const corsOptions = {
  origin: (origin, callback) =>
    (CORS_WHITELIST.indexOf(origin) !== -1)
      ? callback(null, true)
      : callback(new Error('Not allowed by CORS'))
};

const configureServer = app => {
  app.use(cors());

  app.use(bodyParser.json());
};

module.exports = configureServer;
server/routes/payments.js

const stripe = require('../const/stripe');

const postStripeCharge = res => (stripeErr, stripeRes) => {
  if (stripeErr) {
    res.status(500).send({ error: stripeErr });
  } else {    
    res.status(200).send({ success: stripeRes });
  }
}

const paymentApi = app => {
  app.get('/', (req, res) => {
    res.send({ message: 'Hello Stripe checkout server!', timestamp: new Date().toISOString() })
  });

  app.post('/', (req, res) => {
    stripe.charges.create({
      amount: req.body.amount,
      currency: req.body.currency,
      source: req.body.source,
      description: req.body.description
    }, postStripeCharge(res));
  });

  return app;
};

module.exports = paymentApi;

有几件事:1)你能发布你的服务器端代码吗。2) 通过使用postman或curl调用API,您是否已经从等式中删除了React?如果没有,请尝试一下,然后发布curl命令的副本(或邮递员呼叫的详细信息)。然后,您可以将问题简化为服务器端代码。确保不要发布任何API密钥!:)嗨,艾略特!谢谢你的快速回复。我将立即编辑我的问题并添加代码。老实说,我从来没有听说过邮递员或卷发。然而,我肯定会学习如何,如果它将帮助我作为一个网络开发人员。非常感谢。两者都只允许您对服务(本地运行或在另一台服务器上运行)进行HTTP调用。如果您发布他们的详细信息,那么我们也可以看到您发送的示例数据和格式,这只是确保它不会像您从React发送到API的数据那样愚蠢。Postman可能是最用户友好的,但curl最适合将问题发布到stackoverflow等。好的,是的,这完全有意义!我必须这么做,因为问题可能就在那里。再次感谢您的投入,我非常感谢!
const stripe = require('../const/stripe');

const postStripeCharge = res => (stripeErr, stripeRes) => {
  if (stripeErr) {
    res.status(500).send({ error: stripeErr });
  } else {    
    res.status(200).send({ success: stripeRes });
  }
}

const paymentApi = app => {
  app.get('/', (req, res) => {
    res.send({ message: 'Hello Stripe checkout server!', timestamp: new Date().toISOString() })
  });

  app.post('/', (req, res) => {
    stripe.charges.create({
      amount: req.body.amount,
      currency: req.body.currency,
      source: req.body.source,
      description: req.body.description
    }, postStripeCharge(res));
  });

  return app;
};

module.exports = paymentApi;