Skip to content

Commit

Permalink
Fix issue with invoice sharable link
Browse files Browse the repository at this point in the history
  • Loading branch information
ej2 committed Aug 7, 2024
1 parent 6943dec commit f4e7661
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 113 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pytest-cov = "*"

[packages]
urllib3 = ">=2.1.0"
intuit-oauth = "==1.2.5"
intuit-oauth = "==1.2.6"
requests = ">=2.31.0"
requests_oauthlib = ">=1.3.1"
setuptools = "*"
303 changes: 208 additions & 95 deletions Pipfile.lock

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,23 @@ One example is `include=allowduplicatedocnum` on the Purchase object. You can ad

purchase.save(qb=self.qb_client, params={'include': 'allowduplicatedocnum'})

Other operations
Sharable Invoice Link
----------------
Add Sharable link for an invoice sent to external customers (minorversion must be set to 36 or greater):
To add a sharable link for an invoice, make sure the AllowOnlineCreditCardPayment is set to True and BillEmail is set to a invalid email address:

invoice.invoice_link = true
invoice.AllowOnlineCreditCardPayment = True
invoice.BillEmail = EmailAddress()
invoice.BillEmail.Address = '[email protected]'

When you query the invoice include the following params (minorversion must be set to 36 or greater):

Void an invoice:
invoice = Invoice.get(id, qb=self.qb_client, params={'include': 'invoiceLink'})


Void an invoice
----------------
Call `void` on any invoice with an Id:

invoice = Invoice()
invoice.Id = 7
invoice.void(qb=client)
Expand Down
7 changes: 2 additions & 5 deletions quickbooks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
if request_id:
params['requestid'] = request_id

if self.invoice_link:
params['include'] = 'invoiceLink'

if not request_body:
request_body = {}

Expand Down Expand Up @@ -242,9 +239,9 @@ def process_request(self, request_type, url, headers="", params="", data=""):
return self.session.request(
request_type, url, headers=headers, params=params, data=data)

def get_single_object(self, qbbo, pk):
def get_single_object(self, qbbo, pk, params=None):
url = "{0}/company/{1}/{2}/{3}/".format(self.api_url, self.company_id, qbbo.lower(), pk)
result = self.get(url, {})
result = self.get(url, {}, params=params)

return result

Expand Down
4 changes: 2 additions & 2 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class ReadMixin(object):
qbo_json_object_name = ""

@classmethod
def get(cls, id, qb=None):
def get(cls, id, qb=None, params=None):
if not qb:
qb = QuickBooks()

json_data = qb.get_single_object(cls.qbo_object_name, pk=id)
json_data = qb.get_single_object(cls.qbo_object_name, pk=id, params=params)

if cls.qbo_json_object_name != '':
return cls.from_json(json_data[cls.qbo_json_object_name])
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
)

self.qb_client = QuickBooks(
minorversion=69,
minorversion=73,
auth_client=self.auth_client,
refresh_token=os.environ.get('REFRESH_TOKEN'),
company_id=os.environ.get('COMPANY_ID'),
Expand Down
46 changes: 42 additions & 4 deletions tests/integration/test_invoice.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from datetime import datetime

from quickbooks.objects.base import CustomerMemo
from quickbooks.objects.customer import Customer
from quickbooks.objects.detailline import SalesItemLine, SalesItemLineDetail
from quickbooks.objects.invoice import Invoice
from quickbooks.objects.item import Item
from quickbooks.objects.base import EmailAddress
from tests.integration.test_base import QuickbooksTestCase
import uuid

class InvoiceTest(QuickbooksTestCase):
def create_invoice(self, customer, request_id=None):
invoice = Invoice()

class InvoiceTest(QuickbooksTestCase):
def create_invoice_line(self):
line = SalesItemLine()
line.LineNum = 1
line.Description = "description"
Expand All @@ -18,7 +20,11 @@ def create_invoice(self, customer, request_id=None):
item = Item.all(max_results=1, qb=self.qb_client)[0]

line.SalesItemLineDetail.ItemRef = item.to_ref()
invoice.Line.append(line)
return line

def create_invoice(self, customer, request_id=None):
invoice = Invoice()
invoice.Line.append(self.create_invoice_line())

invoice.CustomerRef = customer.to_ref()

Expand Down Expand Up @@ -86,3 +92,35 @@ def test_void(self):
self.assertEqual(query_invoice.Balance, 0.0)
self.assertEqual(query_invoice.TotalAmt, 0.0)
self.assertIn('Voided', query_invoice.PrivateNote)

def test_invoice_link(self):
# Sharable link for the invoice sent to external customers.
# The link is generated only for invoices with online payment enabled and having a valid customer email address.
# Include query param `include=invoiceLink` to get the link back on query response.

# Create test customer
customer_name = datetime.now().strftime('%d%H%M%S')
customer = Customer()
customer.DisplayName = customer_name
customer.save(qb=self.qb_client)

# Create an invoice with sharable link flags set
invoice = Invoice()
invoice.CustomerRef = customer.to_ref()

# BillEmail must be set for Sharable link to work!
invoice.BillEmail = EmailAddress()
invoice.BillEmail.Address = '[email protected]'

invoice.PrivateNote = 'This is a test invoice'
invoice.DueDate = '2024-12-31'
invoice.AllowOnlineCreditCardPayment = True
invoice.AllowOnlineACHPayment = True
invoice.Line.append(self.create_invoice_line())
invoice.save(qb=self.qb_client)

# You must set the params when doing a query for the invoice
query_invoice = Invoice.get(invoice.Id, qb=self.qb_client, params={'include': 'invoiceLink'})

self.assertIsNotNone(query_invoice.InvoiceLink)
self.assertIn('https', query_invoice.InvoiceLink)
1 change: 0 additions & 1 deletion tests/unit/objects/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_to_ref(self):
self.assertEqual(ref.name, 1) # should be DocNumber
self.assertEqual(ref.value, 2) # should be Id


class DeliveryInfoTests(unittest.TestCase):
def test_init(self):
info = DeliveryInfo()
Expand Down

0 comments on commit f4e7661

Please sign in to comment.