This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rel-1.1.0' into stable
Merge in release branch for 1.1.0
- Loading branch information
Showing
14 changed files
with
336 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import paypalrestsdk.util as util | ||
from paypalrestsdk.resource import List, Find, Delete, Create, Update, Post, Resource | ||
from paypalrestsdk.api import default as default_api | ||
|
||
class Invoice(List, Find, Create, Delete, Update, Post): | ||
"""Invoice class wrapping the REST v1/invoices/invoice endpoint | ||
Usage:: | ||
>>> invoice_histroy = Invoice.all({"count": 5}) | ||
>>> invoice = Invoice.new({}) | ||
>>> invoice.create() # return True or False | ||
""" | ||
path = "v1/invoicing/invoices" | ||
|
||
def send(self): | ||
return self.post('send', {}, self) | ||
|
||
def remind(self, attributes): | ||
return self.post('remind', attributes, self) | ||
|
||
def cancel(self, attributes): | ||
return self.post('cancel', attributes, self) | ||
|
||
@classmethod | ||
def search(cls, params=None, api=None): | ||
api = api or default_api() | ||
params = params or {} | ||
|
||
url = util.join_url(cls.path, 'search') | ||
|
||
return Resource(api.post(url, params), api=api) | ||
|
||
Invoice.convert_resources['invoices'] = Invoice | ||
Invoice.convert_resources['invoice'] = Invoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.0.1" | ||
__version__ = "1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from test_helper import paypal, unittest | ||
from mock import patch, ANY | ||
|
||
class TestInvoice(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.invoice_attributes = { | ||
'merchant_info': { | ||
'email': 'ppaas_default@paypal.com' | ||
}, | ||
'billing_info': [ | ||
{ 'email': 'example@example.com' } | ||
], | ||
'items': [ | ||
{ | ||
'name': 'Sutures', | ||
'quantity': 100, | ||
'unit_price': { | ||
'currency': 'USD', | ||
'value': 5 | ||
} | ||
} | ||
] | ||
} | ||
self.invoice = paypal.Invoice(self.invoice_attributes) | ||
self.invoice.id = 'INV2-RUVR-ADWQ-H89Y-ABCD' | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_create(self, mock): | ||
invoice = paypal.Invoice(self.invoice_attributes) | ||
response = invoice.create() | ||
|
||
mock.assert_called_once_with(invoice.api,'v1/invoicing/invoices', self.invoice_attributes, {'PayPal-Request-Id' : invoice.request_id}, None) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.get', autospec=True) | ||
def test_find(self, mock): | ||
invoice = paypal.Invoice.find(self.invoice.id) | ||
|
||
mock.assert_called_once_with(self.invoice.api, 'v1/invoicing/invoices/'+self.invoice.id) | ||
self.assertTrue(isinstance(invoice, paypal.Invoice)) | ||
|
||
@patch('test_helper.paypal.Api.get', autospec=True) | ||
def test_all(self, mock): | ||
mock.return_value = {'total_count': 1, 'invoices': [self.invoice_attributes]} | ||
history = paypal.Invoice.all({'count': 1}) | ||
|
||
mock.assert_called_once_with(self.invoice.api, 'v1/invoicing/invoices?count=1') | ||
self.assertEqual(history.total_count, 1) | ||
self.assertTrue(isinstance(history.invoices[0], paypal.Invoice)) | ||
|
||
|
||
@patch('test_helper.paypal.Api.delete', autospec=True) | ||
def test_delete(self, mock): | ||
response = self.invoice.delete() | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/'+self.invoice.id) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.put', autospec=True) | ||
def test_update(self, mock): | ||
response = self.invoice.update(self.invoice_attributes) | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/'+self.invoice.id, self.invoice_attributes, {'PayPal-Request-Id' : self.invoice.request_id}, None) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_send(self, mock): | ||
response = self.invoice.send() | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/'+self.invoice.id+'/send', {}, {'PayPal-Request-Id' : ANY}) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_search(self, mock): | ||
search_attributes = { | ||
"start_invoice_date" : "2014-04-01 PST", | ||
"end_invoice_date" : "2013-04-03 PST", | ||
"page" : 1, | ||
"page_size" : 20, | ||
"total_count_required" : True | ||
} | ||
mock.return_value = {'total_count': 1, 'invoices': [self.invoice_attributes]} | ||
|
||
history = paypal.Invoice.search(search_attributes) | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/search', search_attributes) | ||
self.assertEqual(history.total_count, 1) | ||
self.assertTrue(isinstance(history.invoices[0], paypal.Invoice)) | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_remind(self, mock): | ||
remind_attributes = { | ||
'subject': 'Past due', | ||
'note': 'Please pay soon', | ||
'send_to_merchant': True | ||
} | ||
|
||
response = self.invoice.remind(remind_attributes) | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/'+self.invoice.id+'/remind', remind_attributes, {'PayPal-Request-Id' : ANY}) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_cancel(self, mock): | ||
cancel_attributes = { | ||
'subject': 'Past due', | ||
'note': 'Canceling invoice', | ||
'send_to_merchant': True, | ||
'send_to_payer': True | ||
} | ||
|
||
response = self.invoice.cancel(cancel_attributes) | ||
|
||
mock.assert_called_once_with(self.invoice.api,'v1/invoicing/invoices/'+self.invoice.id+'/cancel', cancel_attributes, {'PayPal-Request-Id' : ANY}) | ||
self.assertEqual(response, True) |