Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ $ mvn clean compile
```

### Deploy to your own artifacts sever

Currently, the Datatrans Java SDK is not yet available on Maven Central (or something similar).
Thats why you manually need to deploy it to your own artifacts hosting solution.
That's why you manually need to deploy it to your own artifacts hosting solution.

```
# You might have to adjust your ~/.m2/settings.xml or add a <distributionManagement> section to the pom.xml
$ mvn deploy
```

## Using the Java SDK

Once deployed, add the following dependency:

### Maven users
Expand All @@ -41,6 +43,7 @@ compile "ch.datatrans:datatrans-java-sdk:2.0.15"
```

### Invoking the SDK

```java
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.sandbox.datatrans.com");
Expand All @@ -52,28 +55,26 @@ Basic.setPassword("password"); // your Datatrans server to server password

V1TransactionsApi transactionsApiInstance = new V1TransactionsApi(defaultClient);

AuthorizeRequest authorizeRequest = new AuthorizeRequest();
authorizeRequest.currency("CHF")
RedirectRequest redirectRequest = new RedirectRequest();
redirectRequest.successUrl("https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp")
.cancelUrl("https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp")
.errorUrl("https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp");

InitRequest initRequest = new InitRequest();
initRequest.currency("CHF")
.paymentMethods(List.of(InitRequest.PaymentMethodsEnum.VIS))
.redirect(redirectRequest)
.amount(100L)
.refno(String.valueOf(System.currentTimeMillis()));

CardAuthorizeRequest cardAuthorizeRequest = new CardAuthorizeRequest();

cardAuthorizeRequest.alias("AAABcH0Bq92s3kgAESIAAbGj5NIsAHWC")
.expiryMonth("12")
.expiryYear("21");

authorizeRequest.setCard(cardAuthorizeRequest);

try {
AuthorizeResponse result = transactionsApiInstance.authorize(authorizeRequest);
InitResponse result = transactionsApiInstance.init(initRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling V1AliasesApi#aliasesConvert");
System.err.println("Exception when calling V1TransactionsApi#init");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
```

16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<gson-fire-version>1.8.5</gson-fire-version>
<swagger-core-version>1.6.2</swagger-core-version>
<okhttp-version>4.9.1</okhttp-version>
<gson-version>2.8.6</gson-version>
<okhttp-version>4.12.0</okhttp-version>
<gson-version>2.8.9</gson-version>
<commons-lang3-version>3.11</commons-lang3-version>
<javax-annotation-version>1.3.2</javax-annotation-version>
<junit-version>4.13.1</junit-version>
<junit-version>5.10.3</junit-version>
<jsr305.version>3.0.2</jsr305.version>
<datatrans-json-api.version>2.0.15</datatrans-json-api.version>
<openapi-generator-maven-plugin>5.1.0</openapi-generator-maven-plugin>
<datatrans-json-api.version>2.0.45</datatrans-json-api.version>
<openapi-generator-maven-plugin>7.7.0</openapi-generator-maven-plugin>
<default.package>ch.datatrans</default.package>
</properties>

Expand Down Expand Up @@ -70,8 +70,8 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -133,4 +133,4 @@
</build>


</project>
</project>
Loading