Socket
Socket
Sign inDemoInstall

@orjdev/paypal

Package Overview
Dependencies
8
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @orjdev/paypal

NPM Package For PayPal Rest API


Version published
Maintainers
1
Created

Readme

Source

PayPal Rest API

PayPal Rest API Package Built In TypeScript Using Axios.

Installation

Using NPM

  npm i @orjdev/paypal

Creating a client

import PayPalAPI from "@orjdev/paypal";

const client = new PayPalAPI.Client({
  mode: "sandbox",
  clientID: "",
  clientSecret: "",
});

Basics

// A Response Type Is
export type IResponse<T> = {
  error: INullable<IError>;
  data?: T;
};
// But it can be converted to "success or throw" like this:
let newFunction = client.successOrThrow(client.getOrder); // Types Inferring (:

Orders

Create

async function myFunction() {
  // using success or throw:
  let newFunction = client.successOrThrow(client.createOrder);
  try {
    let response = await newFunction({
      intent: "CAPTURE",
      purchase_units: [
        {
          amount: {
            currency_code: "USD",
            value: "1.00",
          },
        },
      ],
    });
    console.log(response);
  } catch (e) {
    console.log(e);
  }

  // using default
  let response = await client.createOrder({
    intent: "CAPTURE",
    purchase_units: [
      {
        amount: {
          currency_code: "USD",
          value: "1.00",
        },
      },
    ],
  });
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.data);
  }
}

Show Order Details

async function myFunction() {
  // using success or throw:
  let newFunction = client.successOrThrow(client.getOrder);
  try {
    let response = await newFunction("F2FSDFSF9DF");
    console.log(response);
  } catch (e) {
    console.log(e);
  }

  // using default
  let response = await client.getOrder("F2FSDFSF9DF");
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.data);
  }
}

Authorize Order

async function myFunction() {
  // using success or throw:
  let newFunction = client.successOrThrow(client.authorizeOrder);
  try {
    let response = await newFunction("F2FSDFSF9DF", {
      payment_source: {
        id: "F5Z1LXZ1Z1-X1",
        type: "BILLING_AGREEMENT",
      },
    });
    console.log(response);
  } catch (e) {
    console.log;
  }

  // using default
  let response = await client.authorizeOrder("F2FSDFSF9DF", {
    payment_source: {
      id: "F5Z1LXZ1Z1-X1",
      type: "BILLING_AGREEMENT",
    },
  });
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.data);
  }
}

Capture Order

async function myFunction() {
  // using success or throw:
  let newFunction = client.successOrThrow(client.captureOrder);
  try {
    let response = await newFunction("F2FSDFSF9DF", {
      payment_source: {
        id: "F5Z1LXZ1Z1-X1",
        type: "BILLING_AGREEMENT",
      },
    });
    console.log(response);
  } catch (e) {
    console.log;
  }

  // using default
  let response = await client.captureOrder("F2FSDFSF9DF", {
    payment_source: {
      id: "F5Z1LXZ1Z1-X1",
      type: "BILLING_AGREEMENT",
    },
  });
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.data);
  }
}

Confirm Order

async function myFunction() {
  // using success or throw:
  let newFunction = client.successOrThrow(client.confirmOrder);
  try {
    let response = await newFunction("F2FSDFSF9DF", {
      token: {
        id: "F5Z1LXZ1Z1-X1",
        type: "BILLING_AGREEMENT",
      },
    });
    console.log(response);
  } catch (e) {
    console.log;
  }

  // using default
  let response = await client.confirmOrder("F2FSDFSF9DF", {
    token: {
      id: "F5Z1LXZ1Z1-X1",
      type: "BILLING_AGREEMENT",
    },
  });
  if (response.error) {
    console.log(response.error);
  } else {
    console.log(response.data);
  }
}

FAQs

Last updated on 04 Aug 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc