Skip to content

glim/rest-api-sdk-python

Repository files navigation

PayPal REST SDK Build Status

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

Installation

Install using pip:

pip install paypalrestsdk

From Github:

pip install git+https://github.com/paypal/rest-api-sdk-python.git

Configuration

importpaypalrestsdkpaypalrestsdk.configure( mode="sandbox", # sandbox or liveclient_id="EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM", client_secret="EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM")

Configure through environment variables:

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

Create Payment

importpaypalrestsdkimportlogginglogging.basicConfig(level=logging.INFO) paypalrestsdk.configure( mode="sandbox", # sandbox or liveclient_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." }]}) ifpayment.create(): print("Payment created successfully") else: print(payment.error)

Get Payment details

# Fetch Paymentpayment=paypalrestsdk.Payment.find("PAY-57363176S1057143SKE2HO3A") # Get List of Paymentspayment_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") ifpayment.execute({"payer_id": "DUFRQ8GWYMJXC"}): print("Payment execute successfully") else: print(payment.error) # Error Hash

For more samples github.com/paypal/rest-api-sdk-python/tree/master/samples

OpenID Connect

importpaypalrestsdkfrompaypalrestsdk.openid_connectimportTokeninfo, Userinfopaypalrestsdk.configure({"openid_client_id": "CLIENT_ID", 'openid_client_secret': "CLIENT_SECRET", 'openid_redirect_uri': "http://example.com" }) # Generate login urllogin_url=Tokeninfo.authorize_url({"scope": "openid profile"}) # Create tokeninfo with Authorize codetokeninfo=Tokeninfo.create("Replace with Authorize code") # Refresh tokeninfotokeninfo=tokeninfo.refresh() # Create tokeninfo with refresh_tokentokeninfo=Tokeninfo.create_with_refresh_token("Replace with refresh_token") # Get userinfouserinfo=tokeninfo.userinfo() # Get userinfo with access_tokenuserinfo=Userinfo.get("Replace with access_token") # Generate logout urllogout_url=tokeninfo.logout_url()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages