forked from glim/rest-api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.py
45 lines (42 loc) · 1.17 KB
/
create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from paypalrestsdk import Payment
import logging
logging.basicConfig(level=logging.INFO)
# Payment
# A Payment Resource of type order; intent set as 'order'
payment = Payment({
"intent": "order",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://return.url",
"cancel_url": "http://cancel.url"
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "1.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}]
})
# Create Payment and return status
if payment.create():
print("Payment[%s] created successfully" % (payment.id))
# Redirect the user to given approval url
for link in payment.links:
if link.rel == "approval_url":
approval_url = str(link.href)
print("Redirect for approval: %s" % (approval_url))
else:
print("Error while creating payment:")
print(payment.error)