Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
unipayconnect
Advanced tools
<!-- **unipayconnect/unipayconnect** is a ✨ _special_ ✨ repository because its `README.md` (this file) appears on your GitHub profile.
UnipayConnect is a unified payment library designed to make handling payments with Stripe, PayPal, and Razorpay simple and efficient. It abstracts away the complexities of using multiple payment APIs and offers a straightforward interface for initializing payments, capturing payments, and verifying webhook events.
Before getting started, ensure you have the following:
You can install the UnipayConnect package using npm:
npm install unipayconnect
Create a .env file and add your API keys and connection details:
STRIPE_SECRET_KEY=<your-stripe-secret-key>
STRIPE_WEBHOOK_SECRET=<your-stripe-webhook-secret>
PAYPAL_CLIENT_ID=<your-paypal-client-id>
PAYPAL_CLIENT_SECRET=<your-paypal-secret>
NODE_ENV='sandbox'||'production' for paypal
RAZORPAY_KEY_ID=<your-razorpay-key-id>
RAZORPAY_KEY_SECRET=<your-razorpay-secret>
RAZORPAY_WEBHOOK_SECRET=<your-razorpay-webhook-secret>
PORT=<your-port>
JWT_SECRET='<your-jwt-secret>'
REACT_APP_API_URL=http://localhost
REACT_APP_RAZORPAY_KEY_ID=<your-razorpay-key-id>
REACT_APP_RAZORPAY_URL='https://checkout.razorpay.com/v1/checkout.js'
const unipayconnect = require('unipayconnect');
const session = await unipayconnect.createCheckoutSession({
price: 250, //total value of the cart
currency: "USD",
providers: ["razorpay", "stripe", "paypal"],
//Not Mandatory
name: "Avanish",
email: "avanishporwal01@gmail.com",
products: [
{
name: "Nike Tshirt",
price: 50,
quantity: 1,
},
{
name: "Puma shoes",
price: 100,
quantity: 2,
},
],
});
-Capture Payment After a successful checkout, capture the payment:
const paymentResult = await unipayconnect.capturePayment({
providerName: "razorpay", // Choose provider
paymentId: "pay_ABC123", // Payment ID from the provider
amount: 100, // Only required for Razorpay
});
providerName: Payment provider (required).
paymentId: The ID of the payment (from Stripe/PayPal/Razorpay).
amount: Total payment amount (required for Razorpay).
Verify Webhook Events Webhooks are crucial for receiving updates from payment providers. Here's how you verify the webhook data:
const isValid = unipayconnect.verifyWebhookPayload(
req.body, // Webhook payload received from the provider
req.headers["provider-name"] // Provider name ('stripe', 'paypal', 'razorpay')
// Signature from webhook headers
req.headers['paypal-transmission-sig']
|| req.headers['stripe-signature']
|| req.headers['X-Razorpay-Signature']
);
app.post("/api/v1/payments/create-checkout-session", async (req, res) => {
const { price, currency, providers, products } = req.body;
const sessionData = await unipayconnect.createCheckoutSession({
providerName: providers[0],
price,
currency,
products,
});
res.status(200).json(sessionData);
});
app.post("/api/v1/payments/capture", async (req, res) => {
const { providerName, paymentId, amount } = req.body;
const result = await unipayconnect.capturePayment({
providerName,
paymentId,
amount,
});
res.status(200).json(result);
});
app.post("/api/v1/webhooks", (req, res) => {
const providerName = req.headers["provider-name"];
const signature =
req.headers["stripe-signature"] || req.headers["paypal-transmission-sig"];
const verified = unipayconnect.verifyWebhookPayload(
providerName,
req.body,
signature
);
res.status(verified ? 200 : 400).json({ verified });
});
To install and set up the unipayconnect/packages/client
on your local machine, follow these steps:
Node.js: Ensure you have Node.js installed on your machine. You can download it from nodejs.org.
npm: npm is included with Node.js. You can check if it's installed by running the following command in your terminal:
npm -v
First, clone the unipayconnect repository from GitHub:
git clone https://github.com/yourusername/unipayconnect.git
Change your working directory to the client package:
cd unipayconnect/packages/client
Install the required dependencies using npm:
npm install
Create a .env file in the packages/client directory to store your API keys and any other environment variables required for your application:
touch .env
Add your configuration details:
REACT_APP_API_URL=http://localhost
REACT_APP_RAZORPAY_KEY_ID=<your-razorpay-key-id>
REACT_APP_RAZORPAY_URL='https://checkout.razorpay.com/v1/checkout.js'
Start the development server to see your client application in action:
npm start
The application should open in your default browser at http://localhost:3000.
For production, you might want to build the application by running:
npm run build
UnipayConnect lets you build a custom checkout page like Stripe's. Here’s an example of a form using React Hook Form and Tailwind CSS:
import { useForm } from "react-hook-form";
const CheckoutForm = ({ products, totalAmount }) => {
const { register, handleSubmit } = useForm();
const onSubmit = async (data) => {
console.log(data);
// Add your submit logic here
};
return (
<form onSubmit={handleSubmit(onSubmit)} className="checkout-form">
<div className="col-left">
<input {...register("name")} placeholder="Name" className="input" />
<input {...register("email")} placeholder="Email" className="input" />
<input {...register("amount")} placeholder="Amount" className="input" />
{/* Add more fields as necessary */}
</div>
<div className="col-right">
<h2>Order Summary</h2>
{products.map((product, index) => (
<div key={index}>
{product.name} - ${product.price * product.quantity}
</div>
))}
<div>Total: ${totalAmount}</div>
</div>
<button type="submit" className="submit-button">
Pay Now
</button>
</form>
);
};
<div>
<label>
<input {...register("provider")} type="radio" value="stripe" /> Stripe
</label>
<label>
<input {...register("provider")} type="radio" value="paypal" /> PayPal
</label>
<label>
<input {...register("provider")} type="radio" value="razorpay" /> Razorpay
</label>
</div>
UnipayConnect simplifies payments across multiple providers. Whether it's creating checkout sessions, capturing payments, or verifying webhooks, it provides an easy way to integrate and manage multiple payment gateways without getting into their complex APIs.
FAQs
<!-- **unipayconnect/unipayconnect** is a ✨ _special_ ✨ repository because its `README.md` (this file) appears on your GitHub profile.
The npm package unipayconnect receives a total of 1 weekly downloads. As such, unipayconnect popularity was classified as not popular.
We found that unipayconnect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.