- Notifications
You must be signed in to change notification settings - Fork1
License
primer-io/primer-sdk-react-native
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Official React Native SDK plugin forPrimer
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.
Add the SDK package.
\# With yarnyarn add @primer-io/react-native\# With npmnpm i @primer-io/react-native --save
Once you are done, navigate to the /ios folder and run pod install.
Import the Primer SDK, construct your settings and call the SDK’s configure function.
import*asReactfrom'react';import{Primer,PrimerSettings,PrimerCheckoutData}from'@primer-io/react-native';constCheckoutScreen=(props:any)=>{constonCheckoutComplete=(checkoutData:PrimerCheckoutData)=>{// Perform an action based on the payment creation response// ex. show success screen, redirect to order confirmation view, etc.};React.useEffect(()=>{constsettings:PrimerSettings={onCheckoutComplete:onCheckoutComplete};Primer.configure(settings).then(()=>{// SDK is initialized sucessfully}).catch(err=>{// SDK failed to initialize})},[]);}
Note: Check our guide on how to set up the client sessionhere.
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.
constCheckoutScreen=(props:any)=>{// ...constonUniversalCheckoutButtonTapped=async()=>{try{// Make an API request to your backend to create a client session// and fetch a client token.constclientToken=awaitcreateClientSession(clientSessionRequestParams);}catch(err){// ...}};}
At this step, you should have a Client Token available. Call theshowUniversalCheckout(clientToken) function, with the Client Token (as shown below) to present Universal Checkout.
constCheckoutScreen=(props:any)=>{// ...constonUniversalCheckoutButtonTapped=async()=>{try{// ...// Present Universal CheckoutawaitPrimer.showUniversalCheckout(clientToken);}catch(err){// ...}};}
import*asReactfrom'react';import{Primer,PrimerSettings,PrimerCheckoutData}from'@primer-io/react-native';constCheckoutScreen=async(props:any)=>{constonCheckoutComplete=(checkoutData:PrimerCheckoutData)=>{// Show a success screen};constonUniversalCheckoutButtonTapped=async()=>{constsettings:PrimerSettings={onCheckoutComplete:onCheckoutComplete};// Configure the SDKawaitPrimer.configure(settings);// Ask your backend to create a client sessionconstclientToken=awaitcreateClientSession(clientSessionRequestParams);// Present Universal CheckoutawaitPrimer.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 ourdocs.
Distributed under the MIT License. SeeLICENSE for more information.
About
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.