pay-decentral
v1.0.7
Published
PayDecentral PayDecentral is an easy-to-use npm package built on top of the @solana/pay SDK. It allows seamless integration of decentralized Solana payments into your web platform, with support for payment modals and user data retrieval.
Downloads
129
Readme
PayDecentral PayDecentral is an easy-to-use npm package built on top of the @solana/pay SDK. It allows seamless integration of decentralized Solana payments into your web platform, with support for payment modals and user data retrieval.
Table of Contents Installation Usage Features API Documentation Contributing License Changelog Installation To get started with PayDecentral, install the package via npm or yarn:
Using npm: bash Copy code npm install pay-decentral Using yarn: bash Copy code yarn add pay-decentral Usage
- Import the Package Once installed, you can import the PaymentModalWithProvider and getUserData functions from the package:
javascript Copy code import { PaymentModalWithProvider, getUserData } from 'pay-decentral'; 2. Initialize the Payment Modal The PaymentModalWithProvider component allows you to display a payment modal to your users. You need to provide it with necessary props like subscriptionPlans, developerWallet, and developerApiKey.
javascript Copy code import { useState, useEffect } from 'react'; import { PaymentModalWithProvider, getUserData } from 'pay-decentral';
const Docs = () => { const [isOpen, setIsOpen] = useState(false); const [developerWallet, setDeveloperWallet] = useState('YourSolanaWalletAddress'); const [developerApiKey, setDeveloperApiKey] = useState('YourAPIKey');
const subscriptionPlans = [ { id: "plan1", name: "Basic Plan", amount: "0.001" }, { id: "plan2", name: "Pro Plan", amount: "0.002" }, { id: "plan3", name: "Premium Plan", amount: "0.003" }, ];
const handleOpenModal = () => { setIsOpen(true); };
const handleCloseModal = () => { setIsOpen(false); };
return ( Pay with Solana
<PaymentModalWithProvider
subscriptionPlans={subscriptionPlans}
userEmail="[email protected]"
developerApiKey={developerApiKey}
isOpen={isOpen}
onClose={handleCloseModal}
developerWallet={developerWallet}
onPaymentVerified={(planId, transactionSignature) => {
console.log(`Payment for ${planId} verified with transaction ${transactionSignature}`);
}}
/>
</div>
); };
export default Docs; 3. Get User Data You can use the getUserData function to fetch a user's payment status using your developer API key:
javascript Copy code useEffect(() => { const fetchUserData = async () => { try { const data = await getUserData('YourAPIKey'); console.log(data); // Logs user data like payment status } catch (err) { console.error("Error fetching user data: ", err); } };
fetchUserData(); }, []); Features Built on top of the @solana/pay SDK, offering a reliable and secure payment solution. Provides an easy-to-integrate modal for Solana payments. Includes functions to fetch user payment status with your developer API key. Supports multiple subscription plans and customizable payment amounts in SOL. Simple API to trigger payments and verify transactions. API Documentation PaymentModalWithProvider A React component that displays a payment modal and facilitates Solana payments.
Props: subscriptionPlans: An array of objects defining the available subscription plans. Each plan object should include an id, name, and amount.
Example:
javascript Copy code const subscriptionPlans = [ { id: 'plan1', name: 'Basic Plan', amount: '0.001' }, { id: 'plan2', name: 'Pro Plan', amount: '0.002' }, { id: 'plan3', name: 'Premium Plan', amount: '0.003' }, ]; userEmail: The email of the user making the payment (optional but recommended).
developerApiKey: Your developer API key for interacting with the PayDecentral API.
isOpen: A boolean that controls whether the modal is open or closed.
onClose: A callback function to close the modal when triggered.
developerWallet: The wallet address where funds will be sent after payment.
onPaymentVerified: A callback function triggered when a payment is successfully verified. This function receives two arguments: planId and transactionSignature.
getUserData A function used to fetch the payment status of your users.
Parameters: developerApiKey: Your developer API key to authenticate the request. Returns: An object containing the user's payment details, including the plan, transaction signature, and wallet address. javascript Copy code const userData = await getUserData(developerApiKey); console.log(userData); // Example output: { createdAt: "2024-11-30T18:12:19.550Z", email: "[email protected]", planId: "Basic", transactionSignature: "38J...sF1", walletAddress: "7t...nh" }
License This project is licensed under the MIT License - see the LICENSE file for details.
Changelog v1.0.0 (2024-12-01) Initial release of PayDecentral with basic Solana payment modal integration. Functionality to fetch user payment status with developer API key.