skip to Main Content

I am currently using the Stripe React Native SDK to confirm payment and to add users to the backend with their bank details. This is so that users can be paid. However, the previous developer used the tipsi-stripe library but it is pretty much deprecated so the app keeps on crashing. Can anyone offer me guidance?

I can’t understand createTokenWithCard and createTokenWithBankAccount –what are methods that should replace these? Any help would be appreciated.

      if (type === 'CARD') {
      const valid = cardData.valid;
      if (!valid) return;
      const cardValues = cardData.values;
      const expParts = cardValues.expiry.split('/');
      const cardParams = {
        cvc: cardValues.cvc,
        expMonth: Number.parseInt(expParts[0], 10),
        expYear: Number.parseInt(expParts[1], 10),
        number: cardValues.number.split(' ').join(''),
        currency: 'eur',
      };

      const cardToken = await stripe.createTokenWithCard(cardParams);
      if (cardToken.card.funding !== 'debit') {
        setIsRequestLoading(false);
        setError('Sorry');
        setMessage('We can only accept debit cards');
        return popupRef.current.open();
      }
      cardMethod = cardToken.tokenId;
    } else {
      const bankToken = await stripe.createTokenWithBankAccount({
        accountNumber: IBAN,
        countryCode: values.country === 'Ireland' ? 'IE' : 'GB',
        currency: 'eur',
      });
      bankMethod = bankToken.tokenId;
    }
    const account = {
      ...values,
      cardID: cardMethod ? cardMethod : undefined,
      bankDetails: bankMethod ? bankMethod : undefined,
      email: ctx.user.email,
      phone: ctx.user.phoneNumber || '',
    };

    try {
      const res = await createAccount({
        variables: {
          account,
        },
      });

      if (res.data && res.data.id) {
        handleUpdate();
      } else {
        setWithReport(true);
        setIsRequestLoading(false);
        setError('Something went wrong.');
        popupRef.current.open();
      }
    } catch (error) {
      setIsRequestLoading(false);
      const e = extractGraphQLError(error);
      setError('Something went wrong.');
      setMessage(e);
      if (e === DEFAULT_ERROR) setWithReport(true);
      popupRef.current.open();
    }
}

Please help me to proceed in the right direction.

2

Answers


  1. check any of these new Methods

    const {
        collectBankAccountToken,
        collectBankAccountForSetup,
        collectBankAccountForPayment,
        createToken
      } = useStripe();
    
    Login or Signup to reply.
  2. Creating a token is legacy and no longer recommended. If you wish to accept IBAN for payments, you may use SEPA direct debit. Here’s the integration guide of SEPA direct debit on React Native SDK: https://stripe.com/docs/payments/sepa-debit/accept-a-payment?platform=mobile

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search