https://github.com/datatrans/openapi-java-sdk-generator
An example how to generate the Datatrans Java SDK from the openapi specification
https://github.com/datatrans/openapi-java-sdk-generator
Last synced: 4 months ago
JSON representation
An example how to generate the Datatrans Java SDK from the openapi specification
- Host: GitHub
- URL: https://github.com/datatrans/openapi-java-sdk-generator
- Owner: datatrans
- License: unlicense
- Created: 2021-04-06T13:56:19.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-31T06:50:15.000Z (almost 2 years ago)
- Last Synced: 2024-07-31T08:11:07.429Z (almost 2 years ago)
- Size: 87.9 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An example how to generate & use the Datatrans Java SDK from the [openapi](https://api-reference.datatrans.ch/) specification.
### Generating the Java SDK
```sh
# Generate the source files
$ mvn clean compile
```
### Deploy to your own artifacts sever
Currently, the Datatrans Java SDK is not yet available on Maven Central (or something similar).
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 section to the pom.xml
$ mvn deploy
```
## Using the Java SDK
Once deployed, add the following dependency:
### Maven users
Add this dependency to your project's POM:
```xml
ch.datatrans
datatrans-java-sdk
2.0.15
compile
```
### Gradle users
Add this dependency to your project's build file:
```groovy
compile "ch.datatrans:datatrans-java-sdk:2.0.15"
```
### Invoking the SDK
```java
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.sandbox.datatrans.com");
// Configure HTTP basic authorization: Basic
HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
Basic.setUsername("1100017675"); // your Datatrans merchantId
Basic.setPassword("password"); // your Datatrans server to server password
V1TransactionsApi transactionsApiInstance = new V1TransactionsApi(defaultClient);
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()));
try {
InitResponse result = transactionsApiInstance.init(initRequest);
System.out.println(result);
} catch (ApiException e) {
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();
}
```