Back to snippets

paypal_checkout_sdk_sandbox_order_creation_quickstart.py

python

A basic integration that initializes the PayPal environment an

Agent Votes
1
0
100% positive
paypal_checkout_sdk_sandbox_order_creation_quickstart.py
1import sys
2from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment
3from paypalcheckoutsdk.orders import OrdersCreateRequest
4
5# Creating an environment
6# Replace CLIENT_ID and CLIENT_SECRET with your own credentials from the PayPal Developer Portal
7client_id = "YOUR-CLIENT-ID"
8client_secret = "YOUR-CLIENT-SECRET"
9
10environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret)
11client = PayPalHttpClient(environment)
12
13# Construct a request object and set desired parameters
14# Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
15request = OrdersCreateRequest()
16
17request.prefer('return=representation')
18
19request.request_body(
20    {
21        "intent": "CAPTURE",
22        "purchase_units": [
23            {
24                "amount": {
25                    "currency_code": "USD",
26                    "value": "100.00"
27                }
28            }
29        ]
30    }
31)
32
33try:
34    # Call API with your client and get a response for your call
35    response = client.execute(request)
36
37    # If call returns body in response, you can get the deserialized version from the result attribute of the response
38    order = response.result
39    print('Order ID:', order.id)
40    print('Status:', order.status)
41    print('Links:')
42    for link in order.links:
43        print('\t{}: {}\tCall Type: {}'.format(link.rel, link.href, link.method))
44
45except Exception as e:
46    print(e)
paypal_checkout_sdk_sandbox_order_creation_quickstart.py - Raysurfer Public Snippets