Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paypal-rest-api

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paypal-rest-api

paypal-rest-api

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-51.85%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status npm version Dependency Status devDependency Status MIT license

Introduction

This package is NOT supported by PayPal. The current PayPal Node SDK does not support the newest Javascript features. This package is intended to support the most cutting edge Javascript features.

Main Features

  • Written in Typescript and provide api types externally
  • Native Promise support using the request retry library
  • Retry failed api calls automatically using request retry library and paypal idempotency
  • Store access token expiration date and check before sending request. Currently the paypal sdk only updates the token if the request fails. This is more efficient.
  • Api Pre Validation using Joi Schemas. This improves efficiency by preventing invalid api calls from being submitted.
  • High Unit test coverage.
  • Provide request function to submit any URL. Future proofs in case helper method is not available.
  • Mocks for testing.

Installation

npm install --save paypal-rest-api

Configuration

The most up to date configuration options can be found on the IConfigureOptions interface

import { PayPalRestApi } from "../src";

const paypal = new PayPalRestApi({
    client_id: "",  // Your paypal client id
    client_secret": "", // Your paypal client secret
    mode: "sandbox", // "production" or "sandbox"
    requestOptions: {
        maxRetries: 2, // Sets the number of retries for 500 or Network timeout.  Set to 0 to disable.
        retryDelay: 5000, // Microseconds to wait until next retry.  5000 = 5 seconds
        // Any options from the following
        // https://github.com/FGRibreau/node-request-retry
        // https://github.com/request/request
    },
    validate: true, // Turns on prevalidation.  set to false if your validations are false negative.  Only available in execute method.
});

Usage

There are 2 different methods to make API Calls. For full examples refer to the examples folder.

Run an example

// "examples/ANY_FILE_IN_EXAMPLES_FOLDER"
npm run example -- examples/request

Execute Method

The execute method can be executed for any api call that has a helper method.

import { PayPalRestApi } from "../src";

const paypal = new PayPalRestApi({
    client_id: "YOUR_CLIENT_ID",
    client_secret": "YOUR_CLIENT_SECRET",
    mode: "sandbox",
});

paypal.execute("createInvoice", {
    body: {
        // https://developer.paypal.com/docs/api/invoicing/#invoices_create
        merchant_info: {
            business_name: "testy",
        },
    },
})
.then((response) => console.log)
.catch((err) => console.error);

Request Method

If a helper method does not exist you can always use the request method to directly execute an API call to an endpoint. You must specify the path and method.

import { PayPalRestApi } from "../src";

const paypal = new PayPalRestApi({
    client_id: "YOUR_CLIENT_ID",
    client_secret": "YOUR_CLIENT_SECRET",
    mode: "sandbox",
});

paypal.request("v1/invoicing/invoices/", {
    body: {
        merchant_info: {
            business_name: "testy",
        },
    },
    method: "POST",
})
.then((response) => console.log)
.catch((err) => console.error);

FAQs

Package last updated on 29 Aug 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc