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

@paypal/paypal-js

Package Overview
Dependencies
Maintainers
21
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paypal/paypal-js

Loading wrapper and TypeScript types for the PayPal JS SDK

  • 8.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
193K
increased by5.71%
Maintainers
21
Weekly downloads
 
Created

What is @paypal/paypal-js?

@paypal/paypal-js is an npm package that provides a client-side JavaScript SDK for integrating PayPal's payment services into web applications. It allows developers to easily add PayPal buttons, handle transactions, and manage payment flows with minimal setup.

What are @paypal/paypal-js's main functionalities?

Load PayPal Script

This feature allows you to load the PayPal JavaScript SDK dynamically. You need to provide your PayPal client ID, and the script will be loaded asynchronously.

import { loadScript } from '@paypal/paypal-js';

loadScript({ 'client-id': 'your-client-id' }).then((paypal) => {
  console.log('PayPal script loaded successfully');
}).catch((error) => {
  console.error('Failed to load PayPal script', error);
});

Render PayPal Buttons

This feature allows you to render PayPal buttons on your web page. You can customize the button's behavior, such as creating an order and handling the approval process.

import { loadScript } from '@paypal/paypal-js';

loadScript({ 'client-id': 'your-client-id' }).then((paypal) => {
  paypal.Buttons({
    createOrder: (data, actions) => {
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    },
    onApprove: (data, actions) => {
      return actions.order.capture().then((details) => {
        alert('Transaction completed by ' + details.payer.name.given_name);
      });
    }
  }).render('#paypal-button-container');
});

Handle Payment Transactions

This feature allows you to handle payment transactions, including creating orders, capturing payments, and handling errors during the transaction process.

import { loadScript } from '@paypal/paypal-js';

loadScript({ 'client-id': 'your-client-id' }).then((paypal) => {
  paypal.Buttons({
    createOrder: (data, actions) => {
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    },
    onApprove: (data, actions) => {
      return actions.order.capture().then((details) => {
        console.log('Transaction completed by ' + details.payer.name.given_name);
      });
    },
    onError: (err) => {
      console.error('An error occurred during the transaction', err);
    }
  }).render('#paypal-button-container');
});

Other packages similar to @paypal/paypal-js

Keywords

FAQs

Package last updated on 16 Sep 2024

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