当前位置: 首页 > 知识库问答 >
问题:

条纹支付法。使用卡片[拆分形式]不起作用。无法获取卡号过期和cvc号

袁凌
2023-03-14

我正在用react和Node实现stripe。但我没有得到这些值

    <CardNumberElement/>
    <CardExpiryElement/> 
    <CardCvcElement/>
import React from "react";
import { loadStripe } from "@stripe/stripe-js";
import {
    Elements,
    CardElement,
    useStripe,
    useElements,
    CardNumberElement,
    CardExpiryElement,
    CardCVCElement,
    injectStripe,
    StripeProvider,
    CardCvcElement
} from "@stripe/react-stripe-js";
import axios from "axios";
import { ServiceBooking } from "../../services/service-booking"


const CheckoutForm = ({ success }) => {
    const stripe = useStripe();
    const elements = useElements();

    const handleSubmit = async event => {
        event.preventDefault();
        let number = elements.getElement(CardNumberElement);
        let cvc = elements.getElement(CardCvcElement);
        console.log("farrukh",number)
        const { error, paymentMethod } = await stripe.createPaymentMethod({
            type: "card",
            card: {
                number: number,
                exp_month: 4,
                exp_year: 2021,
                cvc: cvc,
              }
        });

        if (!error) {
            const { id } = paymentMethod;

            try {
                const data = await ServiceBooking.charge(id, 1099);
                console.log(data);
                success();
            } catch (error) {
                console.log(error);
            }
        }
    };

    return (
        <form
            onSubmit={handleSubmit}
            style={{ maxWidth: "400px", margin: "0 auto" }}
        >
            <h2>Price: $10.99 USD</h2>
            <CardNumberElement/>
            <CardExpiryElement/> 
            <CardCvcElement/>
            <button type="submit" disabled={!stripe}>
                Pay
      </button>
        </form>
    );
};

// you should use env variables here to not commit this
// but it is a public key anyway, so not as sensitive
const stripePromise = loadStripe("pk_test_wSvr6guTJvkKmv21jVqVd2D20049BVPKHP");

const Checkout = () => {
    const [status, setStatus] = React.useState("ready");

    if (status === "success") {
        return <div>Congrats on your empanadas!</div>;
    }

    return (
          <Elements stripe={stripePromise}>
              <CheckoutForm
                  success={() => {
                  setStatus("success");
                 }}
              />
          </Elements>
    );
};

export default Checkout;

router.post(
    "/charge",
    asyncHandler(async function (req, res) {
        const { id, amount } = req.body;

  try {
    const payment = await stripe.paymentIntents.create({
      amount,
      currency: "USD",
      payment_method: id,
      confirm: true
    });

    console.log(payment);

    return res.status(200).json({
      confirm: "abc123"
    });
  } catch (error) {
    console.log(error);
    return res.status(400).json({
      message: error.message
    });
  }
    })
);

我试过了,但不能成功收费(付款)

共有1个答案

穆睿才
2023-03-14

您需要更改前端代码。要使拆分窗体工作,应在。CreatePaymentMethod下使用三个不同的(卡)键分别捕获CardNumberElement、CardExpiryElement和CardCvcElement

  .createPaymentMethod(
    {
      type: 'card',
      card: elements.getElement(CardNumberElement),
      card: elements.getElement(CardExpiryElement),
      card: elements.getElement(CardCvcElement),
    }

前端代码应该如下所示:

import React from "react";
import { loadStripe } from "@stripe/stripe-js";
import {
    Elements,
    CardElement,
    useStripe,
    useElements,
    CardNumberElement,
    CardExpiryElement,
    CardCVCElement,
    injectStripe,
    StripeProvider,
    CardCvcElement
} from "@stripe/react-stripe-js";
import axios from "axios";
import { ServiceBooking } from "../../services/service-booking"


const CheckoutForm = ({ success }) => {
    const stripe = useStripe();
    const elements = useElements();

    const handleSubmit = async event => {
        event.preventDefault();
        const { error, paymentMethod } = await stripe.createPaymentMethod({
          type: 'card',
          card: elements.getElement(CardNumberElement),
          card: elements.getElement(CardExpiryElement),
          card: elements.getElement(CardCvcElement),
        });

        if (!error) {
            const { id } = paymentMethod;

            try {
                const data = await ServiceBooking.charge(id, 1099);
                console.log(data);
                success();
            } catch (error) {
                console.log(error);
            }
        }
    };

    return (
        <form
            onSubmit={handleSubmit}
            style={{ maxWidth: "400px", margin: "0 auto" }}
        >
            <h2>Price: $10.99 USD</h2>
            <CardNumberElement/>
            <CardExpiryElement/> 
            <CardCvcElement/>
            <button type="submit" disabled={!stripe}>
                Pay
      </button>
        </form>
    );
};

// you should use env variables here to not commit this
// but it is a public key anyway, so not as sensitive
const stripePromise = loadStripe("pk_test_wSvr6guTJvkKmv21jVqVd2D20049BVPKHP");

const Checkout = () => {
    const [status, setStatus] = React.useState("ready");

    if (status === "success") {
        return <div>Congrats on your empanadas!</div>;
    }

    return (
          <Elements stripe={stripePromise}>
              <CheckoutForm
                  success={() => {
                  setStatus("success");
                 }}
              />
          </Elements>
    );
};

export default Checkout;
 类似资料:
  • 我正在用stripe设置定期支付。我正在使用react-stripe-elements来收集卡信息,看起来有两种方法可以保存卡供以后使用:

  • 我们已经实施贝宝支付到我的网站。 我们正在用沙箱测试模式进行检查。付款通过登录与贝宝帐户工作罚款,但没有登录贝宝帐户使用卡选项付款不工作。我正在尝试测试卡的详细信息,它会显示这样的错误信息:“您输入的卡不能用于此付款。请输入其他的借记卡或信用卡号码。” 我有用户所有由贝宝提供的卡号仍有错误 https://developer.paypal.com/webapps/developer/docs/cl

  • 说明 微信刷卡支付SDK。 官方文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1 类 请求参数类 支付参数 类名:\Yurun\PaySDK\Weixin\Micropay\Params\Pay\Request 属性 名称 类型 说明 $_apiMethod string 接口名称 $auth_c

  • 我使用realex支付与iframe我可以加载支付页面正确,但一旦我点击立即支付它返回错误: 508消息:处理您的请求发生了错误。请联系您购买的商品或服务引用以下错误代码的商家: 61,754(大多数时候它返回正确的响应字符串成功或拒绝),但有时它返回以上错误代码)任何想法是什么意思以及如何解决这个问题?

  • 嗨,我一直在我的项目中第一次使用条纹,我要求用户提供他们的信用卡支付细节 我尝试将name属性添加到stripe生成令牌所需的字段中,但是在表单POST中它是空的。

  • 我们正在整合微软Azure广告与我们的应用程序。我正在尝试使用微软图形API(https://graph.microsoft.com/v1.0/users/{id | userPrincipalName }/photo/$ value)获取用户个人资料图片。但这对我不起作用。我已经在应用程序中给出了该API所需的所有权限,但每次都得不到响应。你能告诉我我错过了什么配置吗? 答复: 谢谢