Skip to content

Commit

Permalink
Methods for PeppolBillingApi to find country identifier of supplier a…
Browse files Browse the repository at this point in the history
…nd customer party

These values can be useful for mandatory header property COUNTRY_C1 and corresponding
PEPPOL End User and Transmission report
  • Loading branch information
hermanwh committed Jan 8, 2024
1 parent 0b9b98d commit a1fd0cb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public boolean isInvoice() {
return false;
}

public String getSupplierCountryIdentifier() {
return (String) ((Document) this.object).find("AccountingSupplierParty", "Party", "PostalAddress", "Country", "IdentificationCode").single().children().get(0).text();
}

public String getCustomerCountryIdentifier() {
return (String) ((Document) this.object).find("AccountingCustomerParty", "Party", "PostalAddress", "Country", "IdentificationCode").single().children().get(0).text();
}

public String prettyPrint() {
return XML_FIRST_LINE + (this.object instanceof BillingCommon ? ((BillingCommon) this.object).xmlRoot() : ((Document) this.object).getRootElement()).toIndentedXML();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) Posten Norge AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package peppol.bis.invoice3.api;

import org.eaxy.Document;
import org.eaxy.Xml;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class PeppolBillingApiTest {

@Test
public void test() throws IOException {
try (InputStream inputStream = PeppolBillingApiTest.class.getResourceAsStream("/norwegian-example.xml")) {
assertNotNull(inputStream);
Document document = Xml.xml(new String(inputStream.readAllBytes()));
PeppolBillingApi<Document> peppolBillingApi = new PeppolBillingApi<>(document);
assertEquals("NO", peppolBillingApi.getCustomerCountryIdentifier());
assertEquals("NO", peppolBillingApi.getSupplierCountryIdentifier());
}
}

}

0 comments on commit a1fd0cb

Please sign in to comment.