创建付款失败 Stripe ReactNative 中的卡详细信息不完整

问题描述 投票:0回答:1

我正在使用 @stripe/stripe-react-native": "^0.37.2" 进行付款。我想通过在表单中输入卡详细信息并在 createPaymentMethod 中传递参数来手动付款,但我收到错误 create Payment failed Card详情不完整。

从 'react' 导入 React, { useState }; 从 '@stripe/stripe-react-native' 导入 { StripeProvider, useStripe };

const { paymentMethod, error } =等待 stripe.createPaymentMethod({ 类型:'卡', 结算明细: { 名称:“珍妮·罗森”, }, 卡片: { 号码:'4242424242424242', 到期月份: 12, 预计年份: 2025, 验证码:'123', }, }); 如果(错误){ console.error('创建支付失败', error.message); } else if (付款方式) { setPaymentMethodId( paymentMethod.id ); } } 捕获(错误){ console.error('错误', '发生错误,请重试。'); } };

return (
    <StripeProvider publishableKey="YOUR_PUBLISHABLE_KEY">
        {/* Your form and submit button */}
        <button onClick={onSubmitSteps}>Submit Payment</button>
    </StripeProvider>
);

};

导出默认的MyComponent; `

我需要创建付款的解决方案

react-native expo stripe-payments strip
1个回答
0
投票
Here is whole code:                                                      
import React, { useState } from 'react';
import { StripeProvider, useStripe } from '@stripe/stripe-react-native';
const MyComponent = () => {
 const stripe = useStripe();
 const [paymentMethodId, setPaymentMethodId] = useState(null);

 const onSubmitSteps = async () => {
   try {
            const { paymentMethod, error } = await stripe.createPaymentMethod({
                type: 'Card',
                billingDetails: {
                    name: 'Jenny Rosen',
                },
                card: {
                    number: '4242424242424242',
                    expMonth: 12,
                    expYear: 2025,
                    cvc: '123',
                },
            });

            if (error) {
                console.error('create Payment failed', error.message);
            } else if (paymentMethod) {
                setPaymentMethodId(paymentMethod.id);
            }
        } catch (error) {
            console.error('Error', 'An error occurred, please try again.');
        }
    };

    return (
        <StripeProvider publishableKey="YOUR_PUBLISHABLE_KEY">
            {/* Your form and submit button */}
            <button onClick={onSubmitSteps}>Submit Payment</button>
        </StripeProvider>
    );
};
© www.soinside.com 2019 - 2024. All rights reserved.