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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tiny-paypal

v3.0.0

Published

The missing PayPal tool for Node

Readme

Tiny PayPal

The missing PayPal tool for Node

PayPal has literally A TON of documentation, but little to none is targeted for NodeJS users.

This is a simple tool to create payments using the modern and elegant version of PayPal, solving hours of research, trial and error.

Install the module

yarn add tiny-paypal
# npm install tiny-paypal

Initialize it

const PayPal = require('tiny-paypal');

const CLIENT_ID = "your-client-id-here";
const CLIENT_SECRET = "your-client-secret-here";
const SUCCESS_CALLBACK_URL = "https://www.your-store.com/success";
const CANCEL_CALLBACK_URL = "https://www.your-store.com/checkout";

const defaults = {
	sandbox: true, 		// leave blank for production (default)
	currency: "EUR",	// by default "USD"
	successCallbackUrl: SUCCESS_CALLBACK_URL,
	cancelCallbackUrl: CANCEL_CALLBACK_URL
};

const paypal = new PayPal(CLIENT_ID, CLIENT_SECRET, defaults);

Create a simple payment

If you just want to charge an amount of money, you can invoke this method:

try {
	const payment = await paypal.createPayment({
		amount: 10,
		description: "My Shop Inc.",

		// optional fields

		shipping: 5,    // 0 by default
		discount: 4,    // 0 by default
		discountText: "Welcome discount", // "Discount" by default
		currency: "EUR",    // overrides the value by default
		successCallbackUrl: "https://www.your-store.com/payment-success",    // overrides the value set before
		cancelCallbackUrl: "https://www.your-store.com/payment-canceled"    // overrides the value set before
	});

	// Handle the result here
	console.log("Payment ID:", payment.id);
	console.log("Redirect URL", payment.redirect);  // Redirect your client's browser to this URL
	console.log("Info URL", payment.get);  // Get the payment info from this URL
	console.log("Execute URL", payment.execute);  // Execute the payment through this URL (payment approval is needed)
}
catch (error) {
	// Handle the error
	console.error(error.message);
}

Create a payment based on your cart

To display a list of the items on the PayPal screen, you can use TinyPaypal like this:

try {
	const payment = await paypal.createCartPayment({
		cart: [{
			name: "Product 1",
			description: "Product 1 description here", // optional
			price: 3,
			quantity: 10, // optional
			sku: '#1234'  // optional
		}, {
			name: "Product 2",
			description: "Product 2 description here", // optional
			price: 4,
			quantity: 5, // optional
			sku: '#1235' // optional
		}],
		description: "My Shop Inc.",

		// optional fields

		shipping: 5,
		discount: 4,
		discountText: "Welcome discount", // "Discount" by default
		currency: "EUR",    // overrides the value by default
		successCallbackUrl: "https://www.your-store.com/payment-success",    // overrides the value set before
		cancelCallbackUrl: "https://www.your-store.com/payment-canceled"    // overrides the value set before
	});

	// Handle the result here
	console.log("Payment ID:", payment.id);
	console.log("Redirect URL", payment.redirect);  // Redirect your client's browser to this URL
	console.log("Info URL", payment.get);  // Get the payment info from this URL
	console.log("Execute URL", payment.execute);  // Execute the payment through this URL (payment approval is needed)
}
catch (error) {
	// Handle the error
	console.error(error.message);
}

Redirect

Next, you need to redirect your client to result.redirect. When the client confirms the payment, PayPal will redirect the browser to the SUCCESS_CALLBACK_URL with three query string parameters: paymentId, token and PayerID.

Get these parameters and execute the payment

try {
	const result = await paypal.executePayment("payment-id", "token", "payer-id");
	console.log("Payment result:", result);
}
catch (error) {
	// Handle the error
	console.error(error.message);
}

This will log to the console something like:

Response: { id: 'PAY-1NA38651KW861730HK6HVNHQ',
	intent: 'sale',
	state: 'approved',
	cart: '9H784395YC168205K',
	payer: 
	{ payment_method: 'paypal',
		status: 'VERIFIED',
		payer_info: 
			{
				email: '[email protected]',
				first_name: 'Test',
				last_name: 'Buyer',
				payer_id: 'MEFWRPEQDM(2J',
				shipping_address: [Object],
				country_code: 'ES',
				billing_address: [Object] } },
	transactions: 
	[ { amount: [Object],
			payee: [Object],
			description: 'ACME Corporation Store',
			item_list: [Object],
			related_resources: [Object] } ],
	create_time: '2016-07-20T11:45:47Z',
	links: 
	[ { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-1NA38651KW861730HK6HVNHQ',
			rel: 'self',
			method: 'GET' 
		}
	]
}

Useful Documentation and tools