How to use react-native-square-reader-sdk - 4 common examples

To help you get started, we’ve selected a few react-native-square-reader-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github square / react-native-square-reader-sdk / reader-sdk-react-native-quickstart / app / screens / CheckoutScreen.js View on Github external
// Optional for all following configuration
      skipReceipt: false,
      collectSignature: true,
      allowSplitTender: false,
      delayCapture: false,
      note: 'Hello 💳 💰 World!',
      tipSettings: {
        showCustomTipField: true,
        showSeparateTipScreen: false,
        tipPercentages: [15, 20, 30],
      },
      additionalPaymentTypes: ['cash', 'manual_card_entry', 'other'],
    };

    try {
      const checkoutResult = await startCheckoutAsync(checkoutParams);
      // Consume checkout result from here
      const currencyFormatter = this.props.globalize.getCurrencyFormatter(
        checkoutResult.totalMoney.currencyCode,
        { minimumFractionDigits: 0, maximumFractionDigits: 2 },
      );
      const formattedCurrency = currencyFormatter(checkoutResult.totalMoney.amount / 100);
      Alert.alert(`${formattedCurrency} Successfully Charged`, 'See the debugger console for transaction details. You can refund transactions from your Square Dashboard.');
      console.log(JSON.stringify(checkoutResult));
    } catch (ex) {
      let errorMessage = ex.message;
      switch (ex.code) {
        case CheckoutErrorCanceled:
          // Handle canceled transaction here
          console.log('transaction canceled.');
          break;
        case CheckoutErrorSdkNotAuthorized:
github square / react-native-square-reader-sdk / reader-sdk-react-native-quickstart / app / screens / SettingScreen.js View on Github external
async onStartReaderSettings() {
    const { navigate } = this.props.navigation;
    try {
      await startReaderSettingsAsync();
    } catch (ex) {
      let errorMessage = ex.message;
      switch (ex.code) {
        case ReaderSettingsErrorSdkNotAuthorized:
          // Handle reader settings not authorized
          navigate('Deauthorizing');
          break;
        case UsageError:
        default:
          if (__DEV__) {
            errorMessage += `\n\nDebug Message: ${ex.debugMessage}`;
            console.log(`${ex.code}:${ex.debugCode}:${ex.debugMessage}`);
          }
          Alert.alert('Error', errorMessage);
          break;
      }
github square / react-native-square-reader-sdk / reader-sdk-react-native-quickstart / app / screens / AuthorizingScreen.js View on Github external
async authorize(navigation) {
    const authCode = navigation.getParam('authCode', '');
    if (!authCode) {
      Alert.alert('Error: empty auth code');
      navigation.goBack();
      return;
    }
    try {
      await authorizeAsync(authCode);
      this.props.navigation.navigate('Checkout');
    } catch (ex) {
      let errorMessage = ex.message;
      switch (ex.code) {
        case AuthorizeErrorNoNetwork:
          // Remind connecting to network and retry
          Alert.alert(
            'Network error',
            ex.message,
            [
              { text: 'Retry', onPress: () => this.authorize(navigation) },
              { text: 'Cancel', onPress: () => navigation.navigate('Authorize'), style: 'cancel' },
            ],
          );
          break;
        case UsageError:
github square / react-native-square-reader-sdk / reader-sdk-react-native-quickstart / app / screens / CheckoutScreen.js View on Github external
async componentDidMount() {
    try {
      const authorizedLocation = await getAuthorizedLocationAsync();
      this.setState({ locationName: authorizedLocation.name });
    } catch (ex) {
      if (__DEV__) {
        Alert.alert(ex.debugCode, ex.debugMessage);
      } else {
        Alert.alert(ex.code, ex.message);
      }
    }
  }