skip to navigation
skip to content

Not Logged In

paypalrestsdk 1.1.0

The PayPal REST SDK provides Python APIs to create, process and manage payments.

Latest Version: 1.11.0

Continuous integration status:

PyPI status:

The PayPal REST SDK provides Python APIs to create, process and manage payment.

Installation

Install using easy_install:

easy_install paypalrestsdk

Install using pip:

pip install paypalrestsdk

Configuration

import paypalrestsdk
paypalrestsdk.configure({
  "mode": "sandbox", # sandbox or live
  "client_id": "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
  "client_secret": "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM" })

Configure through environment variables:

export PAYPAL_MODE=sandbox   # sandbox or live
export PAYPAL_CLIENT_ID=EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
export PAYPAL_CLIENT_SECRET=EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM

Configure through a non-global API object

import paypalrestsdk
my_api = paypalrestsdk.Api({
  'mode': 'sandbox',
  'client_id': '...',
  'client_secret': '...'})

payment = paypalrestsdk.Payment({...}, api=my_api)

Create Payment

import paypalrestsdk
import logging

# Include Headers and Content by setting logging level to DEBUG, particularly for
# Paypal-Debug-Id if requesting PayPal Merchant Technical Services for support
logging.basicConfig(level=logging.INFO)

paypalrestsdk.configure({
  "mode": "sandbox", # sandbox or live
  "client_id": "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
  "client_secret": "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM" })

payment = paypalrestsdk.Payment({
  "intent": "sale",
  "payer": {
    "payment_method": "credit_card",
    "funding_instruments": [{
      "credit_card": {
        "type": "visa",
        "number": "4417119669820331",
        "expire_month": "11",
        "expire_year": "2018",
        "cvv2": "874",
        "first_name": "Joe",
        "last_name": "Shopper" }}]},
  "transactions": [{
    "item_list": {
      "items": [{
        "name": "item",
        "sku": "item",
        "price": "1.00",
        "currency": "USD",
        "quantity": 1 }]},
    "amount": {
      "total": "1.00",
      "currency": "USD" },
    "description": "This is the payment transaction description." }]})

if payment.create():
  print("Payment created successfully")
else:
  print(payment.error)

Get Payment details

# Fetch Payment
payment = paypalrestsdk.Payment.find("PAY-57363176S1057143SKE2HO3A")

# Get List of Payments
payment_history = paypalrestsdk.Payment.all({"count": 10})
payment_history.payments

Execute Payment

Only for Payment with payment_method as "paypal"

payment = paypalrestsdk.Payment.find("PAY-57363176S1057143SKE2HO3A")

if payment.execute({"payer_id": "DUFRQ8GWYMJXC"}):
  print("Payment execute successfully")
else:
  print(payment.error) # Error Hash

OpenID Connect

import paypalrestsdk
from paypalrestsdk.openid_connect import Tokeninfo, Userinfo

paypalrestsdk.configure({
  "mode": "sandbox",
  "client_id": "CLIENT_ID",
  "client_secret": "CLIENT_SECRET",
  "openid_redirect_uri": "http://example.com" })

# Generate login url
login_url = Tokeninfo.authorize_url({ "scope": "openid profile"})

# Create tokeninfo with Authorize code
tokeninfo = Tokeninfo.create("Replace with Authorize code")

# Refresh tokeninfo
tokeninfo = tokeninfo.refresh()

# Create tokeninfo with refresh_token
tokeninfo = Tokeninfo.create_with_refresh_token("Replace with refresh_token")

# Get userinfo
userinfo  = tokeninfo.userinfo()

# Get userinfo with access_token
userinfo  = Userinfo.get("Replace with access_token")

# Generate logout url
logout_url = tokeninfo.logout_url()

Future Payments

Check out this sample for executing future payments for a customer who has granted consent on a mobile device.

Invoicing

Create, send and manage invoices.

Create an invoice

from paypalrestsdk import Invoice

invoice = Invoice({
  'merchant_info': {
    "email": "default@merchant.com",
  },
  "billing_info": [{
    "email": "example@example.com"
  }],
  "items": [{
      "name": "Widgets",
      "quantity": 20,
      "unit_price": {
        "currency": "USD",
        "value": 2
      }
    }],
})

response = invoice.create()
print response

Check out more samples. The Invoicing REST APIs are fully supported by the sdk.

 
File Type Py Version Uploaded on Size
paypalrestsdk-1.1.0.tar.gz (md5) Source 2014-04-04 10KB
  • Downloads (All Versions):
  • 262 downloads in the last day
  • 991 downloads in the last week
  • 6733 downloads in the last month
  • Author: PayPal
  • Maintainer: PayPal
  • Home Page: https://github.com/paypal/rest-api-sdk-python
  • Keywords: paypal,rest,sdk,payments
  • License:
    The PayPal Python SDK is released under the following license:
    
    ::
    
        Copyright (c) 2013-2014 PAYPAL, INC.
    
        SDK LICENSE
    
        NOTICE TO USER:  PayPal, Inc. is providing the Software and Documentation for use under the terms of 
        this Agreement. Any use, reproduction, modification or distribution of the Software or Documentation, 
        or any derivatives or portions hereof, constitutes your acceptance of this Agreement.
    
        As used in this Agreement, "PayPal" means PayPal, Inc.  "Software" means the software code accompanying
        this agreement. "Documentation" means the documents, specifications and all other items accompanying 
        this Agreement other than the Software.   
    
        1.  LICENSE GRANT Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, 
        worldwide, royalty free license to use, reproduce, prepare derivative works from, publicly display, 
        publicly perform, distribute and sublicense the Software for any purpose, provided the copyright notice
        below appears in a conspicuous location within the source code of the distributed Software and this 
        license is distributed in the supporting documentation of the Software you distribute. Furthermore, 
        you must comply with all third party licenses in order to use the third party software contained in the 
        Software.
    
        Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free
        license to use, reproduce, publicly display, publicly perform, distribute and sublicense the Documentation 
        for any purpose.  You may not modify the Documentation.
    
        No title to the intellectual property in the Software or Documentation is transferred to you under the 
        terms of this Agreement. You do not acquire any rights to the Software or the Documentation except as 
        expressly set forth in this Agreement.
    
        If you choose to distribute the Software in a commercial product, you do so with the understanding that 
        you agree to defend, indemnify and hold harmless PayPal and its suppliers against any losses, damages and 
        costs arising from the claims, lawsuits or other legal actions arising out of such distribution.  You may 
        distribute the Software in object code form under your own license, provided that your license agreement:
    
        (a)     complies with the terms and conditions of this license agreement; 
    
        (b)     effectively disclaims all warranties and conditions, express or implied, on behalf of PayPal;
    
        (c)     effectively excludes all liability for damages on behalf of PayPal;
    
        (d)     states that any provisions that differ from this Agreement are offered by you alone and not PayPal; and
    
        (e)     states that the Software is available from you or PayPal and informs licensees how to obtain it in a 
        reasonable manner on or through a medium customarily used for software exchange.  
    
        2.  DISCLAIMER OF WARRANTY
        PAYPAL LICENSES THE SOFTWARE AND DOCUMENTATION TO YOU ONLY ON AN "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS 
        OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTIES OR CONDITIONS OF TITLE, 
        NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  PAYPAL MAKES NO WARRANTY THAT THE 
        SOFTWARE OR DOCUMENTATION WILL BE ERROR-FREE. Each user of the Software or Documentation is solely responsible 
        for determining the appropriateness of using and distributing the Software and Documentation and assumes all 
        risks associated with its exercise of rights under this Agreement, including but not limited to the risks and 
        costs of program errors, compliance with applicable laws, damage to or loss of data, programs, or equipment, 
        and unavailability or interruption of operations.  Use of the Software and Documentation is made with the 
        understanding that PayPal will not provide you with any technical or customer support or maintenance.  Some 
        states or jurisdictions do not allow the exclusion of implied warranties or limitations on how long an implied 
        warranty may last, so the above limitations may not apply to you.  To the extent permissible, any implied 
        warranties are limited to ninety (90) days.
    
    
        3.  LIMITATION OF LIABILITY
        PAYPAL AND ITS SUPPLIERS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING OUT OF THIS AGREEMENT OR FROM THE USE 
        OF THE SOFTWARE OR DOCUMENTATION.  IN NO EVENT WILL PAYPAL OR ITS SUPPLIERS BE LIABLE TO YOU OR ANY THIRD PARTY 
        FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES INCLUDING LOST PROFITS, LOST SAVINGS, 
        COSTS, FEES, OR EXPENSES OF ANY KIND ARISING OUT OF ANY PROVISION OF THIS AGREEMENT OR THE USE OR THE INABILITY 
        TO USE THE SOFTWARE OR DOCUMENTATION, HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
        STRICT LIABILITY OR TORT INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
        PAYPAL'S AGGREGATE LIABILITY AND THAT OF ITS SUPPLIERS UNDER OR IN CONNECTION WITH THIS AGREEMENT SHALL BE 
        LIMITED TO THE AMOUNT PAID BY YOU FOR THE SOFTWARE AND DOCUMENTATION. 
    
        4.  TRADEMARK USAGE
        PayPal is a trademark PayPal, Inc. in the United States and other countries.  Such trademarks may not be used 
        to endorse or promote any product unless expressly permitted under separate agreement with PayPal.  
    
        5.  TERM
        Your rights under this Agreement shall terminate if you fail to comply with any of the material  terms or 
        conditions of this Agreement and do not cure such failure in a reasonable period of time after becoming 
        aware of such noncompliance.  If all your rights under this Agreement terminate, you agree to cease use 
        and distribution of the Software and Documentation as soon as reasonably practicable. 
    
        6. GOVERNING LAW AND JURISDICTION. This Agreement is governed by the statutes and laws of the State of 
        California, without regard to the conflicts of law principles thereof.  If any part of this Agreement is 
        found void and unenforceable, it will not affect the validity of the balance of the Agreement, which shall 
        remain valid and enforceable according to its terms.  Any dispute arising out of or related to this Agreement 
        shall be brought in the courts of Santa Clara County, California, USA.
  • Categories
  • Package Index Owner: paypal
  • DOAP record: paypalrestsdk-1.1.0.xml