Rohail Butt
Rohail Butt

Reputation: 461

I can't create stripe token using createTokenWithCard() in React Native

I can integrate Stripe payment method in React Native app. I can use tipsi-stripe package and use createTokenwithCard() method to generate token from server but return null promise.

I am trying different thing but stripe return null promise and i am not understanding why stripe return null promise.

stripe.setOptions({ publishableKey: '*****************', androidPayMode: 'test', })

onVerifyHandler = () =>{

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

}

Promise {_40: 0, _65: 0, _55: null, _72: null}

Upvotes: 1

Views: 1026

Answers (1)

Paul Asjes
Paul Asjes

Reputation: 5857

You need to let the promise resolve to get the result. Either use an async function:

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

  console.log(token);
}

Or resolve the promise with then:

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

Upvotes: 3

Related Questions