Skip to content

Commit f9c4a51

Browse files
author
Andrew Throener
committed
Add samples README and comment to create invoice sample.
Add invoicing with pages sample Updates from review print updates Update
1 parent 6996b2d commit f9c4a51

File tree

6 files changed

+78
-9
lines changed

6 files changed

+78
-9
lines changed

samples/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Running Samples
2+
3+
## System Requirements
4+
PayPal SDK depends on the following system libraries:
5+
6+
* libssl-dev
7+
* libffi-dev
8+
9+
On Debian-based systems, run:
10+
11+
```sh
12+
apt-get install libssl-dev libffi-dev
13+
```
14+
# Installation
15+
```sh
16+
git clone https://github.com/paypal/PayPal-Python-SDK.git
17+
cd PayPal-Python-SDK
18+
pip install -e .
19+
```
20+
21+
## Configuration
22+
```sh
23+
export PAYPAL_MODE=sandbox # sandbox or live
24+
export PAYPAL_CLIENT_ID=YOUR_CLIENT_ID_FROM_PAYPAL # https://developer.paypal.com/docs/integration/admin/manage-apps/
25+
export PAYPAL_CLIENT_SECRET=YOUR_CLIENT_SECRET_FROM_PAYPAL # https://developer.paypal.com/docs/integration/admin/manage-apps/
26+
```
27+
28+
## Run Sample
29+
There may be additional comments in the sample file that you must complete before running.
30+
31+
```sh
32+
python samples/payment/create_with_paypal.py
33+
```

samples/invoice/cancel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from paypalrestsdk import Invoice
22
import logging
3+
import json
34
logging.basicConfig(level=logging.INFO)
45

5-
invoice = Invoice.find("INV2-CJL7-PF4G-BLQF-5FWG")
6+
invoice = Invoice.find("INV2-V2QW-LCUV-RNRL-AQUE")
67
options = {
78
"subject": "Past due",
89
"note": "Canceling invoice",
@@ -11,6 +12,6 @@
1112
}
1213

1314
if invoice.cancel(options): # return True or False
14-
print("Invoice[%s] cancel successfully" % (invoice.id))
15+
print(json.dumps(invoice.to_dict(), sort_keys=False, indent=4))
1516
else:
1617
print(invoice.error)

samples/invoice/create.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from paypalrestsdk import Invoice
22
import logging
3+
import json
34

45
logging.basicConfig(level=logging.INFO)
56

67
invoice = Invoice({
78
"merchant_info": {
8-
"email": "jaypatel512-facilitator@hotmail.com",
9+
"email": "jaypatel512-facilitator@hotmail.com", # You must change this to your sandbox email account
910
"first_name": "Dennis",
1011
"last_name": "Doctor",
1112
"business_name": "Medical Professionals, LLC",
@@ -61,6 +62,6 @@
6162
})
6263

6364
if invoice.create():
64-
print("Invoice[%s] created successfully" % (invoice.id))
65+
print(json.dumps(invoice.to_dict(), sort_keys=False, indent=4))
6566
else:
6667
print(invoice.error)

samples/invoice/get.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from paypalrestsdk import Invoice, ResourceNotFound
22
import logging
3+
import json
34
logging.basicConfig(level=logging.INFO)
45

56
try:
67
invoice = Invoice.find("INV2-9DRB-YTHU-2V9Q-7Q24")
7-
print("Got Invoice Details for Invoice[%s]" % (invoice.id))
8+
print(json.dumps(invoice.to_dict(), sort_keys=False, indent=4))
89

910
except ResourceNotFound as error:
1011
print("Invoice Not Found")

samples/invoice/search.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
from paypalrestsdk import Invoice
22
import logging
3+
import json
34
logging.basicConfig(level=logging.INFO)
45

6+
7+
58
# status should pass array with below enum values
69
# Allowed values: DRAFT, SENT, PAID, MARKED_AS_PAID, CANCELLED, REFUNDED, PARTIALLY_REFUNDED, MARKED_AS_REFUNDED.
710

811
options = {
912
"start_invoice_date": "2016-01-01 PST",
10-
"end_invoice_date": "2017-03-26 PST",
11-
"status": ["SENT", "DRAFT", "PAID", "CANCELLED"],
13+
"end_invoice_date": "2030-03-26 PST",
14+
"status": ["SENT", "DRAFT", "PAID", "CANCELLED"]
1215
}
1316
invoices = Invoice.search(options)
1417

1518
if invoices.success(): # return True or False
16-
print("Search Invoice[%s] successfully" % (invoices,))
19+
print(json.dumps(invoices.to_dict(), sort_keys=False, indent=4))
1720
else:
18-
print(invoices.error)
21+
print(invoices.error)

samples/invoice/search_pages.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from paypalrestsdk import Invoice
2+
import logging
3+
import json
4+
logging.basicConfig(level=logging.INFO)
5+
6+
7+
my_invoices = []
8+
page_size = 2
9+
10+
for i in range(3):
11+
12+
options = {
13+
"start_invoice_date": "2016-01-01 PST",
14+
"end_invoice_date": "2030-03-26 PST",
15+
"status": ["SENT", "DRAFT", "PAID", "CANCELLED"],
16+
"total_count_required": True,
17+
"page": i * page_size,
18+
"page_size": page_size
19+
}
20+
21+
invoices = Invoice.search(options)
22+
23+
if invoices.success(): # return True or False
24+
for inv in invoices.invoices:
25+
my_invoices.append(inv.id)
26+
else:
27+
print(invoices.error)
28+
29+
30+
print(json.dumps(my_invoices, sort_keys=False, indent=4))

0 commit comments

Comments
 (0)