TerminalAPIKit for iOS helps with integrating Adyen's Terminal API into your iOS POS app. The kit provides the models to create a Terminal API SaletoPOIRequest
, and to decode the received SaletoPOIResponse
.
TerminalAPIKit for iOS is available through Swift Package Manager.
To install the kit:
- In your Xcode project, go to File > Swift Packages > Add Package Dependency.
- Enter
https://github.com/Adyen/adyen-terminal-api-ios
as the repository URL. - Specify the version to be at least
1.0.0
.
For detailed instructions see Adding Package Dependencies to Your App.
The next sections describe how to create a request and how to decode the response.
To create a Terminal API SaleToPOIRequest
for making a payment:
- Create an instance of
MessageHeader
, representing the MessageHeader of your Terminal API request.let header = MessageHeader( protocolVersion: "3.0", messageClass: .service, messageCategory: .payment, messageType: .request, serviceIdentifier: "YOUR_SERVICE_IDENTIFIER", saleIdentifier: "YOUR_SERVICE_IDENTIFIER", poiIdentifier: "YOUR_POI_IDENTIFIER" )
- Create an instance of
PaymentTransaction
, representing the body of your Terminal API PaymentRequestlet saleData = SaleData( saleTransactionIdentifier: TransactionIdentifier( transactionIdentifier: "YOUR_TRANSACTION_IDENTIFIER", date: Date() ) ) let paymentTransaction = PaymentTransaction( amounts: Amounts( currency: "TRANSACTION_CURRENCY", requestedAmount: TRANSACTION_AMOUNT ) ) let paymentRequest = PaymentRequest( saleData: saleData, paymentTransaction: paymentTransaction )
- Combine
header
andpaymentRequest
into an instance ofMessage<PaymentRequest>
, representing the SaleToPOIRequest to send.let message = Message(header: header, body: paymentRequest)
- Encode the
message
to JSON. TerminalAPIKit provides aCoder
class to help with the JSON encoding and decoding.let jsonData = try Coder.encode(message)
- Send the JSON message to the appropriate endpoint.
You'll receive a Terminal API response in JSON format from the endpoint that you sent your request to.
To handle the response:
- Decode from
Data
as follows:let message = try Coder.decode(Message<PaymentResponse>.self, from: response)
- After decoding, note the following:
- The message object has a type of
Message<PaymentResponse>
, representing the Terminal API SaleToPOIResponse. - The
header
andbody
properties of themessage
represent the MessageHeader and PaymentResponse body.
- The message object has a type of
To use TerminalAPIKit for iOS, you need:
- iOS 13.0 or later
- Xcode 13.4 or later
- Swift 5.6
If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our support team.
We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
- New features and functionality
- Resolved bug fixes and issues
- Any general improvements
Read our contribution guidelines to find out how.
This repository is open source and available under the MIT license. For more information, see the LICENSE file.