All Projects → recurly → react-recurly

recurly / react-recurly

Licence: MIT License
React components for Recurly.js

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to react-recurly

recurly-integration-examples
Examples to get you integrated with Recurly in any language.
Stars: ✭ 64 (+68.42%)
Mutual labels:  payments, recurly
react-admin-nest
React和Ant Design和 Nest.js 和 Mysql 构建的后台通用管理系统。持续更新。
Stars: ✭ 123 (+223.68%)
Mutual labels:  react-components
react-components
Shared React components for the Zopa projects.
Stars: ✭ 39 (+2.63%)
Mutual labels:  react-components
react-multiversal
React components that works everywhere (iOS, Android, Web, Node)
Stars: ✭ 43 (+13.16%)
Mutual labels:  react-components
MERN-BUS-APP
This is a MFRP (My first Real Project) assigned to me during my internship at Cognizant. Made with MERN Stack technology.
Stars: ✭ 92 (+142.11%)
Mutual labels:  react-components
clarity-react
React Components for VMware Clarity UI and Clarity Design
Stars: ✭ 33 (-13.16%)
Mutual labels:  react-components
card-validator
Card validation helpers for payment forms.
Stars: ✭ 22 (-42.11%)
Mutual labels:  payments
how-react-hooks-work
Understand how React-hook really behaves, once and for all!
Stars: ✭ 73 (+92.11%)
Mutual labels:  react-components
MetFlix
A Movie app demo. Like NetFlix ❤️
Stars: ✭ 50 (+31.58%)
Mutual labels:  react-components
design-system
A resource for creating user interfaces based on brand, UX, and dev principles
Stars: ✭ 17 (-55.26%)
Mutual labels:  react-components
light-ui
A lightly React UI library
Stars: ✭ 38 (+0%)
Mutual labels:  react-components
adyen-dotnet-api-library
Adyen API Library for .NET
Stars: ✭ 69 (+81.58%)
Mutual labels:  payments
nextjs-admin-template
Free admin dashboard template based on Next.Js with @paljs/ui component package
Stars: ✭ 266 (+600%)
Mutual labels:  react-components
react-native-value-picker
Cross-Platform iOS(ish) style picker for react native.
Stars: ✭ 18 (-52.63%)
Mutual labels:  react-components
react-awesome-loaders
🚀 High quality, super responsive and completely customisable Loading Animations to insert into your website with single line of code.
Stars: ✭ 146 (+284.21%)
Mutual labels:  react-components
watson-speech-translator
Use Watson Speech to Text, Language Translator, and Text to Speech in a web app with React components
Stars: ✭ 66 (+73.68%)
Mutual labels:  react-components
React-Interview-Questions
During the last three years had a lot of react interview questions so i decided to collect them all in one place to help other have an idea of most asked react questions , so if you have any more questions feel free to make a pull request and add your question along with its answer .
Stars: ✭ 37 (-2.63%)
Mutual labels:  react-components
reactjs-portfolio
Welcome to my portfolio react.js repository page.
Stars: ✭ 109 (+186.84%)
Mutual labels:  react-components
react-image-resizer
react-image-resizer is a React component that resizes the image to be nice.
Stars: ✭ 29 (-23.68%)
Mutual labels:  react-components
guitar-editor
🎸 A portable guitar tabs editor 🎼 based on react.js, inspired by Markdown and LaTex.
Stars: ✭ 94 (+147.37%)
Mutual labels:  react-components

react-recurly · build status coverage contributor covenant

React components for Recurly.js

Documentation

Documentation & Reference

Recurly.js Documentation

Examples

Interactive Demo

A great way to get started is to try the interactive demo in our documentation, and look through the demo source on GitHub.

Installation

Install this package with npm

npm install @recurly/react-recurly

Then, include recurly.js in your application via our CDN.

<script src="https://js.recurly.com/v4/recurly.js"></script>
<!-- optional: include recurly.css -->
<link rel="stylesheet" href="https://js.recurly.com/v4/recurly.css">

Implementation Guide

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.

// app.js
import React from 'react';
import { RecurlyProvider } from '@recurly/react-recurly';

function App () {
  return (
    <RecurlyProvider publicKey="MY_PUBLIC_KEY" />
  );
}

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.

// app.js
import React from 'react';
import { RecurlyProvider, Elements } from '@recurly/react-recurly';
import { MyPaymentForm } from './my-payment-form';

function App () {
  return (
    <RecurlyProvider publicKey="MY_PUBLIC_KEY">
      <Elements>
        <MyPaymentForm />
      </Elements>
    </RecurlyProvider>
  );
}

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.

// my-payment-form.js
import React from 'react';
import { CardElement } from '@recurly/react-recurly';

export function MyPaymentForm (props) {
  return (
    <form>
      <input type="text" data-recurly="first_name" placeholder="First name" />
      <input type="text" data-recurly="last_name" placeholder="Last name" />
      <CardElement />
    </form>
  );
}

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.

// my-payment-form.js
import React from 'react';
import { CardElement, useRecurly } from '@recurly/react-recurly';

export function MyPaymentForm (props) {
  const formRef = React.useRef();
  const recurly = useRecurly();

  function handleSubmit (event) {
    event.preventDefault();
    recurly.token(formRef.current, (err, token) => {
      if (err) {
        // handle error
      } else {
        // save the token.id, and submit it to the Recurly API from your server
      }
    });
  }

  return (
    <form onSubmit={handleSubmit} ref={formRef}>
      <input type="text" data-recurly="first_name" placeholder="First name" />
      <input type="text" data-recurly="last_name" placeholder="Last name" />
      <CardElement />
    </form>
  );
}

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.

Additional Usage

React-recurly also includes a useCheckoutPricing hook for generating a pricing preview before checking out.

import { useCheckoutPricing, RecurlyProvider } from '@recurly/react-recurly';

function PricingPreview () {
  const initialPricingInput = {
    subscriptions: [
      {
        plan: 'my-plan'
      }
    ]
  };

  const [{ price, loading }, setCheckoutPricing] = useCheckoutPricing(initialPricingInput);

  if (!loading) {
    return <div>{price.now.subtotal}</div>
  };
};

export default function MyApp () {
  <RecurlyProvider>
    <PricingPreview />
  </RecurlyProvider>
};

For more details, see the useCheckoutPricing Documentation.

Additional resources

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].