alanhhwong / react-native-braintree

A react native interface for integrating payments using Braintree's v.zero SDK
MIT License
112 stars 18 forks source link

Issues when view is cancelled or payment submitted #20

Open folivi opened 8 years ago

folivi commented 8 years ago

Hi, I came to a couple of issues using this package:

  1. Error message: "Paypal app switch is missing a returnURLScheme" this message appears when I click on the Paypal Checkout button.
  2. Possible unhandled Promise Rejection (id: 3) this message appears when I tap the 'Pay' button or 'Cancel' to dismiss the payment view.

What I'm I doing wrong here?

Please find my implementation below. I'm using ReactNative 0.25.1

import React, {Component} from 'react';
import {
  Text,
  View,
  Image,
  ScrollView,
  Animated,
  TouchableOpacity,
  TouchableHighlight,
  StyleSheet
} from 'react-native';

const BTClient = require('react-native-braintree');

export default class EventDetail extends Component {
  constructor(props) {
    super(props);
    this.state = { fadeAnim: new Animated.Value(0), // init opacity 0
    };
    this.showBTView = this.showBTView.bind(this);
  }

  componentDidMount(){
      Animated.timing(  // Uses easing functions
        this.state.fadeAnim,  // The value to drive
        {toValue: 1}  // Configuration
    ).start();
  }
  showBTView(){
      fetch('http://localhost:3000/get_token', {method: "GET"})
      .then((response) => response.json())
      .then((responseData) => {
        const clientToken = responseData.clientToken;
        BTClient.setup(clientToken);

        BTClient.showPaymentViewController(function(err, nonce) {
          //callback after the user completes (or cancels) the flow.
          //with the nonce, you can now pass it to your server to create a charge against the user's payment method
          fetch('http://localhost:3000/pay', {
            method: "POST",
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({payment_method_nonce: nonce})
          }).done();
        });

      }).done();

  }
  render() {
    return (
      <ScrollView>
          <TouchableHighlight onPress= {this.showBTView}>
              <View style={{height: 30, flex: 1, backgroundColor: 'red', justifyContent: 'center'}}>
                  <Text style={{textAlign: 'center',}}>Buy this</Text>
              </View>
          </TouchableHighlight>

      </ScrollView>
    );
  }

}

When I hit the button which triggers the payment View,

this is what shows in xcode:

2016-06-03 08:26:25.883 AppTemplate[62808:28893357] -canOpenURL: failed for URL: "com.paypal.ppclient.touch.v1://" - error: "This app is not allowed to query for scheme com.paypal.ppclient.touch.v1" 2016-06-03 08:26:25.884 AppTemplate[62808:28893357] -canOpenURL: failed for URL: "com.paypal.ppclient.touch.v2://" - error: "This app is not allowed to query for scheme com.paypal.ppclient.touch.v2" 2016-06-03 08:26:25.884 AppTemplate[62808:28893357] -canOpenURL: failed for URL: "com.venmo.touch.v2://x-callback-url/vzero/auth" - error: "This app is not allowed to query for scheme com.venmo.touch.v2"

Thanks for your help

AdamBrodzinski commented 8 years ago

@alanhhwong @folivi did you figure out how to work around this?

I'm hitting this now and it kind of looks like perhaps the one touch setup is required as it's enabled by default on the braintree lib. I don't really want one-touch support as it would increase complexity on my end.

Any info would be great!