Reusable React components for Cashfree PG
npm install @cashfreepayments/pg-reactA React component library for integrating Cashfree Payment Gateway in your React applications.
1. Install the package
``bash`
npm install @cashfreepayments/pg-react
2. Import and set up the Cashfree component
3. Run your app and test the integration!
Card payment requires four components: CardNumber, CardHolder, CardExpiry and CardCVV. Optionally, you can include SaveInstrument to let users save their card.
`react
import React, { useState } from "react";
import {
Cashfree,
CardNumber,
CardHolder,
CardExpiry,
CardCVV,
SaveInstrument,
} from "@cashfreepayments/pg-react";
const App: React.FC = () => {
const [isComplete, setIsComplete] = useState(false);
const handlePay = () => {
alert("Payment processing...");
// Trigger your payment logic here
};
return (
onComplete={(status) => {
setIsComplete(status); // this is your local app state
}}
>
export default App;
`onComplete
4. Event Handling
The Cashfree component provides an callback to notify when all card inputs are valid and complete. Use this to enable your Pay button or trigger other actions.
5. Styling Components
Customize the appearance by passing a customStyle` object to the Cashfree component or individual components. This lets you override fonts, colors, borders, and other style properties to match your app's look.
1. Simple integration with Cashfree Payment Gateway
2. Modular React components: CardNumber, CardHolder, CardExpiry, CardCVV, and SaveInstrument
3. Customizable themes and styles
4. Built-in completeness state management with event callbacks
5. Supports saving card details for faster payments