@@ -14,7 +14,7 @@ For those using maven, add the dependency and repository to your pom.xml
1414 <dependency>
1515 <groupId>com.xero</groupId>
1616 <artifactId>xero-java-sdk</artifactId>
17- <version>1.2 .0</version>
17+ <version>1.3 .0</version>
1818 </dependency>
1919
2020 <repositories>
@@ -412,6 +412,122 @@ List<Invoice> InvoiceList24hour = client.getInvoices(cal.getTime(),null,null);
412412System . out. println(" How many invoices modified in last 24 hours?: " + InvoiceList24hour . size());
413413```
414414
415+ ** BankFeed Endpoints**
416+
417+ Currently, BankFeed endpoints (FeedConnection & Statements) is limited beta financial institutions who are engaged with Xero. Once these endpoints have been enabled for your Xero Partner App, use the following pattern to make API calls.
418+
419+ ``` java
420+ import com.xero.api.* ;
421+ import com.xero.api.ApiClient ;
422+ import com.xero.models.bankfeeds.* ;
423+ import com.xero.models.bankfeeds.Statements ;
424+ import com.xero.models.bankfeeds.FeedConnection.AccountTypeEnum ;
425+
426+ import com.fasterxml.jackson.core.type.TypeReference ;
427+ import org.threeten.bp.LocalDate ;
428+
429+ // Get Xero API Resource - DEMONSTRATION ONLY get token from Cookie
430+ TokenStorage storage = new TokenStorage ();
431+ String token = storage. get(request," token" );
432+ String tokenSecret = storage. get(request," tokenSecret" );
433+
434+ // Initialize the BankFeedApi object and set the token & secret
435+ ApiClient apiClientForBankFeeds = new ApiClient (config. getBankFeedsUrl(),null ,null ,null );
436+ BankFeedsApi bankFeedsApi = new BankFeedsApi (apiClientForBankFeeds);
437+ bankFeedsApi. setOAuthToken(token, tokenSecret);
438+ Map<String , String > params = null ;
439+
440+ // Get ALL Feed Connections
441+ try {
442+ FeedConnections fc = bankFeedsApi. getFeedConnections(null );
443+ System . out. println(" Total Banks found: " + fc. getItems(). size());
444+ } catch (Exception e) {
445+ System . out. println(e. toString());
446+ }
447+
448+ // Get one Feed Connection
449+ try {
450+ FeedConnections fc = bankFeedsApi. getFeedConnections(null );
451+ FeedConnection oneFC = bankFeedsApi. getFeedConnection(" 123456789" ,null );
452+ System . out. println(" One Bank: " + oneFC. getAccountName());
453+ } catch (Exception e) {
454+ System . out. println(e. toString());
455+ }
456+
457+ try {
458+ FeedConnection newBank = new FeedConnection ();
459+ newBank. setAccountName(" SDK Bank " + SampleData . loadRandomNum());
460+ newBank. setAccountNumber(" 1234" + SampleData . loadRandomNum());
461+ newBank. setAccountType(AccountTypeEnum . BANK );
462+ newBank. setAccountToken(" foobar" + SampleData . loadRandomNum());
463+ newBank. setCurrency(" GBP" );
464+
465+ FeedConnections arrayFeedConnections = new FeedConnections ();
466+ arrayFeedConnections. addItemsItem(newBank);
467+
468+ FeedConnections fc1 = bankFeedsApi. createFeedConnections(arrayFeedConnections, null );
469+ System . out. println(" New Bank with status: " + fc1. getItems(). get(0 ). getStatus());
470+ } catch (Exception e) {
471+ System . out. println(e. toString());
472+ }
473+
474+
475+ // Create Bank Statement
476+ // Create One Statement
477+ try {
478+ Statements arrayOfStatements = new Statements ();
479+ Statement newStatement = new Statement ();
480+ LocalDate stDate = LocalDate . of(2018 , 9 , 01 );
481+ newStatement. setStartDate(stDate);
482+ LocalDate endDate = LocalDate . of(2018 , 9 , 15 );
483+ newStatement. endDate(endDate);
484+ StartBalance stBalance = new StartBalance ();
485+ stBalance. setAmount(" 100" );
486+ stBalance. setCreditDebitIndicator(CreditDebitIndicator . CREDIT );
487+ newStatement. setStartBalance(stBalance);
488+
489+ EndBalance endBalance = new EndBalance ();
490+ endBalance. setAmount(" 300" );
491+ endBalance. setCreditDebitIndicator(CreditDebitIndicator . CREDIT );
492+ newStatement. endBalance(endBalance);
493+
494+ FeedConnections fc = bankFeedsApi. getFeedConnections(null );
495+ newStatement. setFeedConnectionId(fc. getItems(). get(0 ). getId(). toString());
496+
497+ StatementLine newStatementLine = new StatementLine ();
498+ newStatementLine. setAmount(" 50" );
499+ newStatementLine. setChequeNumber(" 123" );
500+ newStatementLine. setDescription(" My new line" );
501+ newStatementLine. setCreditDebitIndicator(CreditDebitIndicator . CREDIT );
502+ newStatementLine. setReference(" Foobar" );
503+ newStatementLine. setPayeeName(" StarLord" );
504+ newStatementLine. setTransactionId(" 1234" );
505+ LocalDate postedDate = LocalDate . of(2017 , 9 , 05 );
506+ newStatementLine. setPostedDate(postedDate);
507+
508+ StatementLines arrayStatementLines = new StatementLines ();
509+ arrayStatementLines. add(newStatementLine);
510+
511+ newStatement. setStatementLines(arrayStatementLines);
512+ arrayOfStatements. addItemsItem(newStatement);
513+ Statements rStatements = bankFeedsApi. createStatements(arrayOfStatements, params);
514+
515+ System . out. println(" New Bank Statement Status: " + rStatements. getItems(). get(0 ). getStatus());
516+
517+ } catch (Exception e) {
518+ // Error throw is of type Statements - it contains an array of Errors.
519+ TypeReference<Statements > typeRef = new TypeReference<Statements > () {};
520+ Statements statementErrors = apiClientForBankFeeds. getObjectMapper(). readValue(e. getMessage(), typeRef);
521+ System . out. println(statementErrors. getItems(). get(0 ). getErrors(). get(0 ). getDetail());
522+ }
523+
524+
525+
526+
527+ ```
528+
529+
530+
415531** Exception Handling**
416532
417533Below is an example of how how to handle errors.
0 commit comments