npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tabby-react-native-sdk

v1.3.1

Published

Tabby React Native SDK

Downloads

3,010

Readme

Tabby React Native SDK

Requirements

The requirements is react-native-svg, react-native-webview. So you can integrate Tabby checkout for both Expo and pure React Native apps.

Installation

npm install tabby-react-native-sdk
or
yarn add tabby-react-native-sdk

On iOS please make sure you've added in your Info.plist

Feel free to edit descriptions according to your App

<key>NSCameraUsageDescription</key>
<string>This allows Tabby to take a photo</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This allows Tabby to select a photo</string>

On Android please make sure you've added in your AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

SDK usage

1. Init Tabby when your app starts (App.tsx or index.js)

import {Tabby} from 'tabby-react-native-sdk';

Tabby.setApiKey(__API_KEY_HERE__);

2. Build payment data

import { Tabby, Payment as TabbyPaymentData, TabbyCheckoutPayload } from "tabby-react-native-sdk";

// Keep in mind that some fields are optional! Here's the full example
const customerPayment: TabbyPaymentData = {
  amount: "340.00",
  currency: "AED",
  buyer: {
    email: "[email protected]",
    phone: "+971500000001",
    name: "Yazan Khalid",
    dob: "2019-08-24",
  },
  buyer_history: {
    registered_since: "2019-08-24T14:15:22Z",
    loyalty_level: 0,
    wishlist_count: 0,
    is_social_networks_connected: true,
    is_phone_number_verified: true,
    is_email_verified: true,
  },
  order: {
    tax_amount: "0.00",
    shipping_amount: "0.00",
    discount_amount: "0.00",
    reference_id: "#x-abc123",
    items: [
      {
        title: "Jersey",
        description: "Jersey",
        quantity: 1,
        unit_price: "10.00",
        reference_id: "uuid",
        product_url: "http://example.com",
        category: "clothes",
      },
    ],
  },
  order_history: [
    {
      purchased_at: "2019-08-24T14:15:22Z",
      amount: "0.00",
      payment_method: "card",
      status: "new",
      buyer: {
        email: "[email protected]",
        phone: "+971500000001",
        name: "Yazan Khalid",
        dob: "2019-08-24",
      },
      shipping_address: {
        city: "string",
        address: "string",
        zip: "string",
      },
      items: [
        {
          title: "string",
          description: "string",
          quantity: 1,
          unit_price: "0.00",
          reference_id: "string",
          product_url: "http://example.com",
          category: "string",
        },
      ],
    },
  ],
};

const myTestPayment: TabbyCheckoutPayload = { merchant_code: 'ae', lang: 'en', payment: customerPayment }

...
in your <CartScreen /> etc in useEffect
...

const createSession = async () => {
  try {
    const {sessionId, paymentId, availableProducts} = await Tabby.createSession(myTestPayment);
    console.log({sessionId})
    console.log({paymentId})
    console.log({availableProducts})
  } catch (error) {
    // Do something when Tabby checkout session POST request failed
  }
};

3. Launch Tabby checkout

const MyScreen = () => {
  const parseMessage = (msg: WebViewResult) => {
    switch (msg) {
      case 'authorized':
        // Do something else when Tabby authorized customer
        // probably navigation back to Home screen, refetching, etc.
        break;
      case 'rejected':
        // Do something else when Tabby rejected customer
        break;
      case 'close':
        // Do something else when customer closed Tabby checkout
        break;
      case 'expired':
        // Do something else when session expired
        // We strongly recommend to create new session here by calling
        // await Tabby.createSession(myTestPayment)
        break;
      default:
        break;
    }
  };

  return (
    <TabbyPaymentWebView
      onBack={
        // Your navigation back function
      }
      url={
        // Url from Tabby available product
      }
      onResult={parseMessage}
    />
  );
};

Useful types

type WebViewResult = 'close' | 'authorized' | 'rejected' | 'expired';

interface Payment {
  amount: string;
  currency: string;
  buyer: {
    email: string;
    phone: string;
    name?: string;
  };
}

type TabbyPurchaseType = 'installments';

export type Currency = 'AED' | 'SAR' | 'KWD' | 'BDH' | 'QAR';

interface TabbyCheckoutPayload {
  merchant_code: string; // 'ae',
  lang: string; // 'en' | 'ar,
  payment: Payment;
}

type ProductWebURL = {web_url: string};

interface CheckoutSession {
  id: string;
  configuration: {
    available_products: {
      installments?: ProductWebURL[];
    };
  };
  payment: {
    id: string;
  };
}

Checkout

Snippets usage

TabbyLimitSnippet

import React from 'react';
import {TabbyLimitSnippet} from 'tabby-react-native-sdk';
<TabbyLimitSnippet
  lang={'en'}
  price={'5000'} // TabbyLimitSnippet will only be shown if the price is over 5000
  priceTextStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  currencyTextStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  textStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  containerStyle={{
    flex: 1,
    // ...your other ViewStyle
  }}
  url={
    // Your promo wiget url
  }
  withCurrencyInArabic={
    // Optional props. Set true if you need to display currency in Arabic.
  }
/>;

Result

Snippet EN Snippet AR

TabbyCheckoutSnippet

import React from 'react';
import {TabbyCheckoutSnippet} from 'tabby-react-native-sdk';
<TabbyCheckoutSnippet
  lang={'en'}
  circleFillColor={['#3EEDBF', null, '#3EEDBF', null]}
  lineFillColor={['#3EEDBF', null, '#3EEDBF']}
  currency="AED"
  dateTextStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  price="340.00"
  priceTextStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  textStyle={{
    fontSize: 16,
    fontFamily: 'Courier',
    // ...your other TextStyle
  }}
  containerStyle={{
    elevation: 3,
    shadowColor: '#000000',
    // ...your other ViewStyle
  }}
  withCurrencyInArabic={
    // Optional props. Set true if you need to display currency in Arabic.
  }
/>;

Result

Snippet EN Snippet AR

TabbyProductPageSnippet

This snippet will only be shown if the price is greater than or equal to 10.

import React from 'react';
import {TabbyProductPageSnippet} from 'tabby-react-native-sdk';
<TabbyProductPageSnippet
  lang={'ar'}
  currency="AED"
  price="340.00"
  maxLimit={'5000.00'} // Optional props. TabbyProductPageSnippet will be hidden if the maxLimit is less than price.
  priceTextStyle={{
    fontSize: 12,
    fontFamily: 'Cairo',
    // ...your other TextStyle
  }}
  currencyTextStyle={{
    fontSize: 14,
    fontFamily: 'Inter',
    // ...your other TextStyle
  }}
  textStyle={{
    fontSize: 16,
    fontFamily: 'Courier',
    // ...your other TextStyle
  }}
  containerStyle={{
    elevation: 3,
    shadowColor: '#000000',
    // ...your other ViewStyle
  }}
  url={
    // Your promo wiget url
  }
  withCurrencyInArabic={
    // Optional props. Set true if you need to display currency in Arabic.
  }
/>;

Result

Snippet EN Snippet AR

TabbyPaymentWebView

import React from 'react';
import {TabbyPaymentWebView} from 'tabby-react-native-sdk';
<TabbyPaymentWebView
  onBack={
    // Your navigation back function
  }
  url={
    // Url from Tabby available product
  }
  onResult={
    // Your onResult function
  }
/>;

We have example app. Check this out.