React Native Stripe Firebase - 测试令牌有效但测试卡未定义

React Native Stripe Firebase - Test token working but test card undefined

我正在尝试通过 firebase 云函数发送我的费用以进行条带化,当我发送诸如“tok_mastercard”之类的测试令牌时,一切正常。一旦我替换了由 tipsi stripe 创建的令牌,firebase 就会显示所有发送的信息都是未定义的。我的控制台在云函数中记录了我的令牌,一切看起来都很好。

我觉得我遗漏了一些明显的东西。在此先感谢您的帮助。

FIREBASE 云功能

const functions = require("firebase-functions");
const stripe = require("stripe")(MY SECRET KEY);

exports.payWithStripe = functions.https.onRequest(async (request, response) => {
  stripe.charges
    .create({
      amount: request.body.amount,
      currency: request.body.currency,
      source: request.body.token,
    })
    .then((charge) => response.send(charge))
    .catch((err) => {
      console.log(err);
    });
});

控制台记录的令牌

{"card": {"addressCity": "Macon", "addressCountry": "Estonia", "addressLine1": "Canary Place", "addressLine2": "3", "addressState": "", "addressZip": "31217", "brand": "Visa", "cardId": "card_1HdFN7C7qEwniOSJWxN2Tbs6", "country": "US", "expMonth": 1, "expYear": 2022, "funding": "credit", "isApplePayCard": false, "last4": "4242", "name": "Enappd Store"}, "created": 1602940977, "livemode": false, "tokenId": "tok_1HdFN7C7qEwniOSJc1nUQcqH"}

使用 TIPSI 条纹生成令牌


  stripe.setOptions({
    publishableKey:"MY TEST KEY",});

  const [token, setToken] = useState(null);


  const handleCardPayPress = async () => {
    try {
      setLoading(true);
      setToken(null);
      const token = await stripe.paymentRequestWithCardForm({
        smsAutofillDisabled: true,
        requiredBillingAddressFields: "full",
        prefilledInformation: {
          billingAddress: {
            name: "Enappd Store",
            line1: "Canary Place",
            line2: "3",
            city: "Macon",
            state: "",
            country: "Estonia",
            postalCode: "31217",
            email: "admin@enappd.com",
          },
        },
      });
      setToken(token);
      console.log(token);
      setLoading(false);
      Alert.alert("Your card information has been entered!");
    } catch (error) {
      console.log(error);
      setLoading(false);
    }
  };

处理结账

    fetch("MY CLOUD FUNCTIONS URL", {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        amount: cartTotalAmount,
        currency: "usd",
        token: token,
      }),
    })
      .then((response) => response.json())
      .then((responseJson) => {
        console.log(responseJson);
      })
      .catch((error) => {
        console.error(error);
      });

FIREBASE 日志

9:43:09.377 AM
payWithStripe
statusCode: 400,
9:43:09.377 AM
payWithStripe
charge: undefined,
9:43:09.377 AM
payWithStripe
decline_code: undefined,
9:43:09.377 AM
payWithStripe
payment_intent: undefined,
9:43:09.377 AM
payWithStripe
payment_method: undefined,
9:43:09.377 AM
payWithStripe
setup_intent: undefined,
9:43:09.377 AM
payWithStripe
source: undefined }
9:44:08.752 AM
payWithStripe
Function execution took 60008 ms, finished with status: 'timeout'

解决方案是更改:

setToken(token)

setToken(token.tokenId)