npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cashonrails-react

v1.0.17

Published

A React library for seamless payment integration with Cashonrails.

Readme


Cashonrails React Components

Cashonrails Logo

A set of React components for seamlessly integrating the Cashonrails payment gateway into your application. This package provides an easy-to-use interface for processing payments, handling access codes, and creating customizable payment buttons.


Features

  • Easy Integration: Quickly add payment functionality to your React app.
  • Customizable Components: Tailor the look and feel of payment buttons to match your app’s design.
  • Secure Payments: Built on the secure Cashonrails payment gateway.
  • Flexible Configuration: Supports multiple currencies, customer details, and callbacks for payment success or cancellation.

Installation

Install the package using npm:

npm install cashonrails-react

Or using yarn:

yarn add cashonrails-react

Components

This package includes three main components:

  1. Checkout: For processing payments using the Cashonrails API.
  2. UseAccessCode: For processing payments with an access code.
  3. CheckoutButton: A customizable button for initiating payments.

Usage

1. Checkout Component

The Checkout component is used to process payments using the Cashonrails API. It dynamically loads the Cashonrails script and initializes the payment process.

Example

import React from 'react';
import { Checkout } from 'cashonrails-react';

const config = {
	api_key: 'your_api_key', // Replace with your Cashonrails API key
	amount: 1000, // Amount in the smallest currency unit (e.g., 1000 = $10.00)
	currency: 'USD', // Currency code (e.g., 'USD', 'EUR', 'NGN')
	customer: {
		email: "string",
		first_name: "string",
		last_name: "string",
		phone: "string",
	},
	callback_url: 'https://yourcallbackurl.com', // URL to redirect after payment
	onComplete: data => console.log('Payment completed:', data), // Callback for successful payment
	onCancel: data => console.log('Payment canceled:', data), // Callback for canceled payment
	debug: true, // Enable debug mode for testing
};

function App() {
	return <Checkout config={config} />;
}

export default App;

Props

| Prop | Type | Description | | -------- | -------- | ---------------------------------------------------------------------------------- | | config | Config | Configuration object for the payment. See Config Type for details. |


2. UseAccessCode Component

The UseAccessCode component is used to process payments with an access code. This is useful for scenarios where you already have a pre-generated access code.

Example

import React from 'react';
import { UseAccessCode } from 'cashonrails-react';

const config = {
	access_code: 'your_access_code', // Replace with your access code
	callback_url: 'https://yourcallbackurl.com', // URL to redirect after payment
	onComplete: data => console.log('Payment completed:', data), // Callback for successful payment
	onCancel: data => console.log('Payment canceled:', data), // Callback for canceled payment
	debug: true, // Enable debug mode for testing
};

function App() {
	return <UseAccessCode config={config} />;
}

export default App;

Props

| Prop | Type | Description | | -------- | ------------------ | ------------------------------------------------------------------------------------------------------ | | config | AccessCodeConfig | Configuration object for the payment. See AccessCodeConfig Type for details. |


3. CheckoutButton Component

The CheckoutButton component is a customizable button for initiating payments. It includes built-in loading states and hover effects.

Example

import React from 'react';
import { CheckoutButton } from 'cashonrails-react';

const config = {
	api_key: 'your_api_key', // Replace with your Cashonrails API key
	amount: 1000, // Amount in the smallest currency unit (e.g., 1000 = $10.00)
	currency: 'USD', // Currency code (e.g., 'USD', 'EUR', 'NGN')
	customer: {
		email: "string",
		first_name: "string",
		last_name: "string",
		phone: "string",
	},
	callback_url: 'https://yourcallbackurl.com', // URL to redirect after payment
	onComplete: data => console.log('Payment completed:', data), // Callback for successful payment
	onCancel: data => console.log('Payment canceled:', data), // Callback for canceled payment
};

function App() {
	return (
		<CheckoutButton
			config={config}
			buttonText="Pay Now"
			className="custom-button"
			style={{ backgroundColor: '#4CAF50' }}
			disabled={false}
			loadingText="Processing..."
			showHeader={true}
			headerText="Secure payment powered by Cashonrails"
		/>
	);
}

export default App;

Props

| Prop | Type | Default Value | Description | | ------------- | --------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------- | | config | Config | - | Configuration object for the payment. See Config Type for details. | | buttonText | string | 'Checkout Securely' | Text displayed on the button. | | className | string | '' | Additional CSS classes for the button. | | style | React.CSSProperties | {} | Inline styles for the button. | | disabled | boolean | false | Disable the button if true. | | loadingText | string | 'Processing...' | Text displayed while loading. | | showHeader | boolean | true | Show header if true. | | headerText | string | 'Secure payment powered by Cashonrails' | Header text. |


Types

Config Type

The Config type is used for the Checkout and CheckoutButton components.

interface Config {
	api_key: string; // Your Cashonrails API key
	amount: number; // Payment amount in the smallest currency unit (e.g., cents)
	currency: string; // Currency code (e.g., 'USD', 'EUR', 'NGN')
	customer: {
		email: string,
		first_name: string,
		last_name: string,
		phone: string,
	},
	callback_url?: string; // URL to redirect after payment
	onComplete?: (data: unknown) => void; // Callback for successful payment
	onCancel?: (data: unknown) => void; // Callback for canceled payment
	debug?: boolean; // Enable debug mode for testing
}

AccessCodeConfig Type

The AccessCodeConfig type is used for the UseAccessCode component.

interface AccessCodeConfig {
	access_code: string; // Your access code
	callback_url?: string; // URL to redirect after payment
	onComplete?: (data: unknown) => void; // Callback for successful payment
	onCancel?: (data: unknown) => void; // Callback for canceled payment
	debug?: boolean; // Enable debug mode for testing
}

FAQs

1. How do I get an API key?

You can obtain your API key from the Cashonrails Dashboard.

2. Can I customize the payment button?

Yes! The CheckoutButton component supports custom styles, classes, and text.

3. What currencies are supported?

Cashonrails supports multiple currencies, including USD, EUR, NGN, and more. Check the Cashonrails Documentation for a full list.


Support

For issues or feature requests, please open an issue on the GitHub repository.


License

This project is licensed under the MIT License. See the LICENSE file for details.