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 🙏

© 2024 – Pkg Stats / Ryan Hefner

paypal-rest

v1.3.2-ALPHA

Published

SDK for REST PayPal API

Downloads

24

Readme

PayPal-REST

PayPal-REST is an unofficial implementation of the PayPal Rest API. This npm package is here to simplify the usage of this API.

Warning: For the moment, this package is in ALPHA, so it contains very few of the PayPal API functionalities, and has not yet been fully designed for professional use. You are therefore taking a risk by installing and using this package. Avoid using it in production!

Installation

You have to use your favorite package manager like npm, pnpm or yarn to install paypal-rest.

npm i paypal-rest@latest
pnpm add paypal-rest@latest
yarn add paypal-rest@latest

Some Examples:

Authentication:

import { config, auth } from 'paypal-rest';

config({
    client_id: '', // your PayPal CLIENT_ID
    client_secret: '', // your PayPal SECRET
    mode: 'sandbox', // 'sandbox' | 'live' ; default: sandbox
    auto_renew: false // Let or not the package reconnect you
});

await auth().catch(console.error);

Where I can obtain my credentials?

You can get your CLIENT_ID and your CLIENT_SECRET by following these task on the PayPal Docs:

  1. Select Log in to Dashboard and log in or sign up.
  2. Select Apps & Credentials.
  3. New accounts come with a Default Application in the REST API apps section. To create a new project, select Create App.
  4. Copy the client ID and client secret for your app.

Products:

Create, list, get details and update products!

import { product, ProductBuilder } from 'paypal-rest';

const newProduct = await product.create(
    new ProductBuilder()
        .setName('paypal-rest')
        .setType('DIGITAL')
        .setDescription('Buy me a coffee')
        .setHomeUrl('https://paypal.me/pioupia')
);

const listProduct = await product.list();
const paypalRestProduct = await product.get(listProduct.products?.[0].id!);

await paypalRestProduct
    .setDescription("Yes, I'll")
    .update();

Order:

import { order, ItemsBuilder, PurchaseUnitBuilder, CurrencyCodes } from 'paypal-rest';

// Create an item
const item = new ItemsBuilder()
            .setName('coffee')
            .setQuantity(1)
            .setUnitAmount({
                currency_code: CurrencyCodes.UnitedStatesDollar, // or, you can just type 'USD'
                value: 1
            });

// Create a purchase unit
const purchaseUnit = new PurchaseUnitBuilder()
    .setCurrency('USD')
    .setPrice(1)
    .setDescription("A coffee")
    .addItems(item);

// Create the order
const res = await order.create({
    purchase_units: [purchaseUnit]
}).catch(console.error);

// And then, when you have to capture this order:
await order.capture(res.id);