-
Notifications
You must be signed in to change notification settings - Fork 146
Cloud device api #1568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gcatanese
wants to merge
26
commits into
main
Choose a base branch
from
cloud-device-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cloud device api #1568
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
bf840d6
Copy and adjust terminal models
gcatanese 253a752
Create CloudDevice service
gcatanese 2232c59
Add first test
gcatanese cc60347
Update models
gcatanese 1ffc7d3
Implement all endpoints and related tests
gcatanese 0dab88b
Add tests with Terminal
gcatanese 17aad3f
Ignore file with test configuration
gcatanese 830b4c5
Start implementing encryption
gcatanese 358e20a
Add sync encryption
gcatanese c690f6e
Encode and decode when necessary
gcatanese d77595f
Add async encryption and tests
gcatanese 4ba6efa
Support async with different response types
gcatanese e6a7c98
Test async
gcatanese 62c1295
Disable test with Terminal
gcatanese 05256d7
Add decryptNotification method
gcatanese 81228a8
Create separate README for Terminal and Cloud Device API
gcatanese 8ce39bc
Minor edit
gcatanese b9f5018
Tidy up tables
gcatanese 71ed4ba
Correct link
gcatanese 5644190
Update doc/CloudDeviceApi.md
gcatanese 63b959e
Update doc/CloudDeviceApi.md
gcatanese 317246b
Format code
gcatanese 15a6e88
Format code
gcatanese 25afe23
Exception handling with new CloudDeviceException
gcatanese aca2609
Cleanup exception handling and format code
gcatanese 7075537
Merge branch 'main' into cloud-device-api
gcatanese File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
| **/target/** | ||
| .DS_Store | ||
| .vscode | ||
|
|
||
| # test configuration | ||
| src/test/resources/config.properties | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,154 @@ | ||
| # Cloud Device API | ||
|
|
||
| The [Cloud Device API](https://docs.adyen.com/api-explorer/cloud-device-api/1/overview) is our solution to create best-in-class in-person payments integrations. | ||
|
|
||
| With the Cloud device API you can: | ||
|
|
||
| - send Terminal API requests to a cloud endpoint. You can use this communication method when it is not an option to send Terminal API requests over your local network directly to a payment terminal. | ||
| - check the cloud connection of a payment terminal or of a device used in a Mobile solution for in-person payments. | ||
|
|
||
| ## Benefits of the Cloud Device API | ||
|
|
||
| The Cloud Device API offers the following benefits: | ||
| - access to API logs in the Customer Area for troubleshooting errors | ||
| - using a version strategy for the API endpoints for controlled and safer rollouts | ||
| - improved reliability and security (OAuth support) | ||
|
|
||
| New features and products will be released exclusively on the Cloud Device API | ||
|
|
||
| ## Use the Cloud Device API | ||
|
|
||
| ### Setup | ||
|
|
||
| First you must initialise the Client **setting the closest** [Region](https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api/#cloud): | ||
| ``` java | ||
| // Import the required classes | ||
| import com.adyen.Client; | ||
| import com.adyen.enums.Environment; | ||
| import com.adyen.service.checkout.PaymentsApi; | ||
| import com.adyen.model.checkout.*; | ||
|
|
||
| // Setup Client and Service | ||
| Client client = new Client("Your X-API-KEY", Environment.TEST); | ||
| CloudDeviceApi cloudDeviceApi = new CloudDeviceApi(client); | ||
|
|
||
| ``` | ||
|
|
||
| ### Send a payment SYNC request | ||
|
|
||
| ```java | ||
|
|
||
| SaleToPOIRequest saleToPOIRequest = new SaleToPOIRequest(); | ||
|
|
||
| MessageHeader messageHeader = new MessageHeader(); | ||
| messageHeader.setProtocolVersion("3.0"); | ||
| messageHeader.setMessageClass(MessageClassType.SERVICE); | ||
| messageHeader.setMessageCategory(MessageCategoryType.PAYMENT); | ||
| messageHeader.setMessageType(MessageType.REQUEST); | ||
| messageHeader.setSaleID("001"); | ||
| messageHeader.setServiceID("001"); | ||
| messageHeader.setPOIID("P400Plus-123456789"); | ||
|
|
||
| saleToPOIRequest.setMessageHeader(messageHeader); | ||
|
|
||
| PaymentRequest paymentRequest = new PaymentRequest(); | ||
|
|
||
| SaleData saleData = new SaleData(); | ||
| TransactionIdentification transactionIdentification = new TransactionIdentification(); | ||
| transactionIdentification.setTransactionID("001"); | ||
| OffsetDateTime timestamp = OffsetDateTime.now(ZoneOffset.UTC); | ||
| transactionIdentification.setTimeStamp(timestamp); | ||
| saleData.setSaleTransactionID(transactionIdentification); | ||
|
|
||
| PaymentTransaction paymentTransaction = new PaymentTransaction(); | ||
| AmountsReq amountsReq = new AmountsReq(); | ||
| amountsReq.setCurrency("EUR"); | ||
| amountsReq.setRequestedAmount(BigDecimal.ONE); | ||
| paymentTransaction.setAmountsReq(amountsReq); | ||
|
|
||
| paymentRequest.setSaleData(saleData); | ||
| paymentRequest.setPaymentTransaction(paymentTransaction); | ||
|
|
||
| saleToPOIRequest.setPaymentRequest(paymentRequest); | ||
|
|
||
| CloudDeviceApiRequest cloudDeviceApiRequest = new CloudDeviceApiRequest(); | ||
| cloudDeviceApiRequest.setSaleToPOIRequest(saleToPOIRequest); | ||
|
|
||
| var response = cloudDeviceApi.sendSync("myMerchant", "P400Plus-123456789", cloudDeviceApiRequest); | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ### Send a payment ASYNC request | ||
|
|
||
| If you choose to receive the response asynchronously, you only need to use a different method (`sendAsync`). | ||
| Don't forget to set up [event notifications](https://docs.adyen.com/point-of-sale/design-your-integration/notifications/event-notifications/) in the CA to be able to receive the Cloud Device API responses. | ||
|
|
||
| ```java | ||
|
|
||
| ... | ||
|
|
||
| // define the request (same as per sendSync) | ||
| CloudDeviceApiRequest cloudDeviceApiRequest = new CloudDeviceApiRequest(); | ||
| cloudDeviceApiRequest.setSaleToPOIRequest(saleToPOIRequest); | ||
|
|
||
| CloudDeviceApiAsyncResponse response = cloudDeviceApi.sendAsync("myMerchant", "P400Plus-123456789", cloudDeviceApiRequest); | ||
|
|
||
| // | ||
| if(response.equals("ok")) { | ||
| // success | ||
| } else { | ||
| // request failed: see details in the EventNotification object | ||
| EventNotification eventNotification = response.getSaleToPOIRequest().getEventNotification(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Verity the status of the terminals | ||
gcatanese marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The Cloud Device API allows your integration to check the status of the terminals. | ||
|
|
||
| ```java | ||
|
|
||
| // list of payment terminals or SDK mobile installation IDs | ||
| ConnectedDevicesResponse response = cloudDeviceApi.getConnectedDevices("myMerchant"); | ||
| System.out.println(response.getUniqueDeviceIds()); | ||
|
|
||
| // check the payment terminal or SDK mobile installation ID | ||
| DeviceStatusResponse response = cloudDeviceApi.getDeviceStatus("myMerchant", "AMS1-000168242800763"); | ||
| System.out.println(response.getStatus()); | ||
| ``` | ||
|
|
||
| ### Protect cloud communication | ||
|
|
||
| The Adyen Java library supports encrypting request and response payloads, allowing you to secure communication between your integration and the cloud. | ||
|
|
||
| ```java | ||
|
|
||
| // Encryption credentials from the Terminal configuration on CA | ||
| EncryptionCredentialDetails encryptionCredentialDetails = | ||
| new EncryptionCredentialDetails() | ||
| .adyenCryptoVersion(0) | ||
| .keyIdentifier("CryptoKeyIdentifier12345") | ||
| .keyVersion(0) | ||
| .passphrase("p@ssw0rd123456"); | ||
|
|
||
| var response = | ||
| cloudDeviceApi.sendEncryptedSync( | ||
| "TestMerchantAccount", | ||
| "V400m-123456789", | ||
| cloudDeviceApiRequest, | ||
| encryptionCredentialDetails); | ||
|
|
||
| System.out.println(response); | ||
| ``` | ||
|
|
||
| In case of asynchronous integration, you can decrypt the payload of the event notifications using `decryptNotification()` method. | ||
|
|
||
| ```java | ||
| // JSON with encrypted SaleToPOIResponse (for async responses) or SaleToPOIRequest (for event notifications) | ||
| var payload = "..."; | ||
|
|
||
| var response = cloudDeviceApi.decryptNotification(payload, encryptionCredentialDetails); | ||
| System.out.println(response); | ||
|
|
||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.