Skip to content

Commit 9ac220a

Browse files
committed
Add async snippet in README
1 parent e4a985a commit 9ac220a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,75 @@ const paymentRequest: SaleToPOIRequest = {
515515
// Step 5: Make the request
516516
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
517517
```
518+
### Using the Cloud Terminal API Integration (async)
519+
If you choose to integrate [Terminal API over Cloud](https://docs.adyen.com/point-of-sale/design-your-integration/choose-your-architecture/cloud/) **asynchronously**, you need to follow similar steps to initialize the client and prepare the request object. However the response will be asyncronous:
520+
* a successful request will return `200` status code and `ok` as response body. Make sure to setup the [event notifications](https://docs.adyen.com/point-of-sale/design-your-integration/notifications/event-notifications/)
521+
* a request that fails will return `200` status code and the `TerminalApiResponse` as response body
522+
``` javascript
523+
// Step 1: Require the parts of the module you want to use
524+
const {Client, TerminalCloudAPI} from "@adyen/api-library";
525+
526+
// Step 2: Initialize the client object
527+
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});
528+
529+
// Step 3: Initialize the API object
530+
const terminalCloudAPI = new TerminalCloudAPI(client);
531+
532+
// Step 4: Create the request object
533+
const serviceID = "123456789";
534+
const saleID = "POS-SystemID12345";
535+
const POIID = "Your Device Name(eg V400m-123456789)";
536+
537+
// Use a unique transaction for every transaction you perform
538+
const transactionID = "TransactionID";
539+
const paymentRequest: SaleToPOIRequest = {
540+
MessageHeader: {
541+
MessageClass: MessageClassType.Service,
542+
MessageCategory: MessageCategoryType.Payment,
543+
MessageType: MessageType.Request,
544+
ProtocolVersion: "3.0",
545+
ServiceID: serviceID,
546+
SaleID: saleID,
547+
POIID: POIID
548+
},
549+
PaymentRequest: {
550+
SaleData: {
551+
SaleTransactionID: {
552+
TransactionID: transactionID,
553+
TimeStamp: this.GetDate().toISOString()
554+
},
555+
556+
SaleToAcquirerData: {
557+
applicationInfo: {
558+
merchantApplication: {
559+
version: "1",
560+
name: "test",
561+
}
562+
}
563+
}
564+
},
565+
PaymentTransaction: {
566+
AmountsReq: {
567+
Currency: "EUR",
568+
RequestedAmount: 1000
569+
}
570+
}
571+
}
572+
};
573+
574+
// Step 5: Make the request
575+
const response = await terminalCloudAPI.async(paymentRequest);
576+
// handle both `string` and `TerminalApiResponse`
577+
if (typeof response === "string") {
578+
// request was successful
579+
console.log("response:", response); // should be 'ok'
580+
} else {
581+
// request failed: see details in the EventNotification object
582+
console.log("EventToNotify:", requestResponse.SaleToPOIRequest?.EventNotification?.EventToNotify);
583+
console.log("EventDetails:", requestResponse.SaleToPOIRequest?.EventNotification?.EventDetails);
584+
}
585+
```
586+
518587
## Feedback
519588
We value your input! Help us enhance our API Libraries and improve the integration experience by providing your feedback. Please take a moment to fill out [our feedback form](https://forms.gle/A4EERrR6CWgKWe5r9) to share your thoughts, suggestions or ideas.
520589

0 commit comments

Comments
 (0)