-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8928cfa
commit a0a6fcf
Showing
3 changed files
with
57 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,14 +88,14 @@ public with sharing class XeroAccountingApi { | |
|
||
/** | ||
* @author Ben Edwards ([email protected]) | ||
* @description Method to return ALL contacts for your Xero environment | ||
* @return List of Xero Contact wrapper classes | ||
* @description Method to return ALL invoices for your Xero environment | ||
* @return List of Xero Invoice wrapper classes | ||
**/ | ||
public static List<XeroInvoice> getInvoices () { | ||
|
||
List<XeroInvoice> xeroInvoices = new List<XeroInvoice>(); | ||
|
||
// Execute the callout to the Contacts resource | ||
// Execute the callout to the Invoice resource | ||
HttpResponse response = XeroCalloutUtility.executeCallout('GET', 'Invoices', null); | ||
|
||
// If successful response | ||
|
@@ -113,6 +113,33 @@ public with sharing class XeroAccountingApi { | |
return xeroInvoices; | ||
} | ||
|
||
/** | ||
* @author Ben Edwards ([email protected]) | ||
* @description Method to return all invoices for a given Contact Id | ||
* @return List of Xero Invoice wrapper classes | ||
**/ | ||
public static List<XeroInvoice> getInvoicesForContact (String xeroContactId) { | ||
|
||
List<XeroInvoice> xeroInvoices = new List<XeroInvoice>(); | ||
|
||
// Execute the callout to the Invoice resource with the Contact ID filter | ||
HttpResponse response = XeroCalloutUtility.executeCallout('GET', 'Invoices?where=Contact.ContactID%20%3D%20Guid%28%22' + xeroContactId + '%22%29', null); | ||
|
||
// If successful response | ||
if (response.getStatusCode() == 200) { | ||
|
||
// Use the parser to convert the response into Xero objects | ||
xeroInvoices = XeroCalloutResponseParser.parseInvoices(response.getBody()); | ||
} | ||
else { | ||
|
||
// Raise error | ||
throw new XeroAccountingApiException(response.getStatusCode() + ': ' + response.getBody()); | ||
} | ||
|
||
return xeroInvoices; | ||
} | ||
|
||
/** | ||
* @author Ben Edwards ([email protected]) | ||
* @description Method to create an invoice in Xero. | ||
|
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 |
---|---|---|
|
@@ -132,8 +132,6 @@ public class XeroAccountingApiTest { | |
|
||
Test.stopTest(); | ||
|
||
system.debug('### ' + xeroInvoices); | ||
|
||
// Assert that a contact exists | ||
system.assertEquals( | ||
1, | ||
|
@@ -172,6 +170,31 @@ public class XeroAccountingApiTest { | |
Test.stopTest(); | ||
} | ||
|
||
/** | ||
* @author Ben Edwards ([email protected]) | ||
* @description Test a successful callout of the getInvoicesForContact() method | ||
**/ | ||
@isTest | ||
static void getInvoicesForContactSuccess() { | ||
|
||
// Set the Mock Class for the callout | ||
Test.setMock(HttpCalloutMock.class, getStaticMock(200, 'XeroInvoicesMock')); | ||
|
||
Test.startTest(); | ||
|
||
// Execute the callout | ||
List<XeroInvoice> xeroInvoices = XeroAccountingApi.getInvoicesForContact('ABC123'); | ||
|
||
Test.stopTest(); | ||
|
||
// Assert that a contact exists | ||
system.assertEquals( | ||
1, | ||
xeroInvoices.size(), | ||
'There should be one invoice returned from the callout' | ||
); | ||
} | ||
|
||
/** | ||
* @author Ben Edwards ([email protected]) | ||
* @description Test a successful callout of the createInvoice() method | ||
|
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