Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

primer-io/primer-sdk-react-native

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,230 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Set up the Universal Checkout

Step 1. Install the SDK

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.

Step 2. Initialize the SDK

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})},[]);}

Step 3. Generate a client token

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){// ...}};}

Step 4. Show Universal Checkout

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){// ...}};}

Full Code Snippet

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.

📚 License

Distributed under the MIT License. SeeLICENSE for more information.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors21


[8]ページ先頭

©2009-2026 Movatter.jp