反应本机导航条

时间:2020-08-10 16:45:14

标签: react-native stripe-payments react-navigation

我试图从导航到用户输入信用卡详细信息并按“付款”按钮,然后将其带到我应用程序中的另一个屏幕。我已经将导航路径设置为一个名为product的屏幕。但是我的付款功能通过Stripe进行付款,但没有导航到下一个屏幕。我在做什么错了?

这是我的付款功能

  import React, { useState } from 'react'
    import { Image, Text, TextInput, TouchableOpacity, View,ImageBackground } from 'react-native'
    import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
    import styles from './styles';
    import stripe from 'tipsi-stripe';
    import axios from 'axios'

 stripe.setOptions({
    publishableKey:
    'pk_test_XXXXX'
})

export default function PaymentScreen({navigation}) {
    const [ccNumber, setCCNumber] = useState('')
    const [expDate, setExpDate] = useState('')
    const [zipCode, setZipCode] = useState('')
    const [cvv, setCvv] = useState('')
    const [ loading, setLoading] = useState(false)
    const [token, setToken] = useState(null)

   const onPaymentPress = async () => {
        if ( ccNumber && expDate && zipCode && cvv == null) {
            alert("All fields must be completed")
            return
        };
        const token = await stripe.paymentRequestWithCardForm({
            smsAutofillDisabled: true,
        requiredBillingAddressFields: 'full',
        prefilledInformation: {
          billingAddress: {
            name: 'Gunilla Haugeh',
            line1: 'Canary Place',
            line2: '3',
            city: 'Macon',
            state: 'Georgia',
            country: 'US',
            postalCode: '31217',
            email: 'ghaugeh0@printfriendly.com',
          },
        },
      })
    
        axios({
            method:'POST',
            url: 'https://us-central1-lvc2-73300.cloudfunctions.net/completePaymentWithStripe',
            data: {
                amount: 50000,
                currency:'usd',
                token: token
            },
        })
        .then(response => {
            console.log(response);
            loading:false
        })
        navigation.navigate('Products',{token})
            
    }

这是我的激活付款功能

 <TouchableOpacity
                        style={styles.button}
                        onPress={() => onPaymentPress()}>
                        <Text style={styles.buttonTitle}>Submit Payment</Text>
                    </TouchableOpacity>

我也正在使用Firebase存储数据 这是我的数据库Firebase后端

const stripe = require('stripe')('sk_test_XXXX)

exports.completePaymentWithStripe = functions.https.onRequest(
    (request,response) => {
        stripe.charges.create({
amount: request.body.amount,
currency: request.body.currency,
source: request.body.token.tokenId,
        })

        .then(charge => {
            response.send(charge)
            return null
        })
        .catch(error => {
            console.log(error)
        })
    }
)

0 个答案:

没有答案