From 0f80f66b765cafbf6d8d4d180b2a5e88464225d4 Mon Sep 17 00:00:00 2001 From: siddick Date: Fri, 4 Apr 2014 15:40:00 +0530 Subject: [PATCH] Added invoice samples --- samples/invoice/cancel.py | 17 +++++++++++ samples/invoice/create.py | 60 ++++++++++++++++++++++++++++++++++++++ samples/invoice/get.py | 11 +++++++ samples/invoice/get_all.py | 9 ++++++ samples/invoice/remind.py | 16 ++++++++++ samples/invoice/send.py | 11 +++++++ 6 files changed, 124 insertions(+) create mode 100644 samples/invoice/cancel.py create mode 100644 samples/invoice/create.py create mode 100644 samples/invoice/get.py create mode 100644 samples/invoice/get_all.py create mode 100644 samples/invoice/remind.py create mode 100644 samples/invoice/send.py diff --git a/samples/invoice/cancel.py b/samples/invoice/cancel.py new file mode 100644 index 00000000..6ce18cc0 --- /dev/null +++ b/samples/invoice/cancel.py @@ -0,0 +1,17 @@ +from paypalrestsdk import Invoice +import logging +logging.basicConfig(level=logging.INFO) + +invoice = Invoice.find("INV2-CJL7-PF4G-BLQF-5FWG") +options = { + "subject": "Past due", + "note": "Canceling invoice", + "send_to_merchant": True, + "send_to_payer": True +} + +if invoice.cancel(options): # return True or False + print("Invoice[%s] cancel successfully"%(invoice.id)) +else: + print(invoice.error) + diff --git a/samples/invoice/create.py b/samples/invoice/create.py new file mode 100644 index 00000000..41083189 --- /dev/null +++ b/samples/invoice/create.py @@ -0,0 +1,60 @@ +from paypalrestsdk import Invoice +import logging + +logging.basicConfig(level=logging.INFO) + +invoice = Invoice({ + "merchant_info": { + "email": "PPX.DevNet-facilitator@gmail.com", + "first_name": "Dennis", + "last_name": "Doctor", + "business_name": "Medical Professionals, LLC", + "phone": { + "country_code": "001", + "national_number": "5032141716" + }, + "address": { + "line1": "1234 Main St.", + "city": "Portland", + "state": "OR", + "postal_code": "97217", + "country_code": "US" + } + }, + "billing_info": [ { "email": "example@example.com" } ], + "items": [ + { + "name": "Sutures", + "quantity": 100, + "unit_price": { + "currency": "USD", + "value": 5 + } + } + ], + "note": "Medical Invoice 16 Jul, 2013 PST", + "payment_term": { + "term_type": "NET_45" + }, + "shipping_info": { + "first_name": "Sally", + "last_name": "Patient", + "business_name": "Not applicable", + "phone": { + "country_code": "001", + "national_number": "5039871234" + }, + "address": { + "line1": "1234 Broad St.", + "city": "Portland", + "state": "OR", + "postal_code": "97216", + "country_code": "US" + } + } +}) + +if invoice.create(): + print("Invoice[%s] created successfully"%(invoice.id)) +else: + print(invoice.error) diff --git a/samples/invoice/get.py b/samples/invoice/get.py new file mode 100644 index 00000000..dcfdf508 --- /dev/null +++ b/samples/invoice/get.py @@ -0,0 +1,11 @@ +from paypalrestsdk import Invoice, ResourceNotFound +import logging +logging.basicConfig(level=logging.INFO) + +try: + invoice = Invoice.find("INV2-9DRB-YTHU-2V9Q-7Q24") + print("Got Invoice Details for Invoice[%s]"%(invoice.id)) + +except ResourceNotFound as error: + print("Invoice Not Found") + diff --git a/samples/invoice/get_all.py b/samples/invoice/get_all.py new file mode 100644 index 00000000..297b077c --- /dev/null +++ b/samples/invoice/get_all.py @@ -0,0 +1,9 @@ +from paypalrestsdk import Invoice +import logging +logging.basicConfig(level=logging.INFO) + +history = Invoice.all({"page_size": 2}) + +print("List Invoice:") +for invoice in history.invoices: + print(" -> Invoice[%s]"%(invoice.id)) diff --git a/samples/invoice/remind.py b/samples/invoice/remind.py new file mode 100644 index 00000000..cc58a26f --- /dev/null +++ b/samples/invoice/remind.py @@ -0,0 +1,16 @@ +from paypalrestsdk import Invoice +import logging +logging.basicConfig(level=logging.INFO) + +invoice = Invoice.find("INV2-9CAH-K5G7-2JPL-G4B4") +options = { + "subject": "Past due", + "note": "Please pay soon", + "send_to_merchant": True +} + +if invoice.remind(options): # return True or False + print("Invoice[%s] remind successfully"%(invoice.id)) +else: + print(invoice.error) + diff --git a/samples/invoice/send.py b/samples/invoice/send.py new file mode 100644 index 00000000..28ad6e57 --- /dev/null +++ b/samples/invoice/send.py @@ -0,0 +1,11 @@ +from paypalrestsdk import Invoice +import logging +logging.basicConfig(level=logging.INFO) + +invoice = Invoice.find("INV2-9DRB-YTHU-2V9Q-7Q24") + +if invoice.send(): # return True or False + print("Invoice[%s] send successfully"%(invoice.id)) +else: + print(invoice.error) +