2.22.0 • Published 9 days ago

@primer-io/react-native v2.22.0

Weekly downloads
97
License
MIT
Repository
github
Last release
9 days ago

Official React Native SDK plugin for Primer

Note: This quick start guide addresses the platform-specific integration points only. As everything prior to that (e.g. creating a client token) is the same for all the guidelines.

Set up the Universal Checkout

Step 1. Install the SDK

Add the SDK package.

\# With yarn
yarn add @primer-io/react-native

\# With npm
npm i @primer-io/react-native --save

Once you are done, navigate to the \/ios folder and run pod install.

Step 2. Initialize the SDK

Import the Primer SDK, construct your settings and call the SDK’s configure function.

import * as React from 'react';
import {
  Primer,  
  PrimerSettings,
  PrimerCheckoutData
} from '@primer-io/react-native';

const CheckoutScreen = (props: any) => {

  const onCheckoutComplete = (checkoutData: PrimerCheckoutData) => {
    // Perform an action based on the payment creation response
    // ex. show success screen, redirect to order confirmation view, etc.
  };

  React.useEffect(() => {
    const settings: PrimerSettings = {
      onCheckoutComplete: onCheckoutComplete
    };

    Primer.configure(settings)
      .then(() => {
        // SDK is initialized sucessfully
      })
      .catch (err => {
        // SDK failed to initialize
      })
  }, []);
}

Step 3. Generate a client token

Note: Check our guide on how to set up the client session here.

Make an API call to your backend to fetch a Client Token. Here is a simple example of how it can be done from your component. Once successful store your Client Token for future use.

const CheckoutScreen = (props: any) => {

  // ...

  const onUniversalCheckoutButtonTapped = async () => {
    try {
      // Make an API request to your backend to create a client session
      // and fetch a client token.
      const clientToken = await createClientSession(clientSessionRequestParams);
    } catch (err) {
      // ...
    }
  };
}

Step 4. Show Universal Checkout

At this step, you should have a Client Token available. Call the showUniversalCheckout(clientToken) function, with the Client Token (as shown below) to present Universal Checkout.

const CheckoutScreen = (props: any) => {

  // ...

  const onUniversalCheckoutButtonTapped = async () => {
    try {
      // ...

      // Present Universal Checkout
      await Primer.showUniversalCheckout(clientToken);
    } catch (err) {
      // ...
    }
  };
}

Full Code Snippet

import * as React from 'react';
import {
  Primer,  
  PrimerSettings,
  PrimerCheckoutData
} from '@primer-io/react-native';

const CheckoutScreen = async (props: any) => {
  const onCheckoutComplete = (checkoutData: PrimerCheckoutData) => {
    // Show a success screen
  };
  
  const onUniversalCheckoutButtonTapped = async () => {
    const settings: PrimerSettings = {
      onCheckoutComplete: onCheckoutComplete
    };
    
    // Configure the SDK
    await Primer.configure(settings);
    
    // Ask your backend to create a client session
    const clientToken = await createClientSession(clientSessionRequestParams);
    
    // Present Universal Checkout
    await Primer.showUniversalCheckout(clientToken);
  };
}

You should now be able to see Universal Checkout! The user can now interact with Universal Checkout, and the SDK will create the payment. The payment’s data will be returned in the onCheckoutComplete callback configured in Step 2.

Note: For more info & help troubleshooting, check out our docs.

📚 License

Distributed under the MIT License. See LICENSE for more information.

2.22.0

9 days ago

2.21.1

20 days ago

2.21.0

27 days ago

2.20.0

3 months ago

2.19.2

3 months ago

2.19.1

4 months ago

2.19.0

4 months ago

2.17.0-rc.13

10 months ago

2.17.0-rc.12

10 months ago

2.17.0-rc.11

10 months ago

2.18.0

6 months ago

2.17.2

9 months ago

2.17.3

7 months ago

2.17.0

10 months ago

2.17.1

9 months ago

2.17.0-rc.10

11 months ago

2.17.0-rc.3

1 year ago

2.16.7

12 months ago

2.16.5

1 year ago

2.16.6

1 year ago

2.17.0-rc.6

1 year ago

2.17.0-rc.7

12 months ago

2.17.0-rc.4

1 year ago

2.17.0-rc.8

12 months ago

2.17.0-rc.9

11 months ago

2.17.0-rc.2

1 year ago

2.16.4

1 year ago

2.17.0-rc.1

1 year ago

2.16.2

1 year ago

2.11.0

2 years ago

2.15.0

1 year ago

2.15.1

1 year ago

2.14.3

2 years ago

2.14.4

1 year ago

2.14.1

2 years ago

2.14.2

2 years ago

2.14.0

2 years ago

2.13.2

2 years ago

2.13.0

2 years ago

2.13.1

2 years ago

2.12.0

2 years ago

2.16.0

1 year ago

2.12.1

2 years ago

2.12.2

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.8.1

2 years ago

2.8.0

2 years ago

0.17.0

2 years ago

2.10.0

2 years ago

2.7.0

2 years ago

2.5.1

2 years ago

2.9.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.4.0

2 years ago

2.0.1

2 years ago

2.3.0

2 years ago

2.1.1

2 years ago

2.5.0

2 years ago

2.1.0

2 years ago

0.16.1

2 years ago

0.16.2

2 years ago

0.15.4

2 years ago

0.15.5

2 years ago

0.15.8

2 years ago

0.13.0-beta.5

2 years ago

0.13.0-beta.3

2 years ago

2.0.0

2 years ago

0.13.0-beta.4

2 years ago

0.16.0

2 years ago

0.13.0-beta.2

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.12.4

2 years ago

0.12.5

2 years ago

0.12.0

2 years ago

0.12.1

2 years ago

0.12.2

2 years ago

0.12.3

2 years ago

0.13.0-beta.1

2 years ago

0.11.0

2 years ago

0.10.1

2 years ago

0.11.1

2 years ago

0.11.2

2 years ago

0.11.3

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.6.7

2 years ago

0.6.6

3 years ago

0.6.8

2 years ago

0.7.0-beta

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.4

3 years ago

0.5.3-0

3 years ago

0.5.4-beta.0

3 years ago

0.5.4-beta.1

3 years ago

0.5.4-beta.2

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago