forked from glim/rest-api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_with_paypal_security_test.py
64 lines (56 loc) · 1.91 KB
/
create_with_paypal_security_test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Create Payment Using PayPal Sample against endpoint
# that only allows an acceptable highest TLS version
import paypalrestsdk as paypal
import logging
logging.basicConfig(level=logging.INFO)
paypal.configure({
"mode": "security-test-sandbox", # sandbox or live
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>"
})
# Payment
# A Payment Resource; create one using
# the above types and intent as 'sale'
payment = paypal.Payment({
"intent": "sale",
# Payer
# A resource representing a Payer that funds a payment
# Payment Method as 'paypal'
"payer": {
"payment_method": "paypal"},
# Redirect URLs
"redirect_urls": {
"return_url": "http://localhost:3000/payment/execute",
"cancel_url": "http://localhost:3000/"},
# Transaction
# A transaction defines the contract of a
# payment - what is the payment for and who
# is fulfilling it.
"transactions": [{
# ItemList
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "5.00",
"currency": "USD",
"quantity": 1}]},
# Amount
# Let's you specify a payment amount.
"amount": {
"total": "5.00",
"currency": "USD"},
"description": "This is the payment transaction 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.method == "REDIRECT":
# Convert to str to avoid google appengine unicode issue
# https://github.com/paypal/rest-api-sdk-python/pull/58
redirect_url = str(link.href)
print("Redirect for approval: %s" % (redirect_url))
else:
print("Error while creating payment:")
print(payment.error)