Gathering detailed insights and metrics for @recurly/react-recurly
Gathering detailed insights and metrics for @recurly/react-recurly
Gathering detailed insights and metrics for @recurly/react-recurly
Gathering detailed insights and metrics for @recurly/react-recurly
npm install @recurly/react-recurly
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
340 Commits
16 Forks
32 Watching
3 Branches
129 Contributors
Updated on 29 Oct 2024
JavaScript (84.8%)
TypeScript (10.71%)
Makefile (2.07%)
Shell (1.99%)
Dockerfile (0.42%)
Cumulative downloads
Total Downloads
Last day
-15.4%
6,027
Compared to previous day
Last week
3.2%
33,959
Compared to previous week
Last month
18%
140,330
Compared to previous month
Last year
45%
1,064,453
Compared to previous year
3
27
React components for Recurly.js
A great way to get started is to try the interactive demo in our documentation, and look through the demo source on GitHub.
Install this package with npm
1npm install @recurly/react-recurly
Then, include recurly.js in your application via our CDN.
1<script src="https://js.recurly.com/v4/recurly.js"></script> 2<!-- optional: include recurly.css --> 3<link rel="stylesheet" href="https://js.recurly.com/v4/recurly.css">
In this guide, we will cover the steps necessary to create a payment form that will submit your user's payment information to Recurly.
ℹ️ If you haven't yet, please review the Recurly.js documentation. This will give you a solid understanding of the total capabilities of the library before we begin implementing some of its features in React.
To start, we will use the <RecurlyProvider /> component to set our public key.
1// app.js 2import React from 'react'; 3import { RecurlyProvider } from '@recurly/react-recurly'; 4 5function App () { 6 return ( 7 <RecurlyProvider publicKey="MY_PUBLIC_KEY" /> 8 ); 9}
Now we can set up our payment form. For this, we will use Recurly.js Elements. First, we will use the <Elements /> component to group our Elements together. We'll also create a <MyPaymentForm />
component to contain our payment form.
1// app.js 2import React from 'react'; 3import { RecurlyProvider, Elements } from '@recurly/react-recurly'; 4import { MyPaymentForm } from './my-payment-form'; 5 6function App () { 7 return ( 8 <RecurlyProvider publicKey="MY_PUBLIC_KEY"> 9 <Elements> 10 <MyPaymentForm /> 11 </Elements> 12 </RecurlyProvider> 13 ); 14}
Within our new <MyPaymentForm />
component, we'll add a <CardElement /> which will render a secure card element. We'll also add inputs for our users' name. To let react-recurly know that we want to use these fields, we'll use a data-recurly
attribute. To include additional properties, see this billing fields table.
1// my-payment-form.js 2import React from 'react'; 3import { CardElement } from '@recurly/react-recurly'; 4 5export function MyPaymentForm (props) { 6 return ( 7 <form> 8 <input type="text" data-recurly="first_name" placeholder="First name" /> 9 <input type="text" data-recurly="last_name" placeholder="Last name" /> 10 <CardElement /> 11 </form> 12 ); 13}
We are now ready to add the final step: getting a token. When our users submit our form, we want to send their payment information to Recurly, which will return a token. We'll then keep this token to use in the Recurly API.
To accomplish this, we will use the useRecurly hook. This hook returns a Recurly.js instance, on which we will call recurly.token. Since this function expects a <form>
, we will create a React ref to pass to it.
1// my-payment-form.js 2import React from 'react'; 3import { CardElement, useRecurly } from '@recurly/react-recurly'; 4 5export function MyPaymentForm (props) { 6 const formRef = React.useRef(); 7 const recurly = useRecurly(); 8 9 function handleSubmit (event) { 10 event.preventDefault(); 11 recurly.token(formRef.current, (err, token) => { 12 if (err) { 13 // handle error 14 } else { 15 // save the token.id, and submit it to the Recurly API from your server 16 } 17 }); 18 } 19 20 return ( 21 <form onSubmit={handleSubmit} ref={formRef}> 22 <input type="text" data-recurly="first_name" placeholder="First name" /> 23 <input type="text" data-recurly="last_name" placeholder="Last name" /> 24 <CardElement /> 25 </form> 26 ); 27}
With that, we have implemented the essential components of a payment form using react-recurly. The tokens generated above may be used on any billing_info
object in the Recurly API.
React-recurly also includes a useCheckoutPricing hook for generating a pricing preview before checking out.
1import { useCheckoutPricing, RecurlyProvider } from '@recurly/react-recurly'; 2 3function PricingPreview () { 4 const initialPricingInput = { 5 subscriptions: [ 6 { 7 plan: 'my-plan' 8 } 9 ] 10 }; 11 12 const [{ price, loading }, setCheckoutPricing] = useCheckoutPricing(initialPricingInput); 13 14 if (!loading) { 15 return <div>{price.now.subtotal}</div> 16 }; 17}; 18 19export default function MyApp () { 20 <RecurlyProvider> 21 <PricingPreview /> 22 </RecurlyProvider> 23};
For more details, see the useCheckoutPricing Documentation.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 13/16 approved changesets -- score normalized to 8
Reason
SAST tool detected but not run on all commits
Details
Reason
2 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
34 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More