Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Unofficial python Paypal API client with v1 and v2 endpoint support and strongly type hinted objects.
Currently developed API calls:
Developed based on the available documentation at the official Paypal API reference.
Install from PyPi using pip
pip install pypaypal
Sessions can be started by importing http module which supports different ways of authentication and session types.
You can start a session using the "for_token" method providing a valid access token object and a session mode (LIVE or SANDBOX), for example:
import json
from pypaypal.http import (
SessionMode,
PayPalToken,
session_from_token
)
token = PayPalToken.serialize(json.loads('A paypal OAuth token'))
# Live session from a token
live_session = session_from_token(
token=token,
session_mode= SessionMode.LIVE
)
# Sandbox session from a token
sandbox_session = session_from_token(
token=token,
session_mode= SessionMode.SANDBOX
)
Alternatively you can start a session by authenticating via the client library.
In order to start a session based on authentication you need to specify the following:
client: API client ID.
secret: API client secret.
auth_type: Which authorization type you'll use to communicate with the API. These can be:
BASIC: Using basic auth for all request.
TOKEN: Authenticate once and use a token and keep the session until the token expires.
REFRESHABLE: Mix of BASIC and TOKEN to limit the amount of times the credentials are send back and forth a network. basically you authenticate the first time and get a token and the process will refresh the token logging in again with the credentials for an specified amount of sessions.
mode: Session mode (LIVE or SANDBOX)
Python samples for each auth method.
from pypaypal.http import authenticate, SessionMode
session_mode = SessionMode.SANDBOX
# Starting a session with basic auth
basic_session = authenticate(client, secret, session_mode, AuthType.BASIC)
# Authenticate to start a session with a one time token
token_session = authenticate(client, secret, session_mode, AuthType.TOKEN)
# Starting a session with refreshable tokens (refreshing up to 3 times)
refresh_session = authenticate(
client,
secret,
session_mode,
AuthType.REFRESHABLE,
refresh_limit=3
)
After the session is stablished you can perform requests by importing the client library of your choice, all requests objects and calls are based on the official Paypal API reference.
Sample request
import json
from pypaypal.http import (
SessionMode,
PayPalToken,
session_from_token
)
from pypaypal.clients.orders import OrderClient
from pypaypal.entities.base import PaypalApiResponse
order_id = 'some id'
token = PayPalToken.serialize(json.loads('A paypal OAuth token'))
# Sandbox session from a token
sandbox_session = session_from_token(
token=token,
session_mode= SessionMode.SANDBOX
)
client = OrderClient.create(sandbox_session)
response: PaypalApiResponse = client.show_order_details(order_id)
FAQs
Paypal API integration supporting some v1 & most of the current v2 rest APIs calls
We found that pypaypal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.