Skip to content

Commit 41ade4f

Browse files
committed
Add async snippet in README
1 parent d8d1282 commit 41ade4f

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
@@ -507,6 +507,75 @@ const paymentRequest: SaleToPOIRequest = {
507507
// Step 5: Make the request
508508
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
509509
```
510+
### Using the Cloud Terminal API Integration (async)
511+
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:
512+
* 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/)
513+
* a request that fails will return `200` status code and the `TerminalApiResponse` as response body
514+
``` javascript
515+
// Step 1: Require the parts of the module you want to use
516+
const {Client, TerminalCloudAPI} from "@adyen/api-library";
517+
518+
// Step 2: Initialize the client object
519+
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});
520+
521+
// Step 3: Initialize the API object
522+
const terminalCloudAPI = new TerminalCloudAPI(client);
523+
524+
// Step 4: Create the request object
525+
const serviceID = "123456789";
526+
const saleID = "POS-SystemID12345";
527+
const POIID = "Your Device Name(eg V400m-123456789)";
528+
529+
// Use a unique transaction for every transaction you perform
530+
const transactionID = "TransactionID";
531+
const paymentRequest: SaleToPOIRequest = {
532+
MessageHeader: {
533+
MessageClass: MessageClassType.Service,
534+
MessageCategory: MessageCategoryType.Payment,
535+
MessageType: MessageType.Request,
536+
ProtocolVersion: "3.0",
537+
ServiceID: serviceID,
538+
SaleID: saleID,
539+
POIID: POIID
540+
},
541+
PaymentRequest: {
542+
SaleData: {
543+
SaleTransactionID: {
544+
TransactionID: transactionID,
545+
TimeStamp: this.GetDate().toISOString()
546+
},
547+
548+
SaleToAcquirerData: {
549+
applicationInfo: {
550+
merchantApplication: {
551+
version: "1",
552+
name: "test",
553+
}
554+
}
555+
}
556+
},
557+
PaymentTransaction: {
558+
AmountsReq: {
559+
Currency: "EUR",
560+
RequestedAmount: 1000
561+
}
562+
}
563+
}
564+
};
565+
566+
// Step 5: Make the request
567+
const response = await terminalCloudAPI.async(paymentRequest);
568+
// handle both `string` and `TerminalApiResponse`
569+
if (typeof response === "string") {
570+
// request was successful
571+
console.log("response:", response); // should be 'ok'
572+
} else {
573+
// request failed: see details in the EventNotification object
574+
console.log("EventToNotify:", requestResponse.SaleToPOIRequest?.EventNotification?.EventToNotify);
575+
console.log("EventDetails:", requestResponse.SaleToPOIRequest?.EventNotification?.EventDetails);
576+
}
577+
```
578+
510579
## Feedback
511580
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.
512581

0 commit comments

Comments
 (0)