-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/terminal api local unencrypted + readme (#1130)
* Add Terminal API local unencrypted class * Add Terminal API local unencrypted test and readme * remove copyright * remove ApiKeyAuthenticatedService from terminal local api as API key is not used in local communications * add imports to readme
- Loading branch information
Showing
4 changed files
with
265 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/adyen/service/TerminalLocalAPIUnencrypted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.adyen.service; | ||
|
||
import com.adyen.Client; | ||
import com.adyen.Service; | ||
import com.adyen.model.terminal.TerminalAPIRequest; | ||
import com.adyen.model.terminal.TerminalAPIResponse; | ||
import com.adyen.service.resource.terminal.local.LocalRequest; | ||
import com.adyen.terminal.serialization.TerminalAPIGsonBuilder; | ||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
/** | ||
* [UNENCRYPTED] Local Terminal Api. | ||
* Use this class (in TEST only) to experiment with the Local Terminal API separately | ||
* from the encryption implementation required for live payments. | ||
* <p> | ||
* Be sure to remove the encryption key details on the Customer Area as it will not work with encryption key details set up. | ||
*/ | ||
public class TerminalLocalAPIUnencrypted extends Service { | ||
|
||
private final LocalRequest localRequest; | ||
|
||
private final Gson terminalApiGson; | ||
|
||
public TerminalLocalAPIUnencrypted(Client client) { | ||
super(client); | ||
localRequest = new LocalRequest(this); | ||
terminalApiGson = TerminalAPIGsonBuilder.create(); | ||
} | ||
|
||
/** | ||
* Local Terminal API call | ||
* | ||
* @param terminalAPIRequest TerminalAPIRequest | ||
* @return TerminalAPIResponse | ||
* @throws Exception exception | ||
*/ | ||
public TerminalAPIResponse request(TerminalAPIRequest terminalAPIRequest) throws Exception { | ||
String jsonRequest = terminalApiGson.toJson(terminalAPIRequest); | ||
|
||
String jsonResponse = localRequest.request(jsonRequest); | ||
|
||
if (jsonResponse == null || jsonResponse.isEmpty() || "ok".equals(jsonResponse)) { | ||
return null; | ||
} | ||
|
||
return terminalApiGson.fromJson(jsonResponse, new TypeToken<TerminalAPIResponse>() { | ||
}.getType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters