Skip to content

Commit

Permalink
Merge pull request #1238 from Adyen/terminal-api-readme
Browse files Browse the repository at this point in the history
Update README.md with terminal api instructions
  • Loading branch information
Aleffio committed Aug 22, 2023
2 parents 0524a2f + 440ee4a commit 68b3f98
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,157 @@ client.httpClient = httpClient;
// ... more code
```

## Using the Cloud Terminal API Integration
In order to submit In-Person requests with [Terminal API over Cloud](https://docs.adyen.com/point-of-sale/design-your-integration/choose-your-architecture/cloud/) you need to initialize the client in a similar way as the steps listed above for Ecommerce transactions, but make sure to include `TerminalCloudAPI`:
``` javascript
// Step 1: Require the parts of the module you want to use
const {Client, TerminalCloudAPI} from "@adyen/api-library";

// Step 2: Initialize the client object
const client = new Client({apiKey: "YOUR_API_KEY", environment: "TEST"});

// Step 3: Initialize the API object
const terminalCloudAPI = new TerminalCloudAPI(client);

// Step 4: Create the request object
const serviceID = "123456789";
const saleID = "POS-SystemID12345";
const POIID = "Your Device Name(eg V400m-123456789)";

// Use a unique transaction for every transaction you perform
const transactionID = "TransactionID";
const paymentRequest: SaleToPOIRequest = {
MessageHeader: {
MessageClass: MessageClassType.Service,
MessageCategory: MessageCategoryType.Payment,
MessageType: MessageType.Request,
ProtocolVersion: "3.0",
ServiceID: serviceID,
SaleID: saleID,
POIID: POIID
},
PaymentRequest: {
SaleData: {
SaleTransactionID: {
TransactionID: transactionID,
TimeStamp: this.GetDate().toISOString()
},

SaleToAcquirerData: {
applicationInfo: {
merchantApplication: {
version: "1",
name: "test",
}
}
}
},
PaymentTransaction: {
AmountsReq: {
Currency: "EUR",
RequestedAmount: 1000
}
}
}
};

// Step 5: Make the request
const terminalAPIResponse: terminal.TerminalApiResponse = await terminalCloudAPI.sync(paymentRequest);
```

### Optional: perform an abort request

To perform an [abort request](https://docs.adyen.com/point-of-sale/basic-tapi-integration/cancel-a-transaction/) you can use the following example:
``` javascript
const abortRequest: SaleToPOIRequest = {
MessageHeader: {
MessageClass: MessageClassType.Service,
MessageCategory: MessageCategoryType.Abort,
MessageType: MessageType.Request,
ProtocolVersion: "3.0",
// Different serviceID than the one you're aborting
ServiceID: "Different service ID",
SaleID: saleID,
POIID: POIID
},
AbortRequest: {
AbortReason: "MerchantAbort",
MessageReference: {
MessageCategory: MessageCategoryEnum.Payment,
SaleID: saleID,
// Service ID of the payment you're aborting
ServiceID: serviceID,
POIID: POIID
}

}
};
const terminalAPIResponse: terminal.TerminalApiResponse = await terminalCloudAPI.sync(abortRequest);
```

### Optional: perform a status request

To perform a [status request](https://docs.adyen.com/point-of-sale/basic-tapi-integration/verify-transaction-status/) you can use the following example:
``` javascript
const statusRequest: SaleToPOIRequest = {
MessageHeader: {
MessageClass: MessageClassType.Service,
MessageCategory: MessageCategoryType.TransactionStatus,
MessageType: MessageType.Request,
ProtocolVersion: "3.0",
ServiceID: "Different service ID",
SaleID: saleID,
POIID: POIID
},
TransactionStatusRequest: {
ReceiptReprintFlag: true,
DocumentQualifier: [DocumentQualifierEnum.CashierReceipt, DocumentQualifierEnum.CustomerReceipt],
MessageReference: {
SaleID: saleID,
// serviceID of the transaction you want the status update for
ServiceID: serviceID,
MessageCategory: MessageCategoryEnum.Payment
}
}
};
const terminalAPIResponse: terminal.TerminalApiResponse = await terminalCloudAPI.sync(statusRequest);
```

## Using the Local Terminal API Integration
The procedure to send In-Person requests using [Terminal API over Local Connection](https://docs.adyen.com/point-of-sale/design-your-integration/choose-your-architecture/local/) is similar to the Cloud Terminal API one, however, additional encryption details are required to perform the requests. Make sure to [install the certificate as described here](https://docs.adyen.com/point-of-sale/design-your-integration/choose-your-architecture/local/#protect-communications)
```javascript
// Step 1: Require the parts of the module you want to use
const {Client, TerminalLocalAPI} from "@adyen/api-library";

// Step 2: Add your Merchant Account, Certificate Path and Local Endpoint to the config path. Install the certificate and save it in your project folder as "cert.cer"
const config: Config = new Config();
config.merchantAccount = "Your merchant account";
config.certificatePath = "./cert.cer";
config.terminalApiLocalEndpoint = "The IP of your terminal (eg https://192.168.47.169)";
config.apiKey = "YOUR_API_KEY_HERE";

// Step 3: Setup a security password for your terminal in CA, and import the security key object:
const securityKey: SecurityKey = {
AdyenCryptoVersion: 1,
KeyIdentifier: "keyIdentifier",
KeyVersion: 1,
Passphrase: "passphrase",
};

// Step 4 Initialize the client and the API objects
client = new Client({ config });
const terminalLocalAPI = new TerminalLocalAPI(client);

// Step 5: Create the request object
const paymentRequest: SaleToPOIRequest = {
// Similar to the saleToPOIRequest used for Cloud API
}

// Step 6: Make the request
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest, securityKey);
```


## Feedback
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.

Expand Down

0 comments on commit 68b3f98

Please sign in to comment.