Skip to content

Commit

Permalink
Fjerner alt som har med faktura og oppslag på bankkontonummer å gjøre.
Browse files Browse the repository at this point in the history
Både STNB 2.0 (faktura) og kvitteringstjenesten (oppslag på kontonummer) er avsluttet, så disse APIene skal ikke lenger være i bruk.
  • Loading branch information
martin-jackson committed Apr 14, 2023
1 parent 16ac832 commit 3ecce70
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 474 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

Online documentation: https://digipost.github.io/digipost-useragreements-api-client-java

API specification: https://github.com/digipost/invoice-api-specification

## Java Cryptographic Extension

To build and use the API client you need the *Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE*
Expand Down
67 changes: 67 additions & 0 deletions docs/_v3_x/1_introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Introduction
identifier: introduction
layout: default
---

This API makes it possible to access agreements between Digipost users and third parties, and followingly perform certain operations which the user has granted the third party.
For instance, the user may permit that certain information may be provided to a third party in order to receive a service. The user may also grant the sender access to documents
through an agreement. The agreement governs which documents the sender can access and what operations it can perform.


### Download

The library can be acquired from Maven Central Repository, using the dependency management tool of your choice.
For Maven you can use the following dependency:

```xml
<dependency>
<groupId>no.digipost</groupId>
<artifactId>digipost-useragreements-api-client-java</artifactId>
<version>2.0-delta</version>
</dependency>
```

### Prerequisites

The library requires *Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE* to be installed:
[www.oracle.com/technetwork/java/javase/downloads/index.html](http://www.oracle.com/technetwork/java/javase/downloads/index.html)

Starting from *Java 8 build 152* the unlimited strength cryptography policy files are bundled with the JDK/JRE, and may be enabled by setting
the security property `security.policy` to `"unlimited"`. How this is set depends on how you deploy your application, but if done early enough,
i.e. *before* the JCE framework is initialized, it can be set programatically like this:

```java
Security.setProperty("crypto.policy", "unlimited"); // only effective on Java 8 b152 or newer
```

More details are available in the [Java 8u152 Release Notes](http://www.oracle.com/technetwork/java/javase/8u152-relnotes-3850503.html#JDK-8157561).


### Instantiate and configure client

```java
InputStream key = getClass().getResourceAsStream("certificate.p12");

HttpHost proxy = new HttpHost("proxy.example.com", 8080, "http");

BrokerId brokerId = BrokerId.of(1234L);

DigipostUserAgreementsClient client = new DigipostUserAgreementsClient
.Builder(brokerId, key, "password")
.useProxy(proxy) //optional
.setHttpClientBuilder(HttpClientBuilder.create()) //optional
.serviceEndpoint(URI.create("https://api.digipost.no")) //optional
.build();
```

### Identify Digipost user

```java
final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final IdentificationResult identificationResult = client.identifyUser(senderId, userId);
boolean isDigipost = identificationResult.getResult() == IdentificationResultCode.DIGIPOST;
```

64 changes: 64 additions & 0 deletions docs/_v3_x/2_fetch_messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Messages sent to user
identifier: fetch_messages
layout: default
---

The agreement type `FETCH_MESSAGES` allows a sender to retrieve metadata for
documents that sender has previously sent to the user, that e.g. can be used to
present a synthetic inbox to the user. The metadata includes a deep-link the
user can use to access the document in Digipost.


### Create, read, update and delete agreement

```java
final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

//CreateAgreement
client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES));

//GetAgreement
final GetAgreementResult agreement = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);

//UpdateAgreement
client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES));

//DeleteAgreement
client.deleteAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);
```

### Get and verify agreement

```java
final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final GetAgreementResult agreementResult = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);
if (agreementResult.isSuccess()) {
final Agreement agreement = agreementResult.getAgreement();
} else {
switch (agreementResult.getFailedReason()) {
case UNKNOWN_USER: //User does not have a Digipost account
case NO_AGREEMENT: //No agreement exists for user
}
}
```

### Get documents

```java
final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final List<Document> previouslyDeliveredDocs = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES,
userId, GetDocumentsQuery.empty());

final ZoneId OSLO_ZONE = ZoneId.of("Europe/Oslo");
final List<Document> withinTimeWindow = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId,
GetDocumentsQuery.builder()
.deliveryTimeFrom(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, OSLO_ZONE))
.deliveryTimeTo(ZonedDateTime.now(OSLO_ZONE))
.build());
```
15 changes: 15 additions & 0 deletions docs/_v3_x/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
{% for dok in site.v3_x %}
{% if dok.identifier != 'index' %}
<section class="bs-docs-section">
<h1 id="{{ dok.identifier }}" class="page-header">{{ dok.title}}</h1>
{{dok.content}}
</section>
{% endif%}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ public Agreement(final AgreementType type, final UserId userId, final HashMap<St
this.attributes = attributes == null ? new HashMap<String, String>() : attributes;
}

public static Agreement createInvoiceBankAgreement(final UserId userId, final boolean smsNotification) {
HashMap<String, String> attribs = new HashMap<>();
attribs.put("sms-notification", String.valueOf(smsNotification));
return new Agreement(AgreementType.INVOICE_BANK, userId, attribs);
}

public AgreementType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

public final class AgreementType {

public static final AgreementType INVOICE_BANK = new AgreementType("invoice-bank");
public static final AgreementType BANK_ACCOUNT_NUMBER_FOR_RECEIPTS = new AgreementType("account-num-for-receipts");
public static final AgreementType FETCH_MESSAGES = new AgreementType("fetch-messages");

public static final String QUERY_PARAM_NAME = "agreement-type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import static java.time.Duration.ofMinutes;
import static java.time.format.DateTimeFormatter.ISO_DATE_TIME;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
import static no.digipost.api.useragreements.client.Headers.X_Digipost_UserId;
import static no.digipost.api.useragreements.client.response.ResponseUtils.mapOkResponseOrThrowException;
import static no.digipost.api.useragreements.client.response.ResponseUtils.unmarshallEntities;
Expand Down Expand Up @@ -104,15 +103,6 @@ public Documents getDocuments(final SenderId senderId, final AgreementType agree
}

private void setGetDocumentsQueryParams(final URIBuilder uriBuilder, final GetDocumentsQuery query) {
if (query.getInvoiceStatus() != null) {
uriBuilder.setParameter(InvoiceStatus.QUERY_PARAM_NAME, query.getInvoiceStatus().getStatus());
}
if (query.getInvoiceDueDateFrom() != null) {
uriBuilder.setParameter("invoice-due-date-from", query.getInvoiceDueDateFrom().format(ISO_LOCAL_DATE));
}
if (query.getInvoiceDueDateTo() != null) {
uriBuilder.setParameter("invoice-due-date-to", query.getInvoiceDueDateTo().format(ISO_LOCAL_DATE));
}
if (query.getDeliveryTimeFrom() != null) {
uriBuilder.setParameter("delivery-time-from", query.getDeliveryTimeFrom().format(ISO_DATE_TIME));
}
Expand All @@ -128,13 +118,6 @@ public Document getDocument(final SenderId senderId, final AgreementType agreeme
return executeHttpRequest(newGetRequest(uriBuilder, requestTrackingId), handler);
}

public void updateInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final InvoiceUpdate invoice, final String requestTrackingId, final ResponseHandler<Void> handler) {
URIBuilder uriBuilder = new URIBuilder(serviceEndpoint)
.setPath(userDocumentsPath(senderId) + "/" + documentId + "/invoice")
.setParameter(AgreementType.QUERY_PARAM_NAME, agreementType.getType());
executeHttpRequest(newPostRequest(uriBuilder, requestTrackingId, invoice), handler);
}

public DocumentCount getDocumentCount(final SenderId senderId, final AgreementType agreementType, final UserId userId, final GetDocumentsQuery query, final String requestTrackingId, final ResponseHandler<DocumentCount> handler) {
URIBuilder uriBuilder = new URIBuilder(serviceEndpoint)
.setPath(userDocumentsPath(senderId) + "/count")
Expand All @@ -151,14 +134,10 @@ public DocumentContent getDocumentContent(final SenderId senderId, final Agreeme
return executeHttpRequest(newGetRequest(uriBuilder, requestTrackingId), handler);
}

public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId, final AgreementType agreementType, final Boolean smsNotificationsEnabled, final String requestTrackingId) {
public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId, final AgreementType agreementType, final String requestTrackingId) {
URIBuilder uriBuilder = new URIBuilder(serviceEndpoint)
.setPath(userAgreementsPath(senderId) + "/agreement-owners")
.setParameter(AgreementType.QUERY_PARAM_NAME, agreementType.getType());
if (smsNotificationsEnabled != null) {
uriBuilder
.setParameter("invoice-sms-notification", smsNotificationsEnabled.toString());
}

HttpGet request = newGetRequest(uriBuilder, requestTrackingId);
request.setHeader(X_Digipost_UserId, brokerId.serialize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,6 @@ public Document getDocument(final SenderId senderId, final AgreementType agreeme
return apiService.getDocument(senderId, agreementType, documentId, requestTrackingId, singleJaxbEntityHandler(Document.class));
}

public void payInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final InvoicePayment invoicePayment) {
payInvoice(senderId, agreementType, documentId, invoicePayment, null);
}

public void payInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final InvoicePayment invoicePayment, final String requestTrackingId) {
apiService.updateInvoice(senderId, agreementType, documentId, invoicePayment.asInvoiceUpdate(), requestTrackingId, voidOkHandler());
}

public void updateInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final InvoiceUpdate invoiceUpdate) {
updateInvoice(senderId, agreementType, documentId, invoiceUpdate, null);
}

public void updateInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final InvoiceUpdate invoiceUpdate, final String requestTrackingId) {
apiService.updateInvoice(senderId, agreementType, documentId, invoiceUpdate, requestTrackingId, voidOkHandler());
}

public void deleteInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId) {
deleteInvoice(senderId, agreementType, documentId, null);
}

public void deleteInvoice(final SenderId senderId, final AgreementType agreementType, final long documentId, final String requestTrackingId) {
apiService.updateInvoice(senderId, agreementType, documentId, new InvoiceUpdate(InvoiceStatus.DELETED), requestTrackingId, voidOkHandler());
}

public long getDocumentCount(final SenderId senderId, final AgreementType agreementType, final UserId userId, final GetDocumentsQuery query) {
return getDocumentCount(senderId, agreementType, userId, query, null);
}
Expand All @@ -189,14 +165,10 @@ public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId se
return getAgreementOwners(senderId, agreementType, null);
}

public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId, final AgreementType agreementType, final Boolean smsNotificationEnabled) {
return getAgreementOwners(senderId, agreementType, smsNotificationEnabled, null);
}

public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId, final AgreementType agreementType, final Boolean smsNotificationEnabled, final String requestTrackingId) {
public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId, final AgreementType agreementType, final String requestTrackingId) {
Objects.requireNonNull(senderId, "senderId cannot be null");
Objects.requireNonNull(agreementType, "agreementType cannot be null");
return apiService.getAgreementOwners(senderId, agreementType, smsNotificationEnabled, requestTrackingId);
return apiService.getAgreementOwners(senderId, agreementType, requestTrackingId);
}

private ResponseHandler<Void> voidOkHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class Document {
@XmlElement(name = "sender-name")
private String senderName;
@XmlElement
private Invoice invoice;
@XmlElement
private String subject;
@XmlElement(name = "delivery-time")
private ZonedDateTime deliveryTime;
Expand All @@ -45,13 +43,8 @@ public class Document {

private Document() {}

public Document(final long id, final Invoice invoice) {
public Document(final long id) {
this.id = id;
this.invoice = invoice;
}

public Invoice getInvoice() {
return invoice;
}

public String getSenderName() {
Expand Down Expand Up @@ -87,7 +80,6 @@ public String toString() {
final StringBuilder sb = new StringBuilder("Document{");
sb.append("id=").append(id);
sb.append(", senderName='").append(senderName).append('\'');
sb.append(", invoice=").append(invoice);
sb.append(", authenticationLevel=").append(authenticationLevel);
sb.append(", deliveryTime=").append(deliveryTime);
sb.append('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public enum ErrorCode {
UNKNOWN_USER_ID,
NOT_AUTHORIZED,
AGREEMENT_NOT_FOUND,
INVOICE_ALREADY_PAID,
INVALID_INVOICE_STATUS,
INVALID_REQUEST_PARAMETER,
INVALID_FIELD,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,18 @@
package no.digipost.api.useragreements.client;


import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;

public class GetDocumentsQuery {
private final InvoiceStatus invoiceStatus;
private final LocalDate invoiceDueDateFrom;
private final LocalDate invoiceDueDateTo;
private final OffsetDateTime deliveryTimeFrom;
private final OffsetDateTime deliveryTimeTo;

private GetDocumentsQuery(final Builder builder) {
this.invoiceStatus = builder.invoiceStatus;
this.invoiceDueDateFrom = builder.invoiceDueDateFrom;
this.invoiceDueDateTo = builder.invoiceDueDateTo;
this.deliveryTimeFrom = builder.deliveryTimeFrom;
this.deliveryTimeTo = builder.deliveryTimeTo;
}

public InvoiceStatus getInvoiceStatus() {
return invoiceStatus;
}

public LocalDate getInvoiceDueDateFrom() {
return invoiceDueDateFrom;
}

public LocalDate getInvoiceDueDateTo() {
return invoiceDueDateTo;
}

public OffsetDateTime getDeliveryTimeFrom() {
return deliveryTimeFrom;
}
Expand All @@ -64,29 +45,11 @@ public static GetDocumentsQuery empty() {
}

public static class Builder {
private InvoiceStatus invoiceStatus;
private LocalDate invoiceDueDateFrom;
private LocalDate invoiceDueDateTo;
private OffsetDateTime deliveryTimeFrom;
private OffsetDateTime deliveryTimeTo;

private Builder() {}

public Builder invoiceStatus(final InvoiceStatus invoiceStatus) {
this.invoiceStatus = invoiceStatus;
return this;
}

public Builder invoiceDueDateFrom(final LocalDate invoiceDueDateFrom) {
this.invoiceDueDateFrom = invoiceDueDateFrom;
return this;
}

public Builder invoiceDueDateTo(final LocalDate invoiceDueDateTo) {
this.invoiceDueDateTo = invoiceDueDateTo;
return this;
}

public Builder deliveryTimeFrom(final OffsetDateTime deliveryTimeFrom) {
this.deliveryTimeFrom = deliveryTimeFrom;
return this;
Expand Down
Loading

0 comments on commit 3ecce70

Please sign in to comment.