我无法在React Native中使用createTokenWithCard()创建条纹令牌

时间:2019-06-11 05:22:05

标签: react-native stripe-payments

我可以在React Native应用程序中集成Stripe付款方式。我可以使用tipsi-stripe包并使用createTokenwithCard()方法从服务器生成令牌,但返回空承诺。

我正在尝试不同的操作,但是stripe返回空promise,而我不明白为什么stripe返回空promise。

stripe.setOptions({             publishableKey:'*****************',             androidPayMode:“测试”,           })

onVerifyHandler =()=> {

const token =  stripe.createTokenWithCard({
    number: '4242424242424242',
    expMonth: 11,
    expYear: 17,
    cvc: '223'});
  console.log(token);

}

承诺{_40:0,_65:0,_55:空,_72:空}

1 个答案:

答案 0 :(得分:2)

您需要让诺言化解才能得到结果。使用异步功能:

onVerifyHandler = async () => {
  const token = await stripe.createTokenWithCard({
    number: '4242424242424242',
    expMonth: 11,
    expYear: 17,
    cvc: '223'
  });

  console.log(token);
}

或通过then兑现承诺:

onVerifyHandler = () => {
  stripe.createTokenWithCard({
    number: '4242424242424242',
    expMonth: 11,
    expYear: 17,
    cvc: '223'
  }).then(token => {
    console.log(token);
  }).catch(error => {
    console.log(error);
  });
}